qubes/tests/vm/qubesvm: add basic tests for QubesVM
And already one fix to instantiation.
This commit is contained in:
parent
66475e5ca7
commit
bf4dbe07d5
@ -28,7 +28,7 @@ import qubes.vm.adminvm
|
||||
import qubes.tools.qvm_ls
|
||||
|
||||
import qubes.tests
|
||||
import qubes.tests.vm.adminvm
|
||||
import qubes.tests.vm
|
||||
|
||||
class TC_00_Column(qubes.tests.QubesTestCase):
|
||||
def test_000_collected(self):
|
||||
@ -63,7 +63,7 @@ class TC_90_globals(qubes.tests.QubesTestCase):
|
||||
|
||||
# TODO after serious testing of QubesVM and Qubes app, this should be
|
||||
# using normal components
|
||||
app = qubes.tests.vm.adminvm.TestApp()
|
||||
app = qubes.tests.vm.TestApp()
|
||||
vm = qubes.vm.adminvm.AdminVM(app, None,
|
||||
qid=0, name='dom0', internal='False')
|
||||
|
||||
|
@ -0,0 +1,42 @@
|
||||
#!/usr/bin/python2 -O
|
||||
# vim: fileencoding=utf-8
|
||||
# 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>
|
||||
#
|
||||
# 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.tests
|
||||
|
||||
class TestVMM(object):
|
||||
# pylint: disable=too-few-public-methods
|
||||
def __init__(self, offline_mode=False):
|
||||
self.offline_mode = offline_mode
|
||||
|
||||
class TestHost(object):
|
||||
# pylint: disable=too-few-public-methods
|
||||
def __init__(self):
|
||||
self.memory_total = 1000
|
||||
|
||||
class TestApp(qubes.tests.TestEmitter):
|
||||
def __init__(self):
|
||||
super(TestApp, self).__init__()
|
||||
self.vmm = TestVMM()
|
||||
self.host = TestHost()
|
@ -26,33 +26,16 @@ import unittest
|
||||
|
||||
import qubes
|
||||
import qubes.exc
|
||||
import qubes.vm
|
||||
import qubes.vm.adminvm
|
||||
|
||||
import qubes.tests
|
||||
|
||||
class TestVMM(object):
|
||||
# pylint: disable=too-few-public-methods
|
||||
def __init__(self, offline_mode=False):
|
||||
self.offline_mode = offline_mode
|
||||
|
||||
class TestHost(object):
|
||||
# pylint: disable=too-few-public-methods
|
||||
def __init__(self):
|
||||
self.memory_total = 1000
|
||||
|
||||
# this probably can be shared and not as dummy as is
|
||||
class TestApp(qubes.tests.TestEmitter):
|
||||
def __init__(self):
|
||||
super(TestApp, self).__init__()
|
||||
self.vmm = TestVMM()
|
||||
self.host = TestHost()
|
||||
|
||||
|
||||
@qubes.tests.skipUnlessDom0
|
||||
class TC_00_AdminVM(qubes.tests.QubesTestCase):
|
||||
def setUp(self):
|
||||
try:
|
||||
self.app = TestApp()
|
||||
self.app = qubes.tests.vm.TestApp()
|
||||
self.vm = qubes.vm.adminvm.AdminVM(self.app,
|
||||
xml=None, qid=0, name='dom0')
|
||||
except: # pylint: disable=bare-except
|
||||
|
@ -73,27 +73,32 @@ class TC_00_setters(qubes.tests.QubesTestCase):
|
||||
qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'test_name-1'),
|
||||
'test_name-1')
|
||||
|
||||
def test_011_setter_name_longer_than_31(self):
|
||||
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):
|
||||
# pylint: disable=invalid-name
|
||||
with self.assertRaises(ValueError):
|
||||
qubes.vm.qubesvm._setter_name(self.vm, self.prop, 't' * 32)
|
||||
|
||||
def test_012_setter_name_illegal_character(self):
|
||||
def test_013_setter_name_illegal_character(self):
|
||||
# pylint: disable=invalid-name
|
||||
with self.assertRaises(ValueError):
|
||||
qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'test#')
|
||||
|
||||
def test_013_setter_name_first_not_letter(self):
|
||||
def test_014_setter_name_first_not_letter(self):
|
||||
# pylint: disable=invalid-name
|
||||
with self.assertRaises(ValueError):
|
||||
qubes.vm.qubesvm._setter_name(self.vm, self.prop, '1test')
|
||||
|
||||
def test_014_setter_name_running(self):
|
||||
def test_015_setter_name_running(self):
|
||||
self.vm.running = True
|
||||
with self.assertRaises(qubes.exc.QubesVMNotHaltedError):
|
||||
qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'testname')
|
||||
|
||||
def test_015_setter_name_installed_by_rpm(self):
|
||||
def test_016_setter_name_installed_by_rpm(self):
|
||||
# pylint: disable=invalid-name
|
||||
self.vm.installed_by_rpm = True
|
||||
with self.assertRaises(qubes.exc.QubesException):
|
||||
@ -106,6 +111,28 @@ class TC_00_setters(qubes.tests.QubesTestCase):
|
||||
|
||||
|
||||
class TC_90_QubesVM(qubes.tests.QubesTestCase):
|
||||
@unittest.skip('test not implemented')
|
||||
def setUp(self):
|
||||
super(TC_90_QubesVM, self).setUp()
|
||||
self.app = qubes.tests.vm.TestApp()
|
||||
|
||||
def test_000_init(self):
|
||||
pass
|
||||
vm = qubes.vm.qubesvm.QubesVM(self.app, None,
|
||||
qid=1, name=qubes.tests.VMPREFIX + 'test')
|
||||
|
||||
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')
|
||||
def on_domain_init(self, event):
|
||||
self.__class__.event_fired = True
|
||||
|
||||
vm = TestVM2(self.app, None, qid=1, name=qubes.tests.VMPREFIX + 'test')
|
||||
self.assertTrue(TestVM2.event_fired)
|
||||
|
@ -483,8 +483,8 @@ class QubesVM(qubes.vm.BaseVM):
|
||||
|
||||
if xml is None:
|
||||
# we are creating new VM and attributes came through kwargs
|
||||
assert self.qid < qubes.config.max_qid, "VM id out of bounds!"
|
||||
assert self.name is not None
|
||||
assert hasattr(self, 'qid')
|
||||
assert hasattr(self, 'name')
|
||||
|
||||
# Not in generic way to not create QubesHost() to frequently
|
||||
# XXX this doesn't apply, host is instantiated once
|
||||
|
Loading…
Reference in New Issue
Block a user