From 4af5a0503dea600188c362e62b5ecf825adbd69b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 6 Jan 2016 03:47:08 +0100 Subject: [PATCH] tests: qvm-revert-template-changes Regression test for: QubesOS/qubes-issues#1573 --- tests/basic.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tests/basic.py b/tests/basic.py index d3a524c2..456934a1 100644 --- a/tests/basic.py +++ b/tests/basic.py @@ -571,5 +571,64 @@ class TC_02_QvmPrefs(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase): self.execute_tests('kernel', [('default', '', False)]) self.execute_tests('kernelopts', [('default', '', False)]) +class TC_03_QvmRevertTemplateChanges(qubes.tests.SystemTestsMixin, + qubes.tests.QubesTestCase): + + def setup_pv_template(self): + self.test_template = self.qc.add_new_vm( + "QubesTemplateVm", + name=self.make_vm_name("pv-clone"), + ) + self.test_template.clone_attrs(src_vm=self.qc.get_default_template()) + self.test_template.clone_disk_files( + src_vm=self.qc.get_default_template(), + verbose=False) + self.save_and_reload_db() + self.qc.unlock_db() + + def setup_hvm_template(self): + self.test_template = self.qc.add_new_vm( + "QubesTemplateHVm", + name=self.make_vm_name("hvm"), + ) + self.test_template.create_on_disk(verbose=False) + self.save_and_reload_db() + self.qc.unlock_db() + + def get_rootimg_checksum(self): + p = subprocess.Popen(['sha1sum', self.test_template.root_img], + stdout=subprocess.PIPE) + return p.communicate()[0] + + def _do_test(self): + checksum_before = self.get_rootimg_checksum() + self.test_template.start(verbose=False) + self.shutdown_and_wait(self.test_template) + checksum_changed = self.get_rootimg_checksum() + if checksum_before == checksum_changed: + self.log.warning("template not modified, test result will be " + "unreliable") + with self.assertNotRaises(subprocess.CalledProcessError): + subprocess.check_call(['sudo', 'qvm-revert-template-changes', + '--force', self.test_template.name]) + + checksum_after = self.get_rootimg_checksum() + self.assertEquals(checksum_before, checksum_after) + + def test_000_revert_pv(self): + """ + Test qvm-revert-template-changes for PV template + """ + self.setup_pv_template() + self._do_test() + + def test_000_revert_hvm(self): + """ + Test qvm-revert-template-changes for HVM template + """ + # TODO: have some system there, so the root.img will get modified + self.setup_hvm_template() + self._do_test() + # vim: ts=4 sw=4 et