2015-01-19 19:02:28 +01:00
|
|
|
# pylint: disable=protected-access
|
2015-01-19 18:03:23 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# The Qubes OS Project, https://www.qubes-os.org/
|
|
|
|
#
|
|
|
|
# Copyright (C) 2014-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
|
|
|
|
# Copyright (C) 2014-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.
|
|
|
|
#
|
2017-01-18 22:16:46 +01:00
|
|
|
|
2016-02-10 17:41:05 +01:00
|
|
|
import os
|
2014-12-29 12:46:16 +01:00
|
|
|
|
|
|
|
import unittest
|
2015-12-30 01:48:37 +01:00
|
|
|
import uuid
|
2016-02-10 17:41:05 +01:00
|
|
|
import datetime
|
2014-12-29 12:46:16 +01:00
|
|
|
|
|
|
|
import qubes
|
2015-10-14 22:02:11 +02:00
|
|
|
import qubes.exc
|
2015-01-20 14:09:47 +01:00
|
|
|
import qubes.config
|
2014-12-29 12:46:16 +01:00
|
|
|
import qubes.vm.qubesvm
|
|
|
|
|
2015-01-05 14:41:59 +01:00
|
|
|
import qubes.tests
|
|
|
|
|
2015-12-30 01:48:37 +01:00
|
|
|
class TestApp(object):
|
|
|
|
labels = {1: qubes.Label(1, '0xcc0000', 'red')}
|
2014-12-29 12:46:16 +01:00
|
|
|
|
2016-02-10 17:41:05 +01:00
|
|
|
def __init__(self):
|
|
|
|
self.domains = {}
|
|
|
|
|
2014-12-29 12:46:16 +01:00
|
|
|
class TestProp(object):
|
2015-01-19 19:02:28 +01:00
|
|
|
# pylint: disable=too-few-public-methods
|
2014-12-29 12:46:16 +01:00
|
|
|
__name__ = 'testprop'
|
|
|
|
|
|
|
|
class TestVM(object):
|
2015-01-19 19:02:28 +01:00
|
|
|
# pylint: disable=too-few-public-methods
|
2015-12-30 01:48:37 +01:00
|
|
|
app = TestApp()
|
|
|
|
|
2016-02-10 17:41:05 +01:00
|
|
|
def __init__(self, **kwargs):
|
2014-12-29 12:46:16 +01:00
|
|
|
self.running = False
|
|
|
|
self.installed_by_rpm = False
|
2016-02-10 17:41:05 +01:00
|
|
|
for k, v in kwargs.items():
|
|
|
|
setattr(self, k, v)
|
2014-12-29 12:46:16 +01:00
|
|
|
|
|
|
|
def is_running(self):
|
|
|
|
return self.running
|
|
|
|
|
|
|
|
|
2015-01-05 14:41:59 +01:00
|
|
|
class TC_00_setters(qubes.tests.QubesTestCase):
|
2014-12-29 12:46:16 +01:00
|
|
|
def setUp(self):
|
2017-04-18 10:16:14 +02:00
|
|
|
super().setUp()
|
2014-12-29 12:46:16 +01:00
|
|
|
self.vm = TestVM()
|
|
|
|
self.prop = TestProp()
|
|
|
|
|
|
|
|
|
|
|
|
def test_000_setter_qid(self):
|
|
|
|
self.assertEqual(
|
|
|
|
qubes.vm.qubesvm._setter_qid(self.vm, self.prop, 5), 5)
|
|
|
|
|
|
|
|
def test_001_setter_qid_lt_0(self):
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
qubes.vm.qubesvm._setter_qid(self.vm, self.prop, -1)
|
|
|
|
|
|
|
|
def test_002_setter_qid_gt_max(self):
|
|
|
|
with self.assertRaises(ValueError):
|
2015-01-20 14:09:47 +01:00
|
|
|
qubes.vm.qubesvm._setter_qid(self.vm,
|
|
|
|
self.prop, qubes.config.max_qid + 5)
|
2014-12-29 12:46:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_010_setter_name(self):
|
|
|
|
self.assertEqual(
|
|
|
|
qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'test_name-1'),
|
|
|
|
'test_name-1')
|
|
|
|
|
2015-12-29 20:35:04 +01:00
|
|
|
def test_011_setter_name_not_a_string(self):
|
|
|
|
# pylint: disable=invalid-name
|
|
|
|
with self.assertRaises(TypeError):
|
|
|
|
qubes.vm.qubesvm._setter_name(self.vm, self.prop, False)
|
|
|
|
|
|
|
|
def test_012_setter_name_longer_than_31(self):
|
2015-01-19 19:02:28 +01:00
|
|
|
# pylint: disable=invalid-name
|
2014-12-29 12:46:16 +01:00
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
qubes.vm.qubesvm._setter_name(self.vm, self.prop, 't' * 32)
|
|
|
|
|
2015-12-29 20:35:04 +01:00
|
|
|
def test_013_setter_name_illegal_character(self):
|
2015-01-19 19:02:28 +01:00
|
|
|
# pylint: disable=invalid-name
|
2014-12-29 12:46:16 +01:00
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'test#')
|
|
|
|
|
2015-12-29 20:35:04 +01:00
|
|
|
def test_014_setter_name_first_not_letter(self):
|
2015-01-19 19:02:28 +01:00
|
|
|
# pylint: disable=invalid-name
|
2014-12-29 12:46:16 +01:00
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
qubes.vm.qubesvm._setter_name(self.vm, self.prop, '1test')
|
|
|
|
|
2015-12-29 20:35:04 +01:00
|
|
|
def test_015_setter_name_running(self):
|
2014-12-29 12:46:16 +01:00
|
|
|
self.vm.running = True
|
2015-10-14 22:02:11 +02:00
|
|
|
with self.assertRaises(qubes.exc.QubesVMNotHaltedError):
|
2014-12-29 12:46:16 +01:00
|
|
|
qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'testname')
|
|
|
|
|
2015-12-29 20:35:04 +01:00
|
|
|
def test_016_setter_name_installed_by_rpm(self):
|
2015-01-19 19:02:28 +01:00
|
|
|
# pylint: disable=invalid-name
|
2014-12-29 12:46:16 +01:00
|
|
|
self.vm.installed_by_rpm = True
|
2015-10-14 22:02:11 +02:00
|
|
|
with self.assertRaises(qubes.exc.QubesException):
|
2014-12-29 12:46:16 +01:00
|
|
|
qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'testname')
|
|
|
|
|
2016-02-10 17:41:05 +01:00
|
|
|
def test_017_setter_name_duplicate(self):
|
|
|
|
# pylint: disable=invalid-name
|
|
|
|
self.vm.app.domains['duplicate'] = TestVM(name='duplicate')
|
|
|
|
with self.assertRaises(qubes.exc.QubesException):
|
|
|
|
qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'duplicate')
|
|
|
|
|
2014-12-29 12:46:16 +01:00
|
|
|
|
|
|
|
@unittest.skip('test not implemented')
|
|
|
|
def test_020_setter_kernel(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2015-12-30 01:48:37 +01:00
|
|
|
def test_030_setter_label_object(self):
|
|
|
|
label = TestApp.labels[1]
|
|
|
|
self.assertIs(label,
|
|
|
|
qubes.vm.qubesvm._setter_label(self.vm, self.prop, label))
|
|
|
|
|
|
|
|
def test_031_setter_label_getitem(self):
|
|
|
|
label = TestApp.labels[1]
|
|
|
|
self.assertIs(label,
|
|
|
|
qubes.vm.qubesvm._setter_label(self.vm, self.prop, 'label-1'))
|
|
|
|
|
|
|
|
# there is no check for self.app.get_label()
|
|
|
|
|
|
|
|
|
2016-04-20 13:41:33 +02:00
|
|
|
class QubesVMTestsMixin(object):
|
|
|
|
property_no_default = object()
|
|
|
|
|
2015-12-29 20:35:04 +01:00
|
|
|
def setUp(self):
|
2016-04-20 13:41:33 +02:00
|
|
|
super(QubesVMTestsMixin, self).setUp()
|
2015-12-29 20:35:04 +01:00
|
|
|
self.app = qubes.tests.vm.TestApp()
|
2016-05-21 03:30:53 +02:00
|
|
|
self.app.vmm.offline_mode = True
|
2015-12-29 20:35:04 +01:00
|
|
|
|
2015-12-30 01:48:37 +01:00
|
|
|
def get_vm(self, **kwargs):
|
|
|
|
return qubes.vm.qubesvm.QubesVM(self.app, None,
|
|
|
|
qid=1, name=qubes.tests.VMPREFIX + 'test',
|
|
|
|
**kwargs)
|
|
|
|
|
2016-02-10 17:41:05 +01:00
|
|
|
def assertPropertyValue(self, vm, prop_name, set_value, expected_value,
|
|
|
|
expected_xml_content=None):
|
|
|
|
# FIXME: any better exception list? or maybe all of that should be a
|
|
|
|
# single exception?
|
|
|
|
with self.assertNotRaises((ValueError, TypeError, KeyError)):
|
|
|
|
setattr(vm, prop_name, set_value)
|
2017-05-29 16:42:40 +02:00
|
|
|
self.assertEqual(getattr(vm, prop_name), expected_value)
|
2016-02-10 17:41:05 +01:00
|
|
|
if expected_xml_content is not None:
|
|
|
|
xml = vm.__xml__()
|
|
|
|
prop_xml = xml.xpath(
|
|
|
|
'./properties/property[@name=\'{}\']'.format(prop_name))
|
2017-05-29 16:42:40 +02:00
|
|
|
self.assertEqual(len(prop_xml), 1, "Property not found in XML")
|
|
|
|
self.assertEqual(prop_xml[0].text, expected_xml_content)
|
2016-02-10 17:41:05 +01:00
|
|
|
|
|
|
|
def assertPropertyInvalidValue(self, vm, prop_name, set_value):
|
|
|
|
orig_value_set = True
|
|
|
|
orig_value = None
|
|
|
|
try:
|
|
|
|
orig_value = getattr(vm, prop_name)
|
|
|
|
except AttributeError:
|
|
|
|
orig_value_set = False
|
|
|
|
# FIXME: any better exception list? or maybe all of that should be a
|
|
|
|
# single exception?
|
|
|
|
with self.assertRaises((ValueError, TypeError, KeyError)):
|
|
|
|
setattr(vm, prop_name, set_value)
|
|
|
|
if orig_value_set:
|
2017-05-29 16:42:40 +02:00
|
|
|
self.assertEqual(getattr(vm, prop_name), orig_value)
|
2016-02-10 17:41:05 +01:00
|
|
|
else:
|
|
|
|
with self.assertRaises(AttributeError):
|
|
|
|
getattr(vm, prop_name)
|
|
|
|
|
|
|
|
def assertPropertyDefaultValue(self, vm, prop_name,
|
|
|
|
expected_default=property_no_default):
|
|
|
|
if expected_default is self.property_no_default:
|
|
|
|
with self.assertRaises(AttributeError):
|
|
|
|
getattr(vm, prop_name)
|
|
|
|
else:
|
|
|
|
with self.assertNotRaises(AttributeError):
|
2017-05-29 16:42:40 +02:00
|
|
|
self.assertEqual(getattr(vm, prop_name), expected_default)
|
2016-02-10 17:41:05 +01:00
|
|
|
xml = vm.__xml__()
|
|
|
|
prop_xml = xml.xpath(
|
|
|
|
'./properties/property[@name=\'{}\']'.format(prop_name))
|
2017-05-29 16:42:40 +02:00
|
|
|
self.assertEqual(len(prop_xml), 0, "Property still found in XML")
|
2016-02-10 17:41:05 +01:00
|
|
|
|
|
|
|
def _test_generic_bool_property(self, vm, prop_name, default=False):
|
|
|
|
self.assertPropertyDefaultValue(vm, prop_name, default)
|
|
|
|
self.assertPropertyValue(vm, prop_name, False, False, 'False')
|
|
|
|
self.assertPropertyValue(vm, prop_name, True, True, 'True')
|
|
|
|
delattr(vm, prop_name)
|
|
|
|
self.assertPropertyDefaultValue(vm, prop_name, default)
|
|
|
|
self.assertPropertyValue(vm, prop_name, 'True', True, 'True')
|
|
|
|
self.assertPropertyValue(vm, prop_name, 'False', False, 'False')
|
|
|
|
self.assertPropertyInvalidValue(vm, prop_name, 'xxx')
|
|
|
|
self.assertPropertyValue(vm, prop_name, 123, True)
|
|
|
|
self.assertPropertyInvalidValue(vm, prop_name, '')
|
|
|
|
|
|
|
|
|
2016-04-20 13:41:33 +02:00
|
|
|
class TC_90_QubesVM(QubesVMTestsMixin,qubes.tests.QubesTestCase):
|
2015-01-19 17:06:30 +01:00
|
|
|
def test_000_init(self):
|
2015-12-30 01:48:37 +01:00
|
|
|
self.get_vm()
|
2015-12-29 20:35:04 +01:00
|
|
|
|
|
|
|
def test_001_init_no_qid_or_name(self):
|
|
|
|
with self.assertRaises(AssertionError):
|
|
|
|
qubes.vm.qubesvm.QubesVM(self.app, None,
|
|
|
|
name=qubes.tests.VMPREFIX + 'test')
|
|
|
|
with self.assertRaises(AssertionError):
|
|
|
|
qubes.vm.qubesvm.QubesVM(self.app, None,
|
|
|
|
qid=1)
|
|
|
|
|
|
|
|
def test_003_init_fire_domain_init(self):
|
|
|
|
class TestVM2(qubes.vm.qubesvm.QubesVM):
|
|
|
|
event_fired = False
|
|
|
|
@qubes.events.handler('domain-init')
|
2015-12-29 22:04:00 +01:00
|
|
|
def on_domain_init(self, event): # pylint: disable=unused-argument
|
2015-12-29 20:35:04 +01:00
|
|
|
self.__class__.event_fired = True
|
|
|
|
|
2015-12-29 22:04:00 +01:00
|
|
|
TestVM2(self.app, None, qid=1, name=qubes.tests.VMPREFIX + 'test')
|
2015-12-29 20:35:04 +01:00
|
|
|
self.assertTrue(TestVM2.event_fired)
|
2015-12-30 01:48:37 +01:00
|
|
|
|
|
|
|
def test_004_uuid_autogen(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.assertTrue(hasattr(vm, 'uuid'))
|
|
|
|
|
|
|
|
def test_100_qid(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.assertIsInstance(vm.qid, int)
|
|
|
|
with self.assertRaises(AttributeError):
|
|
|
|
vm.qid = 2
|
|
|
|
|
|
|
|
def test_110_name(self):
|
|
|
|
vm = self.get_vm()
|
2017-01-18 22:16:46 +01:00
|
|
|
self.assertIsInstance(vm.name, str)
|
2015-12-30 01:48:37 +01:00
|
|
|
|
|
|
|
def test_120_uuid(self):
|
|
|
|
my_uuid = uuid.uuid4()
|
|
|
|
vm = self.get_vm(uuid=my_uuid)
|
|
|
|
self.assertIsInstance(vm.uuid, uuid.UUID)
|
|
|
|
self.assertIs(vm.uuid, my_uuid)
|
|
|
|
with self.assertRaises(AttributeError):
|
|
|
|
vm.uuid = uuid.uuid4()
|
|
|
|
|
2016-02-10 17:41:05 +01:00
|
|
|
@unittest.skip('TODO: how to not fail on making an icon symlink here?')
|
|
|
|
def test_130_label(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.assertPropertyDefaultValue(vm, 'label')
|
|
|
|
self.assertPropertyValue(vm, 'label', self.app.labels[1],
|
|
|
|
self.app.labels[1], 'label-1')
|
|
|
|
del vm.label
|
|
|
|
self.assertPropertyDefaultValue(vm, 'label')
|
|
|
|
self.assertPropertyValue(vm, 'label', 'red',
|
|
|
|
self.app.labels[1], 'label-1')
|
|
|
|
self.assertPropertyValue(vm, 'label', 'label-1',
|
|
|
|
self.app.labels[1], 'label-1')
|
2016-02-10 19:26:07 +01:00
|
|
|
|
|
|
|
def test_131_label_invalid(self):
|
|
|
|
vm = self.get_vm()
|
2016-02-10 17:41:05 +01:00
|
|
|
self.assertPropertyInvalidValue(vm, 'label', 'invalid')
|
|
|
|
self.assertPropertyInvalidValue(vm, 'label', 123)
|
|
|
|
|
|
|
|
def test_150_hvm(self):
|
|
|
|
vm = self.get_vm()
|
2017-06-01 03:51:24 +02:00
|
|
|
self._test_generic_bool_property(vm, 'hvm', default=True)
|
2016-02-10 17:41:05 +01:00
|
|
|
|
|
|
|
def test_160_memory(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.assertPropertyDefaultValue(vm, 'memory', 400)
|
|
|
|
self.assertPropertyValue(vm, 'memory', 500, 500, '500')
|
|
|
|
del vm.memory
|
|
|
|
self.assertPropertyDefaultValue(vm, 'memory', 400)
|
|
|
|
self.assertPropertyValue(vm, 'memory', '500', 500, '500')
|
2016-02-10 19:26:07 +01:00
|
|
|
|
|
|
|
def test_161_memory_invalid(self):
|
|
|
|
vm = self.get_vm()
|
2016-02-10 17:41:05 +01:00
|
|
|
self.assertPropertyInvalidValue(vm, 'memory', -100)
|
|
|
|
self.assertPropertyInvalidValue(vm, 'memory', '-100')
|
|
|
|
self.assertPropertyInvalidValue(vm, 'memory', '')
|
|
|
|
# TODO: higher than maxmem
|
|
|
|
# TODO: human readable setter (500M, 4G)?
|
|
|
|
|
|
|
|
def test_170_maxmem(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.assertPropertyDefaultValue(vm, 'maxmem',
|
2016-02-10 18:15:16 +01:00
|
|
|
self.app.host.memory_total / 1024 / 2)
|
2016-02-10 17:41:05 +01:00
|
|
|
self.assertPropertyValue(vm, 'maxmem', 500, 500, '500')
|
|
|
|
del vm.maxmem
|
|
|
|
self.assertPropertyDefaultValue(vm, 'maxmem',
|
2016-02-10 18:15:16 +01:00
|
|
|
self.app.host.memory_total / 1024 / 2)
|
2016-02-10 17:41:05 +01:00
|
|
|
self.assertPropertyValue(vm, 'maxmem', '500', 500, '500')
|
2016-02-10 19:26:07 +01:00
|
|
|
|
|
|
|
def test_171_maxmem_invalid(self):
|
|
|
|
vm = self.get_vm()
|
2016-02-10 17:41:05 +01:00
|
|
|
self.assertPropertyInvalidValue(vm, 'maxmem', -100)
|
|
|
|
self.assertPropertyInvalidValue(vm, 'maxmem', '-100')
|
|
|
|
self.assertPropertyInvalidValue(vm, 'maxmem', '')
|
|
|
|
# TODO: lower than memory
|
|
|
|
# TODO: human readable setter (500M, 4G)?
|
|
|
|
|
|
|
|
def test_180_internal(self):
|
2016-05-05 14:38:04 +02:00
|
|
|
vm = self.get_vm(label='red')
|
2016-02-10 17:41:05 +01:00
|
|
|
self._test_generic_bool_property(vm, 'internal', False)
|
|
|
|
|
|
|
|
def test_190_vcpus(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.assertPropertyDefaultValue(vm, 'vcpus', self.app.host.no_cpus)
|
|
|
|
self.assertPropertyValue(vm, 'vcpus', 3, 3, '3')
|
|
|
|
del vm.vcpus
|
|
|
|
self.assertPropertyDefaultValue(vm, 'vcpus', self.app.host.no_cpus)
|
|
|
|
self.assertPropertyValue(vm, 'vcpus', '3', 3, '3')
|
2016-02-10 19:26:07 +01:00
|
|
|
|
|
|
|
def test_191_vcpus_invalid(self):
|
|
|
|
vm = self.get_vm()
|
2016-02-10 17:41:05 +01:00
|
|
|
self.assertPropertyInvalidValue(vm, 'vcpus', 0)
|
|
|
|
self.assertPropertyInvalidValue(vm, 'vcpus', -2)
|
|
|
|
self.assertPropertyInvalidValue(vm, 'vcpus', '-2')
|
|
|
|
self.assertPropertyInvalidValue(vm, 'vcpus', '')
|
|
|
|
|
|
|
|
def test_200_debug(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self._test_generic_bool_property(vm, 'debug', False)
|
|
|
|
|
|
|
|
def test_210_installed_by_rpm(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self._test_generic_bool_property(vm, 'installed_by_rpm', False)
|
|
|
|
|
|
|
|
def test_220_include_in_backups(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self._test_generic_bool_property(vm, 'include_in_backups', True)
|
|
|
|
|
2015-12-30 01:48:37 +01:00
|
|
|
@qubes.tests.skipUnlessDom0
|
2016-02-10 17:41:05 +01:00
|
|
|
def test_250_kernel(self):
|
|
|
|
kernels = os.listdir(os.path.join(
|
|
|
|
qubes.config.qubes_base_dir,
|
|
|
|
qubes.config.system_path['qubes_kernels_base_dir']))
|
|
|
|
if not len(kernels):
|
|
|
|
self.skipTest('Needs at least one kernel installed')
|
|
|
|
self.app.default_kernel = kernels[0]
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.assertPropertyDefaultValue(vm, 'kernel', kernels[0])
|
|
|
|
self.assertPropertyValue(vm, 'kernel', kernels[-1], kernels[-1],
|
|
|
|
kernels[-1])
|
|
|
|
del vm.kernel
|
|
|
|
self.assertPropertyDefaultValue(vm, 'kernel', kernels[0])
|
2016-02-10 19:26:07 +01:00
|
|
|
|
|
|
|
@qubes.tests.skipUnlessDom0
|
|
|
|
def test_251_kernel_invalid(self):
|
|
|
|
vm = self.get_vm()
|
2016-02-10 17:41:05 +01:00
|
|
|
self.assertPropertyInvalidValue(vm, 'kernel', 123)
|
|
|
|
self.assertPropertyInvalidValue(vm, 'kernel', 'invalid')
|
|
|
|
|
|
|
|
def test_260_kernelopts(self):
|
2015-12-30 01:48:37 +01:00
|
|
|
vm = self.get_vm()
|
2016-02-10 17:41:05 +01:00
|
|
|
self.assertPropertyDefaultValue(vm, 'kernelopts',
|
|
|
|
qubes.config.defaults['kernelopts'])
|
|
|
|
self.assertPropertyValue(vm, 'kernelopts', 'some options',
|
|
|
|
'some options', 'some options')
|
|
|
|
del vm.kernelopts
|
|
|
|
self.assertPropertyDefaultValue(vm, 'kernelopts',
|
|
|
|
qubes.config.defaults['kernelopts'])
|
|
|
|
self.assertPropertyValue(vm, 'kernelopts', '',
|
|
|
|
'', '')
|
|
|
|
# TODO?
|
|
|
|
# self.assertPropertyInvalidValue(vm, 'kernelopts', None),
|
2015-12-30 01:48:37 +01:00
|
|
|
|
|
|
|
@unittest.skip('test not implemented')
|
2016-02-10 17:41:05 +01:00
|
|
|
def test_261_kernelopts_pcidevs(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
# how to do that here? use dummy DeviceManager/DeviceCollection?
|
|
|
|
# Disable events?
|
|
|
|
vm.devices['pci'].attach('something')
|
|
|
|
self.assertPropertyDefaultValue(vm, 'kernelopts',
|
|
|
|
qubes.config.defaults['kernelopts_pcidevs'])
|
|
|
|
|
|
|
|
def test_270_qrexec_timeout(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.assertPropertyDefaultValue(vm, 'qrexec_timeout', 60)
|
|
|
|
self.assertPropertyValue(vm, 'qrexec_timeout', 3, 3, '3')
|
|
|
|
del vm.qrexec_timeout
|
|
|
|
self.assertPropertyDefaultValue(vm, 'qrexec_timeout', 60)
|
|
|
|
self.assertPropertyValue(vm, 'qrexec_timeout', '3', 3, '3')
|
2016-02-10 19:26:07 +01:00
|
|
|
|
|
|
|
def test_271_qrexec_timeout_invalid(self):
|
|
|
|
vm = self.get_vm()
|
2016-02-10 17:41:05 +01:00
|
|
|
self.assertPropertyInvalidValue(vm, 'qrexec_timeout', -2)
|
|
|
|
self.assertPropertyInvalidValue(vm, 'qrexec_timeout', '-2')
|
|
|
|
self.assertPropertyInvalidValue(vm, 'qrexec_timeout', '')
|
|
|
|
|
|
|
|
def test_280_autostart(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
# FIXME any better idea to not involve systemctl call at this stage?
|
|
|
|
vm.events_enabled = False
|
|
|
|
self._test_generic_bool_property(vm, 'autostart', False)
|
|
|
|
|
|
|
|
@qubes.tests.skipUnlessDom0
|
|
|
|
def test_281_autostart_systemd(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.assertFalse(os.path.exists(
|
|
|
|
'/etc/systemd/system/multi-user.target.wants/'
|
|
|
|
'qubes-vm@{}.service'.format(vm.name)),
|
|
|
|
"systemd service enabled before setting autostart")
|
|
|
|
vm.autostart = True
|
|
|
|
self.assertTrue(os.path.exists(
|
|
|
|
'/etc/systemd/system/multi-user.target.wants/'
|
|
|
|
'qubes-vm@{}.service'.format(vm.name)),
|
|
|
|
"systemd service not enabled by autostart=True")
|
|
|
|
vm.autostart = False
|
|
|
|
self.assertFalse(os.path.exists(
|
|
|
|
'/etc/systemd/system/multi-user.target.wants/'
|
|
|
|
'qubes-vm@{}.service'.format(vm.name)),
|
|
|
|
"systemd service not disabled by autostart=False")
|
|
|
|
vm.autostart = True
|
|
|
|
del vm.autostart
|
|
|
|
self.assertFalse(os.path.exists(
|
|
|
|
'/etc/systemd/system/multi-user.target.wants/'
|
|
|
|
'qubes-vm@{}.service'.format(vm.name)),
|
|
|
|
"systemd service not disabled by resetting autostart")
|
|
|
|
|
|
|
|
@unittest.skip('TODO')
|
|
|
|
def test_300_qrexec_installed(self):
|
|
|
|
vm = self.get_vm()
|
2016-02-10 18:48:05 +01:00
|
|
|
self._test_generic_bool_property(vm, 'qrexec_installed', True)
|
|
|
|
|
|
|
|
@unittest.skip('TODO')
|
|
|
|
def test_301_qrexec_installed_default(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
vm.hvm = False
|
|
|
|
self.assertPropertyDefaultValue(vm, 'qrexec_installed', True)
|
|
|
|
vm.hvm = True
|
|
|
|
self.assertPropertyDefaultValue(vm, 'qrexec_installed', False)
|
2016-02-10 17:41:05 +01:00
|
|
|
# TODO: check inheritance from a template - in appvm copy of this test
|
|
|
|
|
|
|
|
@unittest.skip('TODO')
|
|
|
|
def test_310_guiagent_installed(self):
|
|
|
|
vm = self.get_vm()
|
2016-02-10 18:48:05 +01:00
|
|
|
self._test_generic_bool_property(vm, 'guiagent_installed', True)
|
|
|
|
# TODO: check inheritance from a template - in appvm copy of this test
|
|
|
|
|
|
|
|
@unittest.skip('TODO')
|
|
|
|
def test_311_guiagent_installed_default(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
vm.hvm = False
|
|
|
|
self.assertPropertyDefaultValue(vm, 'guiagent_installed', True)
|
|
|
|
vm.hvm = True
|
|
|
|
self.assertPropertyDefaultValue(vm, 'guiagent_installed', False)
|
2016-02-10 17:41:05 +01:00
|
|
|
# TODO: check inheritance from a template - in appvm copy of this test
|
|
|
|
|
|
|
|
@unittest.skip('TODO')
|
2016-02-10 18:48:05 +01:00
|
|
|
def test_320_seamless_gui_mode(self):
|
2016-02-10 17:41:05 +01:00
|
|
|
vm = self.get_vm()
|
|
|
|
self._test_generic_bool_property(vm, 'seamless_gui_mode')
|
|
|
|
# TODO: reject setting to True when guiagent_installed is false
|
|
|
|
|
|
|
|
def test_330_mac(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
# TODO: calculate proper default here
|
|
|
|
default_mac = vm.mac
|
|
|
|
self.assertIsNotNone(default_mac)
|
|
|
|
self.assertPropertyDefaultValue(vm, 'mac', default_mac)
|
|
|
|
self.assertPropertyValue(vm, 'mac', '00:11:22:33:44:55',
|
|
|
|
'00:11:22:33:44:55', '00:11:22:33:44:55')
|
|
|
|
del vm.mac
|
|
|
|
self.assertPropertyDefaultValue(vm, 'mac', default_mac)
|
2016-02-10 19:26:07 +01:00
|
|
|
|
|
|
|
def test_331_mac_invalid(self):
|
|
|
|
vm = self.get_vm()
|
2016-02-10 17:41:05 +01:00
|
|
|
self.assertPropertyInvalidValue(vm, 'mac', 123)
|
|
|
|
self.assertPropertyInvalidValue(vm, 'mac', 'invalid')
|
|
|
|
self.assertPropertyInvalidValue(vm, 'mac', '00:11:22:33:44:55:66')
|
|
|
|
|
|
|
|
def test_340_default_user(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.assertPropertyDefaultValue(vm, 'default_user', 'user')
|
|
|
|
self.assertPropertyValue(vm, 'default_user', 'someuser', 'someuser',
|
|
|
|
'someuser')
|
|
|
|
del vm.default_user
|
|
|
|
self.assertPropertyDefaultValue(vm, 'default_user', 'user')
|
|
|
|
self.assertPropertyValue(vm, 'default_user', 123, '123', '123')
|
|
|
|
# TODO: check propagation for template-based VMs
|
|
|
|
|
|
|
|
@unittest.skip('TODO')
|
|
|
|
def test_350_timezone(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.assertPropertyDefaultValue(vm, 'timezone', 'localtime')
|
|
|
|
self.assertPropertyValue(vm, 'timezone', 0, 0, '0')
|
|
|
|
del vm.timezone
|
|
|
|
self.assertPropertyDefaultValue(vm, 'timezone', 'localtime')
|
|
|
|
self.assertPropertyValue(vm, 'timezone', '0', 0, '0')
|
|
|
|
self.assertPropertyValue(vm, 'timezone', -3600, -3600, '-3600')
|
|
|
|
self.assertPropertyValue(vm, 'timezone', 7200, 7200, '7200')
|
|
|
|
|
2016-02-10 19:26:07 +01:00
|
|
|
@unittest.skip('TODO')
|
|
|
|
def test_350_timezone_invalid(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.assertPropertyInvalidValue(vm, 'timezone', 'xxx')
|
|
|
|
|
2016-02-10 17:41:05 +01:00
|
|
|
@unittest.skip('TODO')
|
|
|
|
def test_360_drive(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.assertPropertyDefaultValue(vm, 'drive', None)
|
|
|
|
# self.execute_tests('drive', [
|
|
|
|
# ('hd:dom0:/tmp/drive.img', 'hd:dom0:/tmp/drive.img', True),
|
|
|
|
# ('hd:/tmp/drive.img', 'hd:dom0:/tmp/drive.img', True),
|
|
|
|
# ('cdrom:dom0:/tmp/drive.img', 'cdrom:dom0:/tmp/drive.img', True),
|
|
|
|
# ('cdrom:/tmp/drive.img', 'cdrom:dom0:/tmp/drive.img', True),
|
|
|
|
# ('/tmp/drive.img', 'cdrom:dom0:/tmp/drive.img', True),
|
|
|
|
# ('hd:drive.img', '', False),
|
|
|
|
# ('drive.img', '', False),
|
|
|
|
# ])
|
|
|
|
|
|
|
|
@unittest.skip('TODO')
|
|
|
|
def test_370_pci_strictreset(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self._test_generic_bool_property(vm, 'pci_strictreset')
|
|
|
|
|
|
|
|
def test_400_backup_timestamp(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
timestamp = datetime.datetime(2016, 1, 1, 12, 14, 2)
|
|
|
|
timestamp_str = timestamp.strftime('%s')
|
|
|
|
self.assertPropertyDefaultValue(vm, 'backup_timestamp', None)
|
|
|
|
self.assertPropertyValue(vm, 'backup_timestamp', timestamp,
|
|
|
|
timestamp, timestamp_str)
|
|
|
|
del vm.backup_timestamp
|
|
|
|
self.assertPropertyDefaultValue(vm, 'backup_timestamp', None)
|
|
|
|
self.assertPropertyValue(vm, 'backup_timestamp', timestamp_str,
|
|
|
|
timestamp)
|
2016-02-10 19:26:07 +01:00
|
|
|
|
|
|
|
def test_401_backup_timestamp_invalid(self):
|
|
|
|
vm = self.get_vm()
|
2016-02-10 17:41:05 +01:00
|
|
|
self.assertPropertyInvalidValue(vm, 'backup_timestamp', 'xxx')
|
|
|
|
self.assertPropertyInvalidValue(vm, 'backup_timestamp', None)
|