From c663b1dd2df529affa1100e83abb2df3510a7cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Mon, 9 Feb 2015 06:18:57 +0100 Subject: [PATCH] tests: add simple HVM tests --- tests/vm_qrexec_gui.py | 105 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) diff --git a/tests/vm_qrexec_gui.py b/tests/vm_qrexec_gui.py index 2c7863ff..f0f0bcd8 100644 --- a/tests/vm_qrexec_gui.py +++ b/tests/vm_qrexec_gui.py @@ -25,7 +25,7 @@ import subprocess import unittest import time -from qubes.qubes import QubesVmCollection, defaults +from qubes.qubes import QubesVmCollection, defaults, QubesException VM_PREFIX = "test-" @@ -341,6 +341,109 @@ class VmRunningTests(unittest.TestCase): "/home/user/QubesIncoming/%s/passwd" % self.testvm1.name, wait=True) self.assertEqual(retcode, 0, "file differs") +class HVMTests(unittest.TestCase): + # TODO: test with some OS inside + # TODO: windows tools tests + + def setUp(self): + self.qc = QubesVmCollection() + + def remove_vms(self, vms): + self.qc.lock_db_for_writing() + self.qc.load() + + 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.unlock_db() + + def tearDown(self): + vmlist = [vm for vm in self.qc.values() if vm.name.startswith( + VM_PREFIX)] + self.remove_vms(vmlist) + + def test_000_create_start(self): + self.qc.lock_db_for_writing() + try: + self.qc.load() + self.testvm1 = self.qc.add_new_vm("QubesHVm", + name="%svm1" % VM_PREFIX) + self.testvm1.create_on_disk(verbose=False) + self.qc.save() + finally: + self.qc.unlock_db() + self.testvm1.start() + self.assertEquals(self.testvm1.get_power_state(), "Running") + + def test_010_create_start_template(self): + self.qc.lock_db_for_writing() + try: + self.qc.load() + self.templatevm = self.qc.add_new_vm("QubesTemplateHVm", + name="%stemplate" % VM_PREFIX) + self.templatevm.create_on_disk(verbose=False) + self.qc.save() + finally: + self.qc.unlock_db() + + self.templatevm.start() + self.assertEquals(self.templatevm.get_power_state(), "Running") + + def test_020_create_start_template_vm(self): + self.qc.lock_db_for_writing() + try: + self.qc.load() + self.templatevm = self.qc.add_new_vm("QubesTemplateHVm", + name="%stemplate" % VM_PREFIX) + self.templatevm.create_on_disk(verbose=False) + self.testvm2 = self.qc.add_new_vm("QubesHVm", + name="%svm2" % VM_PREFIX, + template=self.templatevm) + self.testvm2.create_on_disk(verbose=False) + self.qc.save() + finally: + self.qc.unlock_db() + + self.testvm2.start() + self.assertEquals(self.testvm2.get_power_state(), "Running") + + def test_030_prevent_simultaneus_start(self): + self.qc.lock_db_for_writing() + try: + self.qc.load() + self.templatevm = self.qc.add_new_vm("QubesTemplateHVm", + name="%stemplate" % VM_PREFIX) + self.templatevm.create_on_disk(verbose=False) + self.testvm2 = self.qc.add_new_vm("QubesHVm", + name="%svm2" % VM_PREFIX, + template=self.templatevm) + self.testvm2.create_on_disk(verbose=False) + self.qc.save() + finally: + self.qc.unlock_db() + + self.templatevm.start() + self.assertEquals(self.templatevm.get_power_state(), "Running") + self.assertRaises(QubesException, self.testvm2.start) + self.templatevm.force_shutdown() + self.testvm2.start() + self.assertEquals(self.testvm2.get_power_state(), "Running") + self.assertRaises(QubesException, self.templatevm.start) + + class DispVmTests(unittest.TestCase): def setUp(self): self.qc = QubesVmCollection()