2015-12-29 20:35:04 +01:00
|
|
|
# pylint: disable=protected-access,pointless-statement
|
|
|
|
|
|
|
|
#
|
|
|
|
# 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>
|
|
|
|
#
|
2017-10-12 00:11:50 +02:00
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
2015-12-29 20:35:04 +01:00
|
|
|
#
|
2017-10-12 00:11:50 +02:00
|
|
|
# This library is distributed in the hope that it will be useful,
|
2015-12-29 20:35:04 +01:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2017-10-12 00:11:50 +02:00
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
2015-12-29 20:35:04 +01:00
|
|
|
#
|
2017-10-12 00:11:50 +02:00
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, see <https://www.gnu.org/licenses/>.
|
2015-12-29 20:35:04 +01:00
|
|
|
#
|
2017-07-17 12:28:24 +02:00
|
|
|
import jinja2
|
2018-01-15 15:58:34 +01:00
|
|
|
import unittest.mock
|
2015-12-29 20:35:04 +01:00
|
|
|
|
|
|
|
import qubes.tests
|
|
|
|
|
|
|
|
class TestVMM(object):
|
|
|
|
# pylint: disable=too-few-public-methods
|
|
|
|
def __init__(self, offline_mode=False):
|
|
|
|
self.offline_mode = offline_mode
|
2018-01-15 15:58:34 +01:00
|
|
|
self.xs = unittest.mock.Mock()
|
|
|
|
|
2016-04-20 13:41:33 +02:00
|
|
|
@property
|
|
|
|
def libvirt_conn(self):
|
2019-09-10 03:34:11 +02:00
|
|
|
if self.offline_mode:
|
|
|
|
import libvirt
|
|
|
|
raise libvirt.libvirtError('phony error')
|
|
|
|
else:
|
|
|
|
libvirt_mock = unittest.mock.Mock()
|
|
|
|
vm_mock = libvirt_mock.lookupByUUID.return_value
|
|
|
|
vm_mock.isActive.return_value = False
|
|
|
|
return libvirt_mock
|
2015-12-29 20:35:04 +01:00
|
|
|
|
|
|
|
class TestHost(object):
|
|
|
|
# pylint: disable=too-few-public-methods
|
|
|
|
def __init__(self):
|
2016-02-10 18:15:16 +01:00
|
|
|
self.memory_total = 1000 * 1024
|
2016-02-10 17:41:05 +01:00
|
|
|
self.no_cpus = 4
|
2020-06-10 05:47:53 +02:00
|
|
|
self.cpu_family_model = (6, 6)
|
2015-12-29 20:35:04 +01:00
|
|
|
|
2017-12-03 03:21:35 +01:00
|
|
|
class TestVMsCollection(dict):
|
|
|
|
def get_vms_connected_to(self, vm):
|
|
|
|
return set()
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
self.clear()
|
|
|
|
|
|
|
|
class TestVolume(object):
|
|
|
|
def __init__(self, pool):
|
|
|
|
self.pool = pool
|
|
|
|
self.size = 0
|
|
|
|
self.source = None
|
|
|
|
|
|
|
|
class TestPool(object):
|
|
|
|
def init_volume(self, *args, **kwargs):
|
|
|
|
return TestVolume(self)
|
|
|
|
|
2015-12-29 20:35:04 +01:00
|
|
|
class TestApp(qubes.tests.TestEmitter):
|
2020-05-05 15:50:41 +02:00
|
|
|
labels = {1: qubes.Label(1, '0xcc0000', 'red'),
|
|
|
|
2: qubes.Label(2, '0x00cc00', 'green'),
|
|
|
|
3: qubes.Label(3, '0x0000cc', 'blue'),
|
|
|
|
4: qubes.Label(4, '0xcccccc', 'black')}
|
2016-02-10 17:41:05 +01:00
|
|
|
check_updates_vm = False
|
|
|
|
|
2016-05-05 16:58:43 +02:00
|
|
|
def get_label(self, label):
|
|
|
|
# pylint: disable=unused-argument
|
2016-05-21 03:46:17 +02:00
|
|
|
if label in self.labels:
|
|
|
|
return self.labels[label]
|
|
|
|
for l in self.labels.values():
|
|
|
|
if l.name == label:
|
|
|
|
return l
|
|
|
|
raise KeyError(label)
|
2016-05-05 16:58:43 +02:00
|
|
|
|
2017-06-04 01:13:57 +02:00
|
|
|
def get_pool(self, pool):
|
|
|
|
return self.pools[pool]
|
|
|
|
|
2015-12-29 20:35:04 +01:00
|
|
|
def __init__(self):
|
|
|
|
super(TestApp, self).__init__()
|
|
|
|
self.vmm = TestVMM()
|
|
|
|
self.host = TestHost()
|
2017-12-03 03:21:35 +01:00
|
|
|
default_pool = TestPool()
|
|
|
|
self.pools = {
|
|
|
|
'default': default_pool,
|
|
|
|
default_pool: default_pool,
|
|
|
|
'linux-kernel': TestPool(),
|
|
|
|
}
|
2017-07-25 05:23:17 +02:00
|
|
|
self.default_pool_volatile = 'default'
|
|
|
|
self.default_pool_root = 'default'
|
|
|
|
self.default_pool_private = 'default'
|
|
|
|
self.default_pool_kernel = 'linux-kernel'
|
2018-09-16 20:42:48 +02:00
|
|
|
self.default_qrexec_timeout = 60
|
2017-12-03 03:21:35 +01:00
|
|
|
self.default_netvm = None
|
2020-06-18 00:31:40 +02:00
|
|
|
self.default_guivm = None
|
2017-12-03 03:21:35 +01:00
|
|
|
self.domains = TestVMsCollection()
|
2017-07-17 12:28:24 +02:00
|
|
|
#: jinja2 environment for libvirt XML templates
|
|
|
|
self.env = jinja2.Environment(
|
|
|
|
loader=jinja2.FileSystemLoader([
|
|
|
|
'templates',
|
|
|
|
'/etc/qubes/templates',
|
|
|
|
'/usr/share/qubes/templates',
|
|
|
|
]),
|
|
|
|
undefined=jinja2.StrictUndefined)
|