Rename storage dir to dir_path, type to driver

Bad idea to use attributes which are named after built in functions.
This commit is contained in:
Bahtiar `kalkin-` Gadimov 2015-11-21 14:46:23 +01:00
parent 9eee00c6d7
commit 885dc5cd81
5 changed files with 29 additions and 30 deletions

View File

@ -7,5 +7,5 @@ from qubes.storage.xen import XenStorage, XenPool
def apply(system_path, vm_files, defaults): def apply(system_path, vm_files, defaults):
defaults['storage_class'] = XenStorage defaults['storage_class'] = XenStorage
defaults['pool_types'] = {'xen': XenPool} defaults['pool_drivers'] = {'xen': XenPool}
defaults['pool_config'] = {'dir': '/var/lib/qubes/'} defaults['pool_config'] = {'dir_path': '/var/lib/qubes/'}

View File

@ -239,7 +239,7 @@ def get_pool(name, vm):
klass = _get_pool_klass(name, config) klass = _get_pool_klass(name, config)
keys = [k for k in config.options(name) if k != 'type' and k != 'class'] keys = [k for k in config.options(name) if k != 'driver' and k != 'class']
values = [config.get(name, o) for o in keys] values = [config.get(name, o) for o in keys]
config_kwargs = dict(zip(keys, values)) config_kwargs = dict(zip(keys, values))
@ -308,19 +308,17 @@ def _get_pool_klass(name, config=None):
if config.has_option(name, 'class'): if config.has_option(name, 'class'):
klass = load(config.get(name, 'class')) klass = load(config.get(name, 'class'))
elif config.has_option(name, 'type'): elif config.has_option(name, 'driver'):
pool_type = config.get(name, 'type') pool_driver = config.get(name, 'driver')
klass = defaults['pool_types'][pool_type] klass = defaults['pool_drivers'][pool_driver]
else:
if klass is None: raise StoragePoolException('Uknown storage pool driver ' + name)
raise StoragePoolException('Uknown storage pool type ' + name)
return klass return klass
class StoragePoolException(QubesException): class StoragePoolException(QubesException):
pass pass
class Pool(object): class Pool(object):
pass pass

View File

@ -1,6 +1,6 @@
[default] ; poolname [default] ; poolname
type=xen ; the default xen storage driver=xen ; the default xen storage
; class = qubes.storage.xen.XenStorage ; class always overwrites type ; class = qubes.storage.xen.XenStorage ; class always overwrites the driver
; ;
; To use our own storage adapter, you need just to specify the module path and ; To use our own storage adapter, you need just to specify the module path and
; class name ; class name
@ -8,5 +8,5 @@ type=xen ; the default xen storage
; class = foo.bar.MyStorage ; class = foo.bar.MyStorage
; ;
; [test-dummy] ; [test-dummy]
; type=dummy ; driver=dummy

View File

@ -274,22 +274,22 @@ class XenStorage(QubesVmStorage):
class XenPool(Pool): class XenPool(Pool):
def __init__(self, vm, dir): def __init__(self, vm, dir_path):
assert vm is not None assert vm is not None
assert dir is not None assert dir_path is not None
appvms_path = os.path.join(dir, 'appvms') appvms_path = os.path.join(dir_path, 'appvms')
servicevms_path = os.path.join(dir, 'servicevms') servicevms_path = os.path.join(dir_path, 'servicevms')
vm_templates_path = os.path.join(dir, 'vm-templates') vm_templates_path = os.path.join(dir_path, 'vm-templates')
self._create_dir_if_not_exists(dir) self._create_dir_if_not_exists(dir_path)
self._create_dir_if_not_exists(appvms_path) self._create_dir_if_not_exists(appvms_path)
self._create_dir_if_not_exists(servicevms_path) self._create_dir_if_not_exists(servicevms_path)
self._create_dir_if_not_exists(vm_templates_path) self._create_dir_if_not_exists(vm_templates_path)
self.vmdir = self._vmdir_path(vm, dir) self.vmdir = self._vmdir_path(vm, dir_path)
self.vm = vm self.vm = vm
self.dir = dir self.dir_path = dir_path
def getStorage(self): def getStorage(self):
""" Returns an instantiated ``XenStorage``. """ """ Returns an instantiated ``XenStorage``. """

View File

@ -42,13 +42,13 @@ class TC_00_Storage(SystemTestsMixin, QubesTestCase):
self.assertEquals(result, expected) self.assertEquals(result, expected)
def test_001_load(self): def test_001_load(self):
""" Loads storage type from a storage string """ """ Loads storage driver from a storage string """
result = qubes.storage.load('qubes.storage.xen.XenStorage') result = qubes.storage.load('qubes.storage.xen.XenStorage')
self.assertTrue(result is XenStorage) self.assertTrue(result is XenStorage)
def test_002_default_pool_types(self): def test_002_default_pool_drivers(self):
""" The only predifined pool type is xen """ """ The only predifined pool driver is xen """
result = defaults['pool_types'].keys() result = defaults['pool_drivers'].keys()
expected = ["xen"] expected = ["xen"]
self.assertEquals(result, expected) self.assertEquals(result, expected)
@ -73,7 +73,7 @@ class TC_00_Storage(SystemTestsMixin, QubesTestCase):
# make sure it's really does not exist # make sure it's really does not exist
qubes.storage.remove_pool(pool_name) qubes.storage.remove_pool(pool_name)
qubes.storage.add_pool(pool_name, type='xen') qubes.storage.add_pool(pool_name, driver='xen')
self.assertTrue(qubes.storage.pool_exists(pool_name)) self.assertTrue(qubes.storage.pool_exists(pool_name))
qubes.storage.remove_pool(pool_name) qubes.storage.remove_pool(pool_name)
@ -91,7 +91,7 @@ class TC_00_Pool(SystemTestsMixin, QubesTestCase):
Data :data:``qubes.qubes.defaults['pool_config']``. Data :data:``qubes.qubes.defaults['pool_config']``.
""" """
vm = self._init_app_vm() vm = self._init_app_vm()
result = qubes.storage.get_pool("default", vm).dir result = qubes.storage.get_pool("default", vm).dir_path
expected = '/var/lib/qubes/' expected = '/var/lib/qubes/'
self.assertEquals(result, expected) self.assertEquals(result, expected)
@ -126,7 +126,8 @@ class TC_01_Pool(SystemTestsMixin, QubesTestCase):
def setUp(self): def setUp(self):
""" Add a test file based storage pool """ """ Add a test file based storage pool """
super(TC_01_Pool, self).setUp() super(TC_01_Pool, self).setUp()
qubes.storage.add_pool('test-pool', type='xen', dir=self.POOL_DIR) qubes.storage.add_pool('test-pool', driver='xen',
dir_path=self.POOL_DIR)
def tearDown(self): def tearDown(self):
""" Remove the file based storage pool after testing """ """ Remove the file based storage pool after testing """
@ -160,7 +161,7 @@ class TC_01_Pool(SystemTestsMixin, QubesTestCase):
template = self.qc.get_default_template() template = self.qc.get_default_template()
vm = self.qc.add_new_vm('QubesAppVm', name=vmname, template=template, vm = self.qc.add_new_vm('QubesAppVm', name=vmname, template=template,
pool_name='test-pool') pool_name='test-pool')
result = qubes.storage.get_pool('test-pool', vm).dir result = qubes.storage.get_pool('test-pool', vm).dir_path
self.assertEquals(self.POOL_DIR, result) self.assertEquals(self.POOL_DIR, result)
def test_004_app_vmdir(self): def test_004_app_vmdir(self):