Skip to content

Commit f28f2dc

Browse files
committed
tests: run TC_21 once natively via SystemTestCase
Inherits directly from SystemTestCase to bypass the template factory and reverts __init__.py changes to the default original file. Assigns self.template to .name to prevent TypeErrors in helper methods.
1 parent 2faea4b commit f28f2dc

2 files changed

Lines changed: 25 additions & 39 deletions

File tree

qubes/tests/__init__.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,9 +1698,7 @@ def list_templates():
16981698
return _templates
16991699

17001700

1701-
def create_testcases_for_templates(
1702-
name, *bases, module, default_template_only=False, **kwds
1703-
):
1701+
def create_testcases_for_templates(name, *bases, module, **kwds):
17041702
"""Do-it-all helper for generating per-template tests via load_tests proto
17051703
17061704
This does several things:
@@ -1733,13 +1731,7 @@ def create_testcases_for_templates(
17331731
# possible to correctly guess frame from stack. Explicit is better than
17341732
# implicit!
17351733

1736-
templates = list_templates()
1737-
if default_template_only and templates:
1738-
# Some tests are template-agnostic and should run only once
1739-
# to avoid slowing down the integration test suite.
1740-
templates = templates[:1]
1741-
1742-
for template in templates:
1734+
for template in list_templates():
17431735
clsname = name + "_" + template
17441736
if hasattr(module, clsname):
17451737
continue

qubes/tests/integ/dispvm.py

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,13 @@ def test_011_failed_start_timeout(self):
196196

197197

198198
class DispVMHelpersMixin:
199-
def setUp(self): # pylint: disable=invalid-name
200-
logger.info("start")
201-
super().setUp()
202-
if "whonix-g" in self.template:
203-
self.skipTest(
204-
"whonix gateway is not supported as DisposableVM Template"
205-
)
199+
def setup_dispvm_nodes(self):
200+
"""Initialize disp_base and related attributes. Called by child setUp"""
206201
self.app.add_handler("domain-add", self._on_domain_add)
207202
self.addCleanup(
208203
self.app.remove_handler, "domain-add", self._on_domain_add
209204
)
210205
self.adminvm = self.app.domains["dom0"]
211-
self.init_default_template(self.template)
212206
self.disp_base = self.app.add_new_vm(
213207
qubes.vm.appvm.AppVM,
214208
name=self.make_vm_name("dvm"),
@@ -523,6 +517,17 @@ async def run_preload(self):
523517

524518

525519
class TC_20_DispVMMixin(DispVMHelpersMixin):
520+
def setUp(self): # pylint: disable=invalid-name
521+
logger.info("start")
522+
super().setUp()
523+
if "whonix-g" in self.template:
524+
self.skipTest(
525+
"whonix gateway is not supported as DisposableVM Template"
526+
)
527+
self.init_default_template(self.template)
528+
self.setup_dispvm_nodes()
529+
logger.info("end")
530+
526531
def test_010_dvm_run_simple(self):
527532
dispvm = self.loop.run_until_complete(
528533
qubes.vm.dispvm.DispVM.from_appvm(self.disp_base)
@@ -1026,16 +1031,23 @@ def test_100_open_in_dispvm(self):
10261031
self.loop.run_until_complete(app.wait())
10271032

10281033

1029-
class TC_21_DispVM_PreloadMixin(DispVMHelpersMixin):
1034+
class TC_21_DispVM_Preload(DispVMHelpersMixin, qubes.tests.SystemTestCase):
10301035
"""
10311036
Template-independent DisposableVM preload tests.
10321037
10331038
These tests do not depend on the template OS and previously ran once
10341039
per template (Debian/Fedora/Whonix), unnecessarily slowing down the
1035-
integration test suite. They are executed only once using the
1036-
default template.
1040+
integration test suite. They execute only once on the default template.
10371041
"""
10381042

1043+
def setUp(self): # pylint: disable=invalid-name
1044+
logger.info("start")
1045+
super().setUp()
1046+
self.init_default_template()
1047+
self.template = self.app.default_template
1048+
self.setup_dispvm_nodes()
1049+
logger.info("end")
1050+
10391051
def test_011_preload_reject_max(self):
10401052
"""Test preloading when max has been reached"""
10411053
self.loop.run_until_complete(
@@ -1365,27 +1377,9 @@ def create_testcases_for_templates():
13651377
)
13661378

13671379

1368-
def create_preload_testcases_for_default_template():
1369-
return qubes.tests.create_testcases_for_templates(
1370-
"TC_21_DispVM_Preload",
1371-
TC_21_DispVM_PreloadMixin,
1372-
qubes.tests.SystemTestCase,
1373-
module=sys.modules[__name__],
1374-
default_template_only=True,
1375-
)
1376-
1377-
13781380
def load_tests(loader, tests, _pattern):
13791381
tests.addTests(loader.loadTestsFromNames(create_testcases_for_templates()))
1380-
tests.addTests(
1381-
loader.loadTestsFromNames(
1382-
create_preload_testcases_for_default_template()
1383-
)
1384-
)
13851382
return tests
13861383

13871384

13881385
qubes.tests.maybe_create_testcases_on_import(create_testcases_for_templates)
1389-
qubes.tests.maybe_create_testcases_on_import(
1390-
create_preload_testcases_for_default_template
1391-
)

0 commit comments

Comments
 (0)