core3: test fixing

part of QubesOS/qubes-issues#1248
This commit is contained in:
Wojtek Porczyk 2015-10-27 11:39:59 +01:00
parent dc3fcc3141
commit 0dc0fd306f
6 changed files with 95 additions and 19 deletions

View File

@ -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))

View File

View File

@ -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)

View File

View File

@ -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 <joanna@invisiblethingslab.com>
# Copyright (C) 2015 Wojtek Porczyk <woju@invisiblethingslab.com>
#
# 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)

View File

@ -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*