tests: perform dom0 update check using VMs of different templates
QubesOS/qubes-issues#1282 QubesOS/qubes-issues#1029
This commit is contained in:
		
							parent
							
								
									33255964c7
								
							
						
					
					
						commit
						5160423065
					
				@ -34,7 +34,10 @@ VM_PREFIX = "test-"
 | 
				
			|||||||
@unittest.skipUnless(os.path.exists('/usr/bin/rpmsign') and
 | 
					@unittest.skipUnless(os.path.exists('/usr/bin/rpmsign') and
 | 
				
			||||||
                     os.path.exists('/usr/bin/rpmbuild'),
 | 
					                     os.path.exists('/usr/bin/rpmbuild'),
 | 
				
			||||||
                     'rpm-sign and/or rpm-build not installed')
 | 
					                     'rpm-sign and/or rpm-build not installed')
 | 
				
			||||||
class TC_00_Dom0Upgrade(qubes.tests.QubesTestCase):
 | 
					class TC_00_Dom0UpgradeMixin(qubes.tests.SystemTestsMixin):
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    Tests for downloading dom0 updates using VMs based on different templates
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
    cleanup_paths = []
 | 
					    cleanup_paths = []
 | 
				
			||||||
    pkg_name = 'qubes-test-pkg'
 | 
					    pkg_name = 'qubes-test-pkg'
 | 
				
			||||||
    dom0_update_common_opts = ['--disablerepo=*', '--enablerepo=test',
 | 
					    dom0_update_common_opts = ['--disablerepo=*', '--enablerepo=test',
 | 
				
			||||||
@ -70,7 +73,7 @@ Expire-Date: 0
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @classmethod
 | 
					    @classmethod
 | 
				
			||||||
    def setUpClass(cls):
 | 
					    def setUpClass(cls):
 | 
				
			||||||
        super(TC_00_Dom0Upgrade, cls).setUpClass()
 | 
					        super(TC_00_Dom0UpgradeMixin, cls).setUpClass()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        cls.tmpdir = tempfile.mkdtemp()
 | 
					        cls.tmpdir = tempfile.mkdtemp()
 | 
				
			||||||
        cls.cleanup_paths += [cls.tmpdir]
 | 
					        cls.cleanup_paths += [cls.tmpdir]
 | 
				
			||||||
@ -100,12 +103,11 @@ enabled = 1
 | 
				
			|||||||
        cls.cleanup_paths = []
 | 
					        cls.cleanup_paths = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def setUp(self):
 | 
					    def setUp(self):
 | 
				
			||||||
        self.qc = QubesVmCollection()
 | 
					        super(TC_00_Dom0UpgradeMixin, self).setUp()
 | 
				
			||||||
        self.qc.lock_db_for_writing()
 | 
					        self.updatevm = self.qc.add_new_vm(
 | 
				
			||||||
        self.qc.load()
 | 
					            "QubesProxyVm",
 | 
				
			||||||
        self.updatevm = self.qc.add_new_vm("QubesProxyVm",
 | 
					            name=self.make_vm_name("updatevm"),
 | 
				
			||||||
                                           name="%supdatevm" % VM_PREFIX,
 | 
					            template=self.qc.get_vm_by_name(self.template))
 | 
				
			||||||
                                           template=self.qc.get_default_template())
 | 
					 | 
				
			||||||
        self.updatevm.create_on_disk(verbose=False)
 | 
					        self.updatevm.create_on_disk(verbose=False)
 | 
				
			||||||
        self.saved_updatevm = self.qc.get_updatevm_vm()
 | 
					        self.saved_updatevm = self.qc.get_updatevm_vm()
 | 
				
			||||||
        self.qc.set_updatevm_vm(self.updatevm)
 | 
					        self.qc.set_updatevm_vm(self.updatevm)
 | 
				
			||||||
@ -117,35 +119,13 @@ enabled = 1
 | 
				
			|||||||
                               os.path.join(self.tmpdir, 'pubkey.asc')])
 | 
					                               os.path.join(self.tmpdir, 'pubkey.asc')])
 | 
				
			||||||
        self.updatevm.start()
 | 
					        self.updatevm.start()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def tearDown(self):
 | 
				
			||||||
    def remove_vms(self, vms):
 | 
					 | 
				
			||||||
        self.qc.lock_db_for_writing()
 | 
					        self.qc.lock_db_for_writing()
 | 
				
			||||||
        self.qc.load()
 | 
					        self.qc.load()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.qc.set_updatevm_vm(self.qc[self.saved_updatevm.qid])
 | 
					        self.qc.set_updatevm_vm(self.qc[self.saved_updatevm.qid])
 | 
				
			||||||
 | 
					 | 
				
			||||||
        for vm in vms:
 | 
					 | 
				
			||||||
            if isinstance(vm, str):
 | 
					 | 
				
			||||||
                vm = self.qc.get_vm_by_name(vm)
 | 
					 | 
				
			||||||
            else:
 | 
					 | 
				
			||||||
                vm = self.qc[vm.qid]
 | 
					 | 
				
			||||||
            if vm.is_running():
 | 
					 | 
				
			||||||
                try:
 | 
					 | 
				
			||||||
                    vm.force_shutdown()
 | 
					 | 
				
			||||||
                except:
 | 
					 | 
				
			||||||
                    pass
 | 
					 | 
				
			||||||
            try:
 | 
					 | 
				
			||||||
                vm.remove_from_disk()
 | 
					 | 
				
			||||||
            except OSError:
 | 
					 | 
				
			||||||
                pass
 | 
					 | 
				
			||||||
            self.qc.pop(vm.qid)
 | 
					 | 
				
			||||||
        self.qc.save()
 | 
					        self.qc.save()
 | 
				
			||||||
        self.qc.unlock_db()
 | 
					        super(TC_00_Dom0UpgradeMixin, self).tearDown()
 | 
				
			||||||
 | 
					 | 
				
			||||||
    def tearDown(self):
 | 
					 | 
				
			||||||
        vmlist = [vm for vm in self.qc.values() if vm.name.startswith(
 | 
					 | 
				
			||||||
            VM_PREFIX)]
 | 
					 | 
				
			||||||
        self.remove_vms(vmlist)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        subprocess.call(['sudo', 'rpm', '-e', self.pkg_name], stderr=open(
 | 
					        subprocess.call(['sudo', 'rpm', '-e', self.pkg_name], stderr=open(
 | 
				
			||||||
            os.devnull, 'w'))
 | 
					            os.devnull, 'w'))
 | 
				
			||||||
@ -202,7 +182,9 @@ Test package
 | 
				
			|||||||
        p.stdin.write(open(filename).read())
 | 
					        p.stdin.write(open(filename).read())
 | 
				
			||||||
        p.stdin.close()
 | 
					        p.stdin.close()
 | 
				
			||||||
        p.wait()
 | 
					        p.wait()
 | 
				
			||||||
        self.updatevm.run('cd /tmp/repo; createrepo .', wait=True)
 | 
					        retcode = self.updatevm.run('cd /tmp/repo; createrepo .', wait=True)
 | 
				
			||||||
 | 
					        if retcode != 0:
 | 
				
			||||||
 | 
					            raise RuntimeError("createrepo failed, cannot perform test")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_000_update(self):
 | 
					    def test_000_update(self):
 | 
				
			||||||
        filename = self.create_pkg(self.tmpdir, self.pkg_name, '1.0')
 | 
					        filename = self.create_pkg(self.tmpdir, self.pkg_name, '1.0')
 | 
				
			||||||
@ -297,3 +279,23 @@ Test package
 | 
				
			|||||||
            self.pkg_name)], stdout=open('/dev/null', 'w'))
 | 
					            self.pkg_name)], stdout=open('/dev/null', 'w'))
 | 
				
			||||||
        self.assertEqual(retcode, 1,
 | 
					        self.assertEqual(retcode, 1,
 | 
				
			||||||
                         'UNSIGNED package {}-1.0 installed'.format(self.pkg_name))
 | 
					                         'UNSIGNED package {}-1.0 installed'.format(self.pkg_name))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def load_tests(loader, tests, pattern):
 | 
				
			||||||
 | 
					    try:
 | 
				
			||||||
 | 
					        qc = qubes.qubes.QubesVmCollection()
 | 
				
			||||||
 | 
					        qc.lock_db_for_reading()
 | 
				
			||||||
 | 
					        qc.load()
 | 
				
			||||||
 | 
					        qc.unlock_db()
 | 
				
			||||||
 | 
					        templates = [vm.name for vm in qc.values() if
 | 
				
			||||||
 | 
					                     isinstance(vm, qubes.qubes.QubesTemplateVm)]
 | 
				
			||||||
 | 
					    except OSError:
 | 
				
			||||||
 | 
					        templates = []
 | 
				
			||||||
 | 
					    for template in templates:
 | 
				
			||||||
 | 
					        tests.addTests(loader.loadTestsFromTestCase(
 | 
				
			||||||
 | 
					            type(
 | 
				
			||||||
 | 
					                'TC_00_Dom0Upgrade_' + template,
 | 
				
			||||||
 | 
					                (TC_00_Dom0UpgradeMixin, qubes.tests.QubesTestCase),
 | 
				
			||||||
 | 
					                {'template': template})))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return tests
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user