tests: migrate qvm-block tests to core3
This commit is contained in:
parent
399d2138bd
commit
d23636fa02
@ -1286,6 +1286,7 @@ def load_tests(loader, tests, pattern): # pylint: disable=unused-argument
|
|||||||
'qubes.tests.integ.basic',
|
'qubes.tests.integ.basic',
|
||||||
'qubes.tests.integ.storage',
|
'qubes.tests.integ.storage',
|
||||||
'qubes.tests.integ.pvgrub',
|
'qubes.tests.integ.pvgrub',
|
||||||
|
'qubes.tests.integ.devices_block',
|
||||||
'qubes.tests.integ.devices_pci',
|
'qubes.tests.integ.devices_pci',
|
||||||
'qubes.tests.integ.dom0_update',
|
'qubes.tests.integ.dom0_update',
|
||||||
'qubes.tests.integ.network',
|
'qubes.tests.integ.network',
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# The Qubes OS Project, https://www.qubes-os.org/
|
# The Qubes OS Project, https://www.qubes-os.org/
|
||||||
#
|
#
|
||||||
# Copyright (C) 2016
|
# Copyright (C) 2018
|
||||||
# Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
|
# Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
|
||||||
#
|
#
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
@ -20,42 +20,44 @@
|
|||||||
#
|
#
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import qubes
|
||||||
import qubes.tests
|
import qubes.tests
|
||||||
import qubes.qubesutils
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
# the same class for both dom0 and VMs
|
# the same class for both dom0 and VMs
|
||||||
class TC_00_List(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
|
class TC_00_List(qubes.tests.SystemTestCase):
|
||||||
template = None
|
template = None
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TC_00_List, self).setUp()
|
super().setUp()
|
||||||
self.img_path = '/tmp/test.img'
|
self.img_path = '/tmp/test.img'
|
||||||
self.mount_point = '/tmp/test-dir'
|
self.mount_point = '/tmp/test-dir'
|
||||||
if self.template is not None:
|
if self.template is not None:
|
||||||
self.vm = self.qc.add_new_vm(
|
self.vm = self.app.add_new_vm(
|
||||||
"QubesAppVm",
|
"AppVM",
|
||||||
name=self.make_vm_name("vm"),
|
label='red',
|
||||||
template=self.qc.get_vm_by_name(self.template))
|
name=self.make_vm_name("vm"))
|
||||||
self.vm.create_on_disk(verbose=False)
|
self.loop.run_until_complete(
|
||||||
|
self.vm.create_on_disk())
|
||||||
self.app.save()
|
self.app.save()
|
||||||
self.qc.unlock_db()
|
self.loop.run_until_complete(self.vm.start())
|
||||||
self.vm.start()
|
|
||||||
else:
|
else:
|
||||||
self.qc.unlock_db()
|
self.vm = self.app.domains[0]
|
||||||
self.vm = self.qc[0]
|
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(TC_00_List, self).tearDown()
|
super().tearDown()
|
||||||
if self.template is None:
|
if self.template is None:
|
||||||
if os.path.exists(self.mount_point):
|
if os.path.exists(self.mount_point):
|
||||||
subprocess.call(['sudo', 'umount', self.mount_point])
|
subprocess.call(['sudo', 'umount', self.mount_point])
|
||||||
subprocess.call(['sudo', 'rmdir', self.mount_point])
|
subprocess.call(['sudo', 'rmdir', self.mount_point])
|
||||||
subprocess.call(['sudo', 'dmsetup', 'remove', 'test-dm'])
|
if os.path.exists('/dev/mapper/test-dm'):
|
||||||
|
subprocess.call(['sudo', 'dmsetup', 'remove', 'test-dm'])
|
||||||
if os.path.exists(self.img_path):
|
if os.path.exists(self.img_path):
|
||||||
loopdev = subprocess.check_output(['losetup', '-j',
|
loopdev = subprocess.check_output(['losetup', '-j',
|
||||||
self.img_path])
|
self.img_path])
|
||||||
for dev in loopdev.splitlines():
|
for dev in loopdev.decode().splitlines():
|
||||||
subprocess.call(
|
subprocess.call(
|
||||||
['sudo', 'losetup', '-d', dev.split(':')[0]])
|
['sudo', 'losetup', '-d', dev.split(':')[0]])
|
||||||
subprocess.call(['sudo', 'rm', '-f', self.img_path])
|
subprocess.call(['sudo', 'rm', '-f', self.img_path])
|
||||||
@ -67,9 +69,8 @@ class TC_00_List(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
|
|||||||
elif user == "root":
|
elif user == "root":
|
||||||
subprocess.check_call(['sudo', 'sh', '-c', script])
|
subprocess.check_call(['sudo', 'sh', '-c', script])
|
||||||
else:
|
else:
|
||||||
retcode = self.vm.run(script, user=user, wait=True)
|
self.loop.run_until_complete(
|
||||||
if retcode != 0:
|
self.vm.run_for_stdio(script, user=user))
|
||||||
raise subprocess.CalledProcessError
|
|
||||||
|
|
||||||
def test_000_list_loop(self):
|
def test_000_list_loop(self):
|
||||||
if self.template is None:
|
if self.template is None:
|
||||||
@ -80,19 +81,18 @@ class TC_00_List(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
|
|||||||
"losetup -f {path}; "
|
"losetup -f {path}; "
|
||||||
"udevadm settle".format(path=self.img_path), user="root")
|
"udevadm settle".format(path=self.img_path), user="root")
|
||||||
|
|
||||||
dev_list = qubes.qubesutils.block_list_vm(self.vm)
|
dev_list = list(self.vm.devices['block'])
|
||||||
found = False
|
found = False
|
||||||
for dev in dev_list.keys():
|
for dev in dev_list:
|
||||||
if dev_list[dev]['desc'] == self.img_path:
|
if dev.description == self.img_path:
|
||||||
self.assertTrue(dev.startswith(self.vm.name + ':loop'))
|
self.assertTrue(dev.ident.startswith('loop'))
|
||||||
self.assertEquals(dev_list[dev]['mode'], 'w')
|
self.assertEquals(dev.mode, 'w')
|
||||||
self.assertEquals(dev_list[dev]['size'], 1024 * 1024 * 128)
|
self.assertEquals(dev.size, 1024 * 1024 * 128)
|
||||||
self.assertEquals(
|
|
||||||
dev_list[dev]['device'], '/dev/' + dev.split(':')[1])
|
|
||||||
found = True
|
found = True
|
||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
self.fail("Device {} not found in {!r}".format(self.img_path, dev_list))
|
self.fail("Device {} not found in {!r}".format(
|
||||||
|
self.img_path, dev_list))
|
||||||
|
|
||||||
def test_001_list_loop_mounted(self):
|
def test_001_list_loop_mounted(self):
|
||||||
if self.template is None:
|
if self.template is None:
|
||||||
@ -108,9 +108,9 @@ class TC_00_List(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
|
|||||||
mntdir=self.mount_point),
|
mntdir=self.mount_point),
|
||||||
user="root")
|
user="root")
|
||||||
|
|
||||||
dev_list = qubes.qubesutils.block_list_vm(self.vm)
|
dev_list = list(self.vm.devices['block'])
|
||||||
for dev in dev_list.keys():
|
for dev in dev_list:
|
||||||
if dev_list[dev]['desc'] == self.img_path:
|
if dev.description == self.img_path:
|
||||||
self.fail(
|
self.fail(
|
||||||
'Device {} ({}) should not be listed because is mounted'
|
'Device {} ({}) should not be listed because is mounted'
|
||||||
.format(dev, self.img_path))
|
.format(dev, self.img_path))
|
||||||
@ -125,19 +125,17 @@ class TC_00_List(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
|
|||||||
"/sys/block/$(basename $loopdev)/dev) 0\";"
|
"/sys/block/$(basename $loopdev)/dev) 0\";"
|
||||||
"udevadm settle".format(path=self.img_path), user="root")
|
"udevadm settle".format(path=self.img_path), user="root")
|
||||||
|
|
||||||
dev_list = qubes.qubesutils.block_list_vm(self.vm)
|
dev_list = list(self.vm.devices['block'])
|
||||||
found = False
|
found = False
|
||||||
for dev in dev_list.keys():
|
for dev in dev_list:
|
||||||
if dev.startswith(self.vm.name + ':loop'):
|
if dev.ident.startswith('loop'):
|
||||||
self.assertNotEquals(dev_list[dev]['desc'], self.img_path,
|
self.assertNotEquals(dev.description, self.img_path,
|
||||||
"Device {} ({}) should not be listed as it is used in "
|
"Device {} ({}) should not be listed as it is used in "
|
||||||
"device-mapper".format(dev, self.img_path)
|
"device-mapper".format(dev, self.img_path)
|
||||||
)
|
)
|
||||||
elif dev_list[dev]['desc'] == 'test-dm':
|
elif dev.description == 'test-dm':
|
||||||
self.assertEquals(dev_list[dev]['mode'], 'w')
|
self.assertEquals(dev.mode, 'w')
|
||||||
self.assertEquals(dev_list[dev]['size'], 1024 * 1024 * 128)
|
self.assertEquals(dev.size, 1024 * 1024 * 128)
|
||||||
self.assertEquals(
|
|
||||||
dev_list[dev]['device'], '/dev/' + dev.split(':')[1])
|
|
||||||
found = True
|
found = True
|
||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
@ -159,15 +157,15 @@ class TC_00_List(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
|
|||||||
mntdir=self.mount_point),
|
mntdir=self.mount_point),
|
||||||
user="root")
|
user="root")
|
||||||
|
|
||||||
dev_list = qubes.qubesutils.block_list_vm(self.vm)
|
dev_list = list(self.vm.devices['block'])
|
||||||
for dev in dev_list.keys():
|
for dev in dev_list:
|
||||||
if dev.startswith(self.vm.name + ':loop'):
|
if dev.ident.startswith('loop'):
|
||||||
self.assertNotEquals(dev_list[dev]['desc'], self.img_path,
|
self.assertNotEquals(dev.description, self.img_path,
|
||||||
"Device {} ({}) should not be listed as it is used in "
|
"Device {} ({}) should not be listed as it is used in "
|
||||||
"device-mapper".format(dev, self.img_path)
|
"device-mapper".format(dev, self.img_path)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.assertNotEquals(dev_list[dev]['desc'], 'test-dm',
|
self.assertNotEquals(dev.description, 'test-dm',
|
||||||
"Device {} ({}) should not be listed as it is "
|
"Device {} ({}) should not be listed as it is "
|
||||||
"mounted".format(dev, 'test-dm')
|
"mounted".format(dev, 'test-dm')
|
||||||
)
|
)
|
||||||
@ -183,19 +181,17 @@ class TC_00_List(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
|
|||||||
"/sys/block/$(basename $loopdev)/dev) 0\";"
|
"/sys/block/$(basename $loopdev)/dev) 0\";"
|
||||||
"udevadm settle".format(path=self.img_path), user="root")
|
"udevadm settle".format(path=self.img_path), user="root")
|
||||||
|
|
||||||
dev_list = qubes.qubesutils.block_list_vm(self.vm)
|
dev_list = list(self.vm.devices['block'])
|
||||||
found = False
|
found = False
|
||||||
for dev in dev_list.keys():
|
for dev in dev_list:
|
||||||
if dev.startswith(self.vm.name + ':loop'):
|
if dev.ident.startswith('loop'):
|
||||||
self.assertNotEquals(dev_list[dev]['desc'], self.img_path,
|
self.assertNotEquals(dev.description, self.img_path,
|
||||||
"Device {} ({}) should not be listed as it is used in "
|
"Device {} ({}) should not be listed as it is used in "
|
||||||
"device-mapper".format(dev, self.img_path)
|
"device-mapper".format(dev, self.img_path)
|
||||||
)
|
)
|
||||||
elif dev_list[dev]['desc'] == 'test-dm':
|
elif dev.description == 'test-dm':
|
||||||
self.assertEquals(dev_list[dev]['mode'], 'w')
|
self.assertEquals(dev.mode, 'w')
|
||||||
self.assertEquals(dev_list[dev]['size'], 1024 * 1024 * 128)
|
self.assertEquals(dev.size, 1024 * 1024 * 128)
|
||||||
self.assertEquals(
|
|
||||||
dev_list[dev]['device'], '/dev/' + dev.split(':')[1])
|
|
||||||
found = True
|
found = True
|
||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
@ -216,15 +212,13 @@ class TC_00_List(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
|
|||||||
"dmsetup remove test-dm;"
|
"dmsetup remove test-dm;"
|
||||||
"udevadm settle".format(path=self.img_path), user="root")
|
"udevadm settle".format(path=self.img_path), user="root")
|
||||||
|
|
||||||
dev_list = qubes.qubesutils.block_list_vm(self.vm)
|
dev_list = list(self.vm.devices['block'])
|
||||||
found = False
|
found = False
|
||||||
for dev in dev_list.keys():
|
for dev in dev_list:
|
||||||
if dev_list[dev]['desc'] == self.img_path:
|
if dev.description == self.img_path:
|
||||||
self.assertTrue(dev.startswith(self.vm.name + ':loop'))
|
self.assertTrue(dev.ident.startswith('loop'))
|
||||||
self.assertEquals(dev_list[dev]['mode'], 'w')
|
self.assertEquals(dev.mode, 'w')
|
||||||
self.assertEquals(dev_list[dev]['size'], 1024 * 1024 * 128)
|
self.assertEquals(dev.size, 1024 * 1024 * 128)
|
||||||
self.assertEquals(
|
|
||||||
dev_list[dev]['device'], '/dev/' + dev.split(':')[1])
|
|
||||||
found = True
|
found = True
|
||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
@ -242,16 +236,14 @@ class TC_00_List(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
|
|||||||
"blockdev --rereadpt $loopdev; "
|
"blockdev --rereadpt $loopdev; "
|
||||||
"udevadm settle".format(path=self.img_path), user="root")
|
"udevadm settle".format(path=self.img_path), user="root")
|
||||||
|
|
||||||
dev_list = qubes.qubesutils.block_list_vm(self.vm)
|
dev_list = list(self.vm.devices['block'])
|
||||||
found = False
|
found = False
|
||||||
for dev in dev_list.keys():
|
for dev in dev_list:
|
||||||
if dev_list[dev]['desc'] == self.img_path:
|
if dev.description == self.img_path:
|
||||||
self.assertTrue(dev.startswith(self.vm.name + ':loop'))
|
self.assertTrue(dev.ident.startswith('loop'))
|
||||||
self.assertEquals(dev_list[dev]['mode'], 'w')
|
self.assertEquals(dev.mode, 'w')
|
||||||
self.assertEquals(dev_list[dev]['size'], 1024 * 1024 * 128)
|
self.assertEquals(dev.size, 1024 * 1024 * 128)
|
||||||
self.assertEquals(
|
self.assertIn(dev.ident + 'p1', [d.ident for d in dev_list])
|
||||||
dev_list[dev]['device'], '/dev/' + dev.split(':')[1])
|
|
||||||
self.assertIn(dev + 'p1', dev_list)
|
|
||||||
found = True
|
found = True
|
||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
@ -274,14 +266,14 @@ class TC_00_List(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
|
|||||||
path=self.img_path, mntdir=self.mount_point),
|
path=self.img_path, mntdir=self.mount_point),
|
||||||
user="root")
|
user="root")
|
||||||
|
|
||||||
dev_list = qubes.qubesutils.block_list_vm(self.vm)
|
dev_list = list(self.vm.devices['block'])
|
||||||
for dev in dev_list.keys():
|
for dev in dev_list:
|
||||||
if dev_list[dev]['desc'] == self.img_path:
|
if dev.description == self.img_path:
|
||||||
self.fail(
|
self.fail(
|
||||||
'Device {} ({}) should not be listed because its '
|
'Device {} ({}) should not be listed because its '
|
||||||
'partition is mounted'
|
'partition is mounted'
|
||||||
.format(dev, self.img_path))
|
.format(dev, self.img_path))
|
||||||
elif dev.startswith(self.vm.name + ':loop') and dev.endswith('p1'):
|
elif dev.ident.startswith('loop') and dev.ident.endswith('p1'):
|
||||||
# FIXME: risky assumption that only tests create partitioned
|
# FIXME: risky assumption that only tests create partitioned
|
||||||
# loop devices
|
# loop devices
|
||||||
self.fail(
|
self.fail(
|
||||||
@ -289,21 +281,14 @@ class TC_00_List(qubes.tests.SystemTestsMixin, qubes.tests.QubesTestCase):
|
|||||||
.format(dev, self.img_path))
|
.format(dev, self.img_path))
|
||||||
|
|
||||||
|
|
||||||
def load_tests(loader, tests, pattern):
|
def create_testcases_for_templates():
|
||||||
try:
|
return qubes.tests.create_testcases_for_templates('TC_00_List',
|
||||||
qc = qubes.qubes.QubesVmCollection()
|
TC_00_List,
|
||||||
qc.lock_db_for_reading()
|
module=sys.modules[__name__])
|
||||||
qc.load()
|
|
||||||
qc.unlock_db()
|
|
||||||
templates = [vm.name for vm in qc.values() if
|
|
||||||
isinstance(vm, qubes.qubes.QubesTemplateVm)]
|
|
||||||
except OSError:
|
|
||||||
templates = []
|
|
||||||
for template in templates:
|
|
||||||
tests.addTests(loader.loadTestsFromTestCase(
|
|
||||||
type(
|
|
||||||
'TC_00_List_' + template,
|
|
||||||
(TC_00_List, qubes.tests.QubesTestCase),
|
|
||||||
{'template': template})))
|
|
||||||
|
|
||||||
|
def load_tests(loader, tests, pattern):
|
||||||
|
tests.addTests(loader.loadTestsFromNames(
|
||||||
|
create_testcases_for_templates()))
|
||||||
return tests
|
return tests
|
||||||
|
|
||||||
|
qubes.tests.maybe_create_testcases_on_import(create_testcases_for_templates)
|
@ -339,6 +339,7 @@ fi
|
|||||||
%{python3_sitelib}/qubes/tests/integ/backup.py
|
%{python3_sitelib}/qubes/tests/integ/backup.py
|
||||||
%{python3_sitelib}/qubes/tests/integ/backupcompatibility.py
|
%{python3_sitelib}/qubes/tests/integ/backupcompatibility.py
|
||||||
%{python3_sitelib}/qubes/tests/integ/basic.py
|
%{python3_sitelib}/qubes/tests/integ/basic.py
|
||||||
|
%{python3_sitelib}/qubes/tests/integ/devices_block.py
|
||||||
%{python3_sitelib}/qubes/tests/integ/devices_pci.py
|
%{python3_sitelib}/qubes/tests/integ/devices_pci.py
|
||||||
%{python3_sitelib}/qubes/tests/integ/dispvm.py
|
%{python3_sitelib}/qubes/tests/integ/dispvm.py
|
||||||
%{python3_sitelib}/qubes/tests/integ/dom0_update.py
|
%{python3_sitelib}/qubes/tests/integ/dom0_update.py
|
||||||
|
Loading…
Reference in New Issue
Block a user