diff --git a/qubes/tests/__init__.py b/qubes/tests/__init__.py index 031c8493..a481f393 100644 --- a/qubes/tests/__init__.py +++ b/qubes/tests/__init__.py @@ -39,6 +39,8 @@ import lxml.etree import qubes.config import qubes.events +XMLPATH = '/var/lib/qubes/qubes-test.xml' +TEMPLATE = 'fedora-21' VMPREFIX = 'test-' @@ -360,8 +362,10 @@ class SystemTestsMixin(object): return VMPREFIX + name - def _remove_vm_qubes(self, vm): + @staticmethod + def _remove_vm_qubes(vm): vmname = vm.name + app = vm.app try: # XXX .is_running() may throw libvirtError if undefined @@ -377,16 +381,20 @@ class SystemTestsMixin(object): try: vm.libvirt_domain.undefine() - except libvirt.libvirtError: + except (AttributeError, libvirt.libvirtError): pass - del self.app.domains[vm] + del app.domains[vm] del vm + app.save() + del app + # Now ensure it really went away. This may not have happened, # for example if vm.libvirt_domain malfunctioned. try: - dom = self.conn.lookupByName(vmname) + conn = libvirt.open(qubes.config.defaults['libvirt_uri']) + dom = conn.lookupByName(vmname) except: # pylint: disable=bare-except pass else: @@ -422,7 +430,6 @@ class SystemTestsMixin(object): def remove_vms(self, vms): for vm in vms: self._remove_vm_qubes(vm) - self.save_and_reload_db() def remove_test_vms(self): @@ -436,16 +443,14 @@ class SystemTestsMixin(object): ''' # first, remove them Qubes-way - something_removed = False - for vm in self.app.domains: - if vm.name.startswith(VMPREFIX): - self._remove_vm_qubes(vm) - something_removed = True - if something_removed: - self.save_and_reload_db() + if os.path.exists(XMLPATH): + self.remove_vms(vm for vm in qubes.Qubes(XMLPATH).domains + if vm.name != TEMPLATE) + os.unlink(XMLPATH) # now remove what was only in libvirt - for dom in self.conn.listAllDomains(): + conn = libvirt.open(qubes.config.defaults['libvirt_uri']) + for dom in conn.listAllDomains(): if dom.name().startswith(VMPREFIX): self._remove_vm_libvirt(dom) @@ -478,13 +483,16 @@ def load_tests(loader, tests, pattern): # pylint: disable=unused-argument 'qubes.tests.tools', # integration tests -# 'qubes.tests.init.basic', +# 'qubes.tests.int.basic', # 'qubes.tests.dom0_update', # 'qubes.tests.network', # 'qubes.tests.vm_qrexec_gui', # 'qubes.tests.backup', # 'qubes.tests.backupcompatibility', # 'qubes.tests.regressions', + + # tool tests + 'qubes.tests.int.tools.qubes_create', ): tests.addTests(loader.loadTestsFromName(modname)) diff --git a/qubes/tests/int/__init__.py b/qubes/tests/int/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/basic.py b/qubes/tests/int/basic.py similarity index 93% rename from tests/basic.py rename to qubes/tests/int/basic.py index 7ed8151e..5d7593f9 100644 --- a/tests/basic.py +++ b/qubes/tests/int/basic.py @@ -12,12 +12,12 @@ # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. @@ -31,13 +31,26 @@ import unittest import time from qubes.qubes import QubesVmCollection, QubesException, system_path -import qubes.qubes +import qubes +import qubes.vm.qubesvm import qubes.tests class TC_00_Basic(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase): - def test_000_create(self): + def setUp(self): + self.app = qubes.Qubes.create_empty_store(qubes.tests.XMLPATH) + + def test_000_qubes_create(self): + self.assertIsInstance(self.app, qubes.Qubes) + + def test_001_qvm_create_default_template(self): + self.app.add_new_vm + + + def test_100_qvm_create(self): + app = qubes.Qubes(qubes.tests.XMLPATH) vmname = self.make_vm_name('appvm') - vm = self.qc.add_new_vm('QubesAppVm', + + vm = app.add_new_vm(qubes.vm.appvm.AppVM, name=vmname, template=self.qc.get_default_template()) self.assertIsNotNone(vm) diff --git a/qubes/tests/int/tools/__init__.py b/qubes/tests/int/tools/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/qubes/tests/int/tools/qubes_create.py b/qubes/tests/int/tools/qubes_create.py new file mode 100644 index 00000000..d7dfb777 --- /dev/null +++ b/qubes/tests/int/tools/qubes_create.py @@ -0,0 +1,47 @@ +#!/usr/bin/python2 -O +# vim: fileencoding=utf-8 + +# +# The Qubes OS Project, https://www.qubes-os.org/ +# +# Copyright (C) 2015 Joanna Rutkowska +# Copyright (C) 2015 Wojtek Porczyk +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + + +import qubes +import qubes.tools.qubes_create + +import qubes.tests + +@qubes.tests.skipUnlessDom0 +class TC_00_qubes_create(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase): + def test_000_basic(self): + self.assertEqual(0, + qubes.tools.qubes_create.main(( + '--qubesxml', qubes.tests.XMLPATH, + ))) + + def test_001_property(self): + self.assertEqual(0, + qubes.tools.qubes_create.main(( + '--qubesxml', qubes.tests.XMLPATH, + '--property', 'default_kernel=testkernel' + ))) + + self.assertEqual('testkernel', + qubes.Qubes(qubes.tests.XMLPATH).default_kernel) diff --git a/rpm_spec/core-dom0.spec b/rpm_spec/core-dom0.spec index 1e8a61e9..53f8a7fb 100644 --- a/rpm_spec/core-dom0.spec +++ b/rpm_spec/core-dom0.spec @@ -253,6 +253,14 @@ fi %{python_sitelib}/qubes/tests/tools/init.py* %{python_sitelib}/qubes/tests/tools/qvm_ls.py* +%dir %{python_sitelib}/qubes/tests/int +%{python_sitelib}/qubes/tests/int/__init__.py* +%{python_sitelib}/qubes/tests/int/basic.py* + +%dir %{python_sitelib}/qubes/tests/int/tools +%{python_sitelib}/qubes/tests/int/tools/__init__.py* +%{python_sitelib}/qubes/tests/int/tools/qubes_create.py* + %dir %{python_sitelib}/qubes/qmemman %{python_sitelib}/qubes/qmemman/__init__.py* %{python_sitelib}/qubes/qmemman/algo.py*