parent
dc3fcc3141
commit
0dc0fd306f
@ -39,6 +39,8 @@ import lxml.etree
|
|||||||
import qubes.config
|
import qubes.config
|
||||||
import qubes.events
|
import qubes.events
|
||||||
|
|
||||||
|
XMLPATH = '/var/lib/qubes/qubes-test.xml'
|
||||||
|
TEMPLATE = 'fedora-21'
|
||||||
VMPREFIX = 'test-'
|
VMPREFIX = 'test-'
|
||||||
|
|
||||||
|
|
||||||
@ -360,8 +362,10 @@ class SystemTestsMixin(object):
|
|||||||
return VMPREFIX + name
|
return VMPREFIX + name
|
||||||
|
|
||||||
|
|
||||||
def _remove_vm_qubes(self, vm):
|
@staticmethod
|
||||||
|
def _remove_vm_qubes(vm):
|
||||||
vmname = vm.name
|
vmname = vm.name
|
||||||
|
app = vm.app
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# XXX .is_running() may throw libvirtError if undefined
|
# XXX .is_running() may throw libvirtError if undefined
|
||||||
@ -377,16 +381,20 @@ class SystemTestsMixin(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
vm.libvirt_domain.undefine()
|
vm.libvirt_domain.undefine()
|
||||||
except libvirt.libvirtError:
|
except (AttributeError, libvirt.libvirtError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
del self.app.domains[vm]
|
del app.domains[vm]
|
||||||
del vm
|
del vm
|
||||||
|
|
||||||
|
app.save()
|
||||||
|
del app
|
||||||
|
|
||||||
# Now ensure it really went away. This may not have happened,
|
# Now ensure it really went away. This may not have happened,
|
||||||
# for example if vm.libvirt_domain malfunctioned.
|
# for example if vm.libvirt_domain malfunctioned.
|
||||||
try:
|
try:
|
||||||
dom = self.conn.lookupByName(vmname)
|
conn = libvirt.open(qubes.config.defaults['libvirt_uri'])
|
||||||
|
dom = conn.lookupByName(vmname)
|
||||||
except: # pylint: disable=bare-except
|
except: # pylint: disable=bare-except
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@ -422,7 +430,6 @@ class SystemTestsMixin(object):
|
|||||||
def remove_vms(self, vms):
|
def remove_vms(self, vms):
|
||||||
for vm in vms:
|
for vm in vms:
|
||||||
self._remove_vm_qubes(vm)
|
self._remove_vm_qubes(vm)
|
||||||
self.save_and_reload_db()
|
|
||||||
|
|
||||||
|
|
||||||
def remove_test_vms(self):
|
def remove_test_vms(self):
|
||||||
@ -436,16 +443,14 @@ class SystemTestsMixin(object):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
# first, remove them Qubes-way
|
# first, remove them Qubes-way
|
||||||
something_removed = False
|
if os.path.exists(XMLPATH):
|
||||||
for vm in self.app.domains:
|
self.remove_vms(vm for vm in qubes.Qubes(XMLPATH).domains
|
||||||
if vm.name.startswith(VMPREFIX):
|
if vm.name != TEMPLATE)
|
||||||
self._remove_vm_qubes(vm)
|
os.unlink(XMLPATH)
|
||||||
something_removed = True
|
|
||||||
if something_removed:
|
|
||||||
self.save_and_reload_db()
|
|
||||||
|
|
||||||
# now remove what was only in libvirt
|
# 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):
|
if dom.name().startswith(VMPREFIX):
|
||||||
self._remove_vm_libvirt(dom)
|
self._remove_vm_libvirt(dom)
|
||||||
|
|
||||||
@ -478,13 +483,16 @@ def load_tests(loader, tests, pattern): # pylint: disable=unused-argument
|
|||||||
'qubes.tests.tools',
|
'qubes.tests.tools',
|
||||||
|
|
||||||
# integration tests
|
# integration tests
|
||||||
# 'qubes.tests.init.basic',
|
# 'qubes.tests.int.basic',
|
||||||
# 'qubes.tests.dom0_update',
|
# 'qubes.tests.dom0_update',
|
||||||
# 'qubes.tests.network',
|
# 'qubes.tests.network',
|
||||||
# 'qubes.tests.vm_qrexec_gui',
|
# 'qubes.tests.vm_qrexec_gui',
|
||||||
# 'qubes.tests.backup',
|
# 'qubes.tests.backup',
|
||||||
# 'qubes.tests.backupcompatibility',
|
# 'qubes.tests.backupcompatibility',
|
||||||
# 'qubes.tests.regressions',
|
# 'qubes.tests.regressions',
|
||||||
|
|
||||||
|
# tool tests
|
||||||
|
'qubes.tests.int.tools.qubes_create',
|
||||||
):
|
):
|
||||||
tests.addTests(loader.loadTestsFromName(modname))
|
tests.addTests(loader.loadTestsFromName(modname))
|
||||||
|
|
||||||
|
0
qubes/tests/int/__init__.py
Normal file
0
qubes/tests/int/__init__.py
Normal file
@ -12,12 +12,12 @@
|
|||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
# the Free Software Foundation; either version 2 of the License, or
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
# (at your option) any later version.
|
# (at your option) any later version.
|
||||||
#
|
#
|
||||||
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License along
|
# 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.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
@ -31,13 +31,26 @@ import unittest
|
|||||||
import time
|
import time
|
||||||
from qubes.qubes import QubesVmCollection, QubesException, system_path
|
from qubes.qubes import QubesVmCollection, QubesException, system_path
|
||||||
|
|
||||||
import qubes.qubes
|
import qubes
|
||||||
|
import qubes.vm.qubesvm
|
||||||
import qubes.tests
|
import qubes.tests
|
||||||
|
|
||||||
class TC_00_Basic(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
|
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')
|
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())
|
name=vmname, template=self.qc.get_default_template())
|
||||||
|
|
||||||
self.assertIsNotNone(vm)
|
self.assertIsNotNone(vm)
|
0
qubes/tests/int/tools/__init__.py
Normal file
0
qubes/tests/int/tools/__init__.py
Normal file
47
qubes/tests/int/tools/qubes_create.py
Normal file
47
qubes/tests/int/tools/qubes_create.py
Normal 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)
|
@ -253,6 +253,14 @@ fi
|
|||||||
%{python_sitelib}/qubes/tests/tools/init.py*
|
%{python_sitelib}/qubes/tests/tools/init.py*
|
||||||
%{python_sitelib}/qubes/tests/tools/qvm_ls.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
|
%dir %{python_sitelib}/qubes/qmemman
|
||||||
%{python_sitelib}/qubes/qmemman/__init__.py*
|
%{python_sitelib}/qubes/qmemman/__init__.py*
|
||||||
%{python_sitelib}/qubes/qmemman/algo.py*
|
%{python_sitelib}/qubes/qmemman/algo.py*
|
||||||
|
Loading…
Reference in New Issue
Block a user