Skip to content

Commit

Permalink
Get local name from qubesdb
Browse files Browse the repository at this point in the history
Do not depend on hostname set inside the VM, especially since Whonix
changes it.

This also adds direct dependency on python3-qubesdb - previously it
depended on it only indirectly (via core-agent-linux).

Do include a fallback to work without qubesdb python module to allow
running tests or rendering sphinx documentation without it.
  • Loading branch information
marmarek committed May 11, 2024
1 parent c779d0d commit ba9cbf6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Architecture: any
Depends:
python3-docutils,
python3-lxml,
python3-qubesdb,
python3-rpm,
python3-tqdm,
${python3:Depends},
Expand Down
19 changes: 18 additions & 1 deletion qubesadmin/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
import qubesadmin.config
import qubesadmin.devices

try:
import qubesdb
has_qubesdb = True
except ImportError:
has_qubesdb = False

Check warning on line 48 in qubesadmin/app.py

View check run for this annotation

Codecov / codecov/patch

qubesadmin/app.py#L47-L48

Added lines #L47 - L48 were not covered by tests


class VMCollection(object):
"""Collection of VMs objects"""
Expand Down Expand Up @@ -257,7 +263,18 @@ def remove_pool(self, name):
def local_name(self):
""" Get localhost name """
if not self._local_name:
self._local_name = os.uname()[1]
local_name = None
if has_qubesdb:
try:
local_qdb = qubesdb.QubesDB()
local_name_b = local_qdb.read('/name')
if local_name_b:
local_name = local_name_b.decode()
except qubesdb.Error:
pass
if local_name is None:
local_name = os.uname()[1]
self._local_name = local_name

Check warning on line 277 in qubesadmin/app.py

View check run for this annotation

Codecov / codecov/patch

qubesadmin/app.py#L266-L277

Added lines #L266 - L277 were not covered by tests

return self._local_name

Expand Down
1 change: 1 addition & 0 deletions rpm_spec/qubes-core-admin-client.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Requires: python%{python3_pkgversion}-daemon
Requires: python%{python3_pkgversion}-docutils
Requires: python%{python3_pkgversion}-lxml
Requires: python%{python3_pkgversion}-xcffib
Requires: python%{python3_pkgversion}-qubesdb
Requires: python%{python3_pkgversion}-rpm
Requires: python%{python3_pkgversion}-tqdm
Requires: python%{python3_pkgversion}-pyxdg
Expand Down
6 changes: 6 additions & 0 deletions test-packages/qubesdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class QubesDB:
def read(self, key):
return b'testvm'

class Error(Exception):
pass

0 comments on commit ba9cbf6

Please sign in to comment.