From 26711e7e9aa64b18d9b8e00e567c6dc4e2f86992 Mon Sep 17 00:00:00 2001 From: Bahtiar `kalkin-` Gadimov Date: Sat, 7 Nov 2015 20:19:17 +0100 Subject: [PATCH] Use default pool_config if pool name is 'default' --- core/settings-xen-Linux.py | 1 + core/storage/__init__.py | 9 ++++++++- core/storage/xen.py | 6 +++++- tests/storage.py | 34 +++++++++++++++++++++++++++------- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/core/settings-xen-Linux.py b/core/settings-xen-Linux.py index 30669407..74503524 100644 --- a/core/settings-xen-Linux.py +++ b/core/settings-xen-Linux.py @@ -8,3 +8,4 @@ from qubes.storage.xen import XenStorage, XenPool def apply(system_path, vm_files, defaults): defaults['storage_class'] = XenStorage defaults['pool_types'] = {'xen': XenPool} + defaults['pool_config'] = {'dir': '/var/lib/qubes/'} diff --git a/core/storage/__init__.py b/core/storage/__init__.py index 4636dc47..39f623d5 100644 --- a/core/storage/__init__.py +++ b/core/storage/__init__.py @@ -247,7 +247,14 @@ def get_pool(name, vm): keys = [k for k in config.options(name) if k != 'type' and k != 'class'] values = [config.get(name, o) for o in keys] - kwargs = dict(zip(keys, values)) + config_kwargs = dict(zip(keys, values)) + + if name == 'default': + kwargs = defaults['pool_config'].copy() + kwargs.update(keys) + else: + kwargs = config_kwargs + return klass(vm, **kwargs) diff --git a/core/storage/xen.py b/core/storage/xen.py index 01ed0277..06bd0186 100644 --- a/core/storage/xen.py +++ b/core/storage/xen.py @@ -252,8 +252,12 @@ class XenStorage(QubesVmStorage): class XenPool(Pool): - def __init__(self, vm): + def __init__(self, vm, dir): + assert vm is not None + assert dir is not None + self.vm = vm + self.dir = dir def getStorage(self): return defaults['storage_class'](self.vm) diff --git a/tests/storage.py b/tests/storage.py index 3115535d..b5a0defc 100644 --- a/tests/storage.py +++ b/tests/storage.py @@ -30,8 +30,9 @@ class TC_00_Storage(SystemTestsMixin, QubesTestCase): """ Dumps storage instance to a storage string """ vmname = self.make_vm_name('appvm') template = self.qc.get_default_template() - storage = self.qc.add_new_vm('QubesAppVm', name=vmname, pool_name='default', - template=template).storage + vm = self.qc.add_new_vm('QubesAppVm', name=vmname, + pool_name='default', template=template) + storage = vm.storage result = qubes.storage.dump(storage) expected = 'qubes.storage.xen.XenStorage' self.assertEquals(result, expected) @@ -62,11 +63,30 @@ class TC_00_Storage(SystemTestsMixin, QubesTestCase): qubes.storage.pool_exists('asdh312096r832598213iudhas')) -class TC_01_Storage(SystemTestsMixin, QubesTestCase): +class TC_00_Pool(SystemTestsMixin, QubesTestCase): - def test_000_vm_use_default_pool(self): + def test000_no_pool_dir(self): + """ If no pool dir ist configured for a ``XenPool`` assume the default + `/var/lib/qubes/`. + """ + vm = self._init_app_vm() + result = qubes.storage.get_pool("default", vm).dir + expected = '/var/lib/qubes/' + self.assertEquals(result, expected) + + def test001_default_storage_class(self): + """ Check if when using default pool the Storage is ``XenStorage``. """ + result = self._init_app_vm().storage + self.assertIsInstance(result, XenStorage) + + def test_002_pool_name(self): + """ Default pool_name is 'default'. """ + vm = self._init_app_vm() + self.assertEquals(vm.pool_name, "default") + + def _init_app_vm(self): + """ Return initalised, but not created, AppVm. """ vmname = self.make_vm_name('appvm') template = self.qc.get_default_template() - vm = self.qc.add_new_vm('QubesAppVm', name=vmname, template=template, - pool_name='default') - self.assertIsInstance(vm.storage, XenStorage) + return self.qc.add_new_vm('QubesAppVm', name=vmname, template=template, + pool_name='default')