Skip to content

Commit 6124fa0

Browse files
committed
Merge remote-tracking branch 'origin/pr/257'
* origin/pr/257: Exclude volatile DispVMs from Global Config
2 parents e37cacc + 048f22d commit 6124fa0

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

qubes_config/global_config/global_config.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,11 +690,47 @@ def _ask_to_quit(self, *_args):
690690
return False
691691

692692

693+
class VMCollection(qubesadmin.app.VMCollection):
694+
"""
695+
Overloaded class to get rid of volatile disposables
696+
"""
697+
698+
def __iter__(self):
699+
for vm in super().__iter__():
700+
try:
701+
if vm.klass == "DispVM" and vm.auto_cleanup:
702+
continue
703+
except: # pylint: disable=bare-except
704+
continue
705+
yield vm
706+
707+
708+
class Qubes(qubesadmin.Qubes):
709+
"""
710+
Overloaded class to get rid of volatile disposables
711+
"""
712+
713+
# Auxiliary domains collection which excludes true disposables (not named)
714+
_domains = None
715+
716+
def __init__(self):
717+
super().__init__()
718+
self._domains = VMCollection(self)
719+
720+
@property
721+
def domains(self):
722+
return self._domains
723+
724+
@domains.setter
725+
def domains(self, d):
726+
self._domains = d
727+
728+
693729
def main():
694730
"""
695731
Start the app
696732
"""
697-
qapp = qubesadmin.Qubes()
733+
qapp = Qubes()
698734
qapp.cache_enabled = True
699735
policy_manager = PolicyManager()
700736
app = GlobalConfig(qapp, policy_manager)

qubes_config/tests/conftest.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"management_dispvm": ("vm", True, "default-mgmt-dvm"),
8282
"netvm": ("vm", False, "sys-firewall"),
8383
"template": ("vm", False, "fedora-36"),
84+
"auto_cleanup": ("bool", True, "False"),
8485
}
8586

8687
possible_tags = ["whonix-updatevm", "anon-gateway"]
@@ -345,6 +346,25 @@ def test_qapp_impl():
345346
[],
346347
)
347348

349+
add_expected_vm(
350+
qapp,
351+
"disp123",
352+
"DispVM",
353+
{"auto_cleanup": ("bool", False, "True")},
354+
{"service.qubes-update-check": None},
355+
[],
356+
)
357+
358+
# This DispVM will die suddently in the middle of Global Config running
359+
add_expected_vm(
360+
qapp,
361+
"disp666",
362+
"DispVM",
363+
{},
364+
{"service.qubes-update-check": None},
365+
[],
366+
)
367+
348368
add_expected_vm(
349369
qapp, "test-vm", "AppVM", {}, {"service.qubes-update-check": None}, []
350370
)

qubes_config/tests/test_global_config.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929
GlobalConfig,
3030
ClipboardHandler,
3131
FileAccessHandler,
32+
VMCollection,
33+
Qubes,
3234
)
3335
from ..global_config.basics_handler import BasicSettingsHandler
36+
from qubesadmin.tests import TestVMCollection, QubesTest
3437

3538
import gi
3639

@@ -49,6 +52,24 @@
4952
)
5053

5154

55+
@patch("qubesadmin.app.VMCollection", TestVMCollection)
56+
def test_vmcollection_global_config(test_qapp):
57+
collection = VMCollection(test_qapp)
58+
test_qapp.expected_calls[
59+
("disp666", "admin.vm.property.Get", "auto_cleanup", None)
60+
] = b"2\x00QubesNoSuchPropertyError\x00\x00DispVM suddenly died!\x00"
61+
for vm in collection:
62+
assert vm.name != "disp123"
63+
assert vm.name != "disp666"
64+
65+
66+
@patch("qubesadmin.Qubes", QubesTest)
67+
def test_qubes_global_config():
68+
app = Qubes()
69+
app.domains = {}
70+
assert app.domains == {}
71+
72+
5273
@patch("subprocess.check_output")
5374
@patch("qubes_config.global_config.global_config.show_error")
5475
def test_global_config_init(

0 commit comments

Comments
 (0)