2015-11-07 19:01:25 +01:00
|
|
|
# The Qubes OS Project, https://www.qubes-os.org/
|
|
|
|
#
|
|
|
|
# Copyright (C) 2015 Bahtiar `kalkin-` Gadimov <bahtiar@gadimov.de>
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
2016-02-11 05:41:42 +01:00
|
|
|
import qubes.log
|
2016-04-15 20:10:53 +02:00
|
|
|
from qubes.exc import QubesException
|
|
|
|
from qubes.storage import pool_drivers
|
2016-04-30 20:42:46 +02:00
|
|
|
from qubes.storage.file import FilePool
|
2016-04-15 20:10:53 +02:00
|
|
|
from qubes.tests import QubesTestCase, SystemTestsMixin
|
|
|
|
|
|
|
|
# :pylint: disable=invalid-name
|
2016-03-20 20:29:46 +01:00
|
|
|
|
2015-11-07 19:01:25 +01:00
|
|
|
|
2016-02-11 05:41:42 +01:00
|
|
|
class TestApp(qubes.tests.TestEmitter):
|
|
|
|
pass
|
2015-11-07 19:01:25 +01:00
|
|
|
|
2016-03-20 20:29:46 +01:00
|
|
|
|
2016-02-11 05:41:42 +01:00
|
|
|
class TestVM(object):
|
2016-04-15 20:10:53 +02:00
|
|
|
def __init__(self, test, template=None):
|
|
|
|
self.app = test.app
|
|
|
|
self.name = test.make_vm_name('appvm')
|
2016-02-11 05:41:42 +01:00
|
|
|
self.log = qubes.log.get_vm_logger(self.name)
|
|
|
|
|
2016-04-15 20:10:53 +02:00
|
|
|
if template:
|
|
|
|
self.template = template
|
|
|
|
|
2016-02-11 05:41:42 +01:00
|
|
|
def is_template(self):
|
2016-04-15 20:10:53 +02:00
|
|
|
# :pylint: disable=no-self-use
|
2016-02-11 05:41:42 +01:00
|
|
|
return False
|
|
|
|
|
|
|
|
def is_disposablevm(self):
|
2016-04-15 20:10:53 +02:00
|
|
|
# :pylint: disable=no-self-use
|
2016-02-11 05:41:42 +01:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
class TestTemplateVM(TestVM):
|
2016-04-15 20:10:53 +02:00
|
|
|
dir_path_prefix = qubes.config.system_path['qubes_templates_dir']
|
|
|
|
|
2016-02-11 05:41:42 +01:00
|
|
|
def is_template(self):
|
|
|
|
return True
|
|
|
|
|
2016-03-20 20:29:46 +01:00
|
|
|
|
2016-02-11 05:41:42 +01:00
|
|
|
class TestDisposableVM(TestVM):
|
|
|
|
def is_disposablevm(self):
|
|
|
|
return True
|
|
|
|
|
2015-11-07 19:01:25 +01:00
|
|
|
|
2016-04-15 20:10:53 +02:00
|
|
|
class TC_00_Pool(SystemTestsMixin, QubesTestCase):
|
2015-11-08 21:23:07 +01:00
|
|
|
""" This class tests the utility methods from :mod:``qubes.storage`` """
|
|
|
|
|
2016-02-11 05:41:42 +01:00
|
|
|
def setUp(self):
|
2016-03-20 20:29:46 +01:00
|
|
|
super(TC_00_Pool, self).setUp()
|
2016-04-15 20:10:53 +02:00
|
|
|
self.init_default_template()
|
2016-03-20 20:29:46 +01:00
|
|
|
|
|
|
|
def test_000_unknown_pool_driver(self):
|
|
|
|
# :pylint: disable=protected-access
|
|
|
|
""" Expect an exception when unknown pool is requested"""
|
2016-04-15 20:10:53 +02:00
|
|
|
with self.assertRaises(QubesException):
|
|
|
|
self.app.get_pool('foo-bar')
|
2016-03-20 20:29:46 +01:00
|
|
|
|
|
|
|
def test_001_all_pool_drivers(self):
|
2016-04-30 20:42:46 +02:00
|
|
|
""" The only predefined pool driver is file """
|
|
|
|
self.assertEquals(['linux-kernel', 'file'], pool_drivers())
|
2016-03-20 20:29:46 +01:00
|
|
|
|
|
|
|
def test_002_get_pool_klass(self):
|
2016-04-30 20:42:46 +02:00
|
|
|
""" Expect the default pool to be `FilePool` """
|
2016-03-20 20:29:46 +01:00
|
|
|
# :pylint: disable=protected-access
|
2016-04-15 20:10:53 +02:00
|
|
|
result = self.app.get_pool('default')
|
2016-04-30 20:42:46 +02:00
|
|
|
self.assertIsInstance(result, FilePool)
|
2015-11-07 19:01:25 +01:00
|
|
|
|
2016-03-20 20:29:46 +01:00
|
|
|
def test_003_pool_exists_default(self):
|
2015-11-07 19:32:03 +01:00
|
|
|
""" Expect the default pool to exists """
|
2016-04-15 20:10:53 +02:00
|
|
|
self.assertPoolExists('default')
|
2015-11-07 19:32:03 +01:00
|
|
|
|
2016-04-15 20:10:53 +02:00
|
|
|
def test_004_add_remove_pool(self):
|
2015-11-07 20:53:50 +01:00
|
|
|
""" Tries to adding and removing a pool. """
|
|
|
|
pool_name = 'asdjhrp89132'
|
|
|
|
|
|
|
|
# make sure it's really does not exist
|
2016-04-15 20:10:53 +02:00
|
|
|
self.app.remove_pool(pool_name)
|
|
|
|
self.assertFalse(self.assertPoolExists(pool_name))
|
|
|
|
|
2016-04-30 20:42:46 +02:00
|
|
|
self.app.add_pool(name=pool_name,
|
|
|
|
driver='file',
|
|
|
|
dir_path='/tmp/asdjhrp89132')
|
2016-04-15 20:10:53 +02:00
|
|
|
self.assertTrue(self.assertPoolExists(pool_name))
|
2015-11-07 20:53:50 +01:00
|
|
|
|
2016-04-15 20:10:53 +02:00
|
|
|
self.app.remove_pool(pool_name)
|
|
|
|
self.assertFalse(self.assertPoolExists(pool_name))
|
2015-11-07 20:53:50 +01:00
|
|
|
|
2016-04-15 20:10:53 +02:00
|
|
|
def assertPoolExists(self, pool):
|
|
|
|
""" Check if specified pool exists """
|
|
|
|
return pool in self.app.pools.keys()
|