From a1575b98d4b7167f1c7b6848dc6bc4eefff26b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 20 Apr 2016 02:25:06 +0200 Subject: [PATCH 1/4] tests: do not drop 'qubes.tests.' prefix This cause troubles with "external" tests (loaded from outside of qubes.tests module). --- qubes/tests/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qubes/tests/__init__.py b/qubes/tests/__init__.py index 8f39eae4..eff6c44f 100644 --- a/qubes/tests/__init__.py +++ b/qubes/tests/__init__.py @@ -223,7 +223,7 @@ class QubesTestCase(unittest.TestCase): def __str__(self): return '{}/{}/{}'.format( - '.'.join(self.__class__.__module__.split('.')[2:]), + self.__class__.__module__, self.__class__.__name__, self._testMethodName) From a707840596f2bd0b3db2a74a95a978767fb52e70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 20 Apr 2016 02:26:16 +0200 Subject: [PATCH 2/4] tests: fix and enable external tests loader QubesOS/qubes-issues#1800 --- qubes/tests/__init__.py | 2 ++ qubes/tests/extra.py | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/qubes/tests/__init__.py b/qubes/tests/__init__.py index eff6c44f..1505a07d 100644 --- a/qubes/tests/__init__.py +++ b/qubes/tests/__init__.py @@ -971,6 +971,8 @@ def load_tests(loader, tests, pattern): # pylint: disable=unused-argument 'qubes.tests.int.tools.qubes_create', 'qubes.tests.int.tools.qvm_prefs', 'qubes.tests.int.tools.qvm_run', + # external modules + 'qubes.tests.extra', ): tests.addTests(loader.loadTestsFromName(modname)) diff --git a/qubes/tests/extra.py b/qubes/tests/extra.py index c5c44a5a..21b67063 100644 --- a/qubes/tests/extra.py +++ b/qubes/tests/extra.py @@ -32,6 +32,10 @@ class ExtraTestCase(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase): template = None + def setUp(self): + super(ExtraTestCase, self).setUp() + self.init_default_template(self.template) + def create_vms(self, names): """ Create AppVMs for the duration of the test. Will be automatically @@ -47,14 +51,15 @@ class ExtraTestCase(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase): for vmname in names: vm = self.app.add_new_vm(qubes.vm.appvm.AppVM, name=self.make_vm_name(vmname), - template=template) - vm.create_on_disk(verbose=False) + template=template, + label='red') + vm.create_on_disk() self.save_and_reload_db() # get objects after reload vms = [] for vmname in names: - vms.append(self.app.domains[self.make_vm_name]) + vms.append(self.app.domains[self.make_vm_name(vmname)]) return vms def enable_network(self): @@ -66,7 +71,7 @@ class ExtraTestCase(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase): def load_tests(loader, tests, pattern): for entry in pkg_resources.iter_entry_points('qubes.tests.extra'): - for test_case in entry(): + for test_case in entry.load()(): tests.addTests(loader.loadTestsFromTestCase(test_case)) try: From 71178478163dc26bd5a27d297a65744af389bf57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 20 Apr 2016 02:26:56 +0200 Subject: [PATCH 3/4] tests: fix int.dom0_update Environment must be preserved for QUBES_XML_PATH variable used to point to a secondary (test) qubes.xml. --- qubes/tests/int/dom0_update.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qubes/tests/int/dom0_update.py b/qubes/tests/int/dom0_update.py index 13dc7bc8..d14fcfed 100644 --- a/qubes/tests/int/dom0_update.py +++ b/qubes/tests/int/dom0_update.py @@ -226,7 +226,7 @@ Test package logpath = os.path.join(self.tmpdir, 'dom0-update-output.txt') try: - subprocess.check_call(['sudo', 'qubes-dom0-update', '-y'] + + subprocess.check_call(['sudo', '-E', 'qubes-dom0-update', '-y'] + self.dom0_update_common_opts, stdout=open(logpath, 'w'), stderr=subprocess.STDOUT) @@ -256,7 +256,7 @@ Test package shutil.rmtree('/var/lib/qubes/updates/repodata') logpath = os.path.join(self.tmpdir, 'dom0-update-output.txt') try: - subprocess.check_call(['sudo', 'qubes-dom0-update', '-y', + subprocess.check_call(['sudo', '-E', 'qubes-dom0-update', '-y', '--clean'] + self.dom0_update_common_opts, stdout=open(logpath, 'w'), From 2a46abbefd6c8c9fc66d2bd23f8339e46ae5877a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 20 Apr 2016 02:28:11 +0200 Subject: [PATCH 4/4] qubes.vm: implement TemplateVM.appvms property --- qubes/vm/templatevm.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qubes/vm/templatevm.py b/qubes/vm/templatevm.py index f2cd0a29..52ee5dea 100644 --- a/qubes/vm/templatevm.py +++ b/qubes/vm/templatevm.py @@ -15,6 +15,11 @@ class TemplateVM(qubes.vm.qubesvm.QubesVM): '''COW image''' return self.storage.rootcow_img + @property + def appvms(self): + for vm in self.app.domains: + if hasattr(vm, 'template') and vm.template is self: + yield vm def __init__(self, *args, **kwargs): super(TemplateVM, self).__init__(*args, **kwargs)