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:
parent
9eee00c6d7
commit
885dc5cd81
@ -7,5 +7,5 @@ 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/'}
|
||||
defaults['pool_drivers'] = {'xen': XenPool}
|
||||
defaults['pool_config'] = {'dir_path': '/var/lib/qubes/'}
|
||||
|
@ -239,7 +239,7 @@ def get_pool(name, vm):
|
||||
|
||||
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]
|
||||
config_kwargs = dict(zip(keys, values))
|
||||
|
||||
@ -308,19 +308,17 @@ def _get_pool_klass(name, config=None):
|
||||
|
||||
if config.has_option(name, 'class'):
|
||||
klass = load(config.get(name, 'class'))
|
||||
elif config.has_option(name, 'type'):
|
||||
pool_type = config.get(name, 'type')
|
||||
klass = defaults['pool_types'][pool_type]
|
||||
|
||||
if klass is None:
|
||||
raise StoragePoolException('Uknown storage pool type ' + name)
|
||||
elif config.has_option(name, 'driver'):
|
||||
pool_driver = config.get(name, 'driver')
|
||||
klass = defaults['pool_drivers'][pool_driver]
|
||||
else:
|
||||
raise StoragePoolException('Uknown storage pool driver ' + name)
|
||||
return klass
|
||||
|
||||
|
||||
|
||||
class StoragePoolException(QubesException):
|
||||
pass
|
||||
|
||||
|
||||
class Pool(object):
|
||||
pass
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
[default] ; poolname
|
||||
type=xen ; the default xen storage
|
||||
; class = qubes.storage.xen.XenStorage ; class always overwrites type
|
||||
driver=xen ; the default xen storage
|
||||
; 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
|
||||
; class name
|
||||
@ -8,5 +8,5 @@ type=xen ; the default xen storage
|
||||
; class = foo.bar.MyStorage
|
||||
;
|
||||
; [test-dummy]
|
||||
; type=dummy
|
||||
; driver=dummy
|
||||
|
||||
|
@ -274,22 +274,22 @@ class XenStorage(QubesVmStorage):
|
||||
|
||||
class XenPool(Pool):
|
||||
|
||||
def __init__(self, vm, dir):
|
||||
def __init__(self, vm, dir_path):
|
||||
assert vm is not None
|
||||
assert dir is not None
|
||||
assert dir_path is not None
|
||||
|
||||
appvms_path = os.path.join(dir, 'appvms')
|
||||
servicevms_path = os.path.join(dir, 'servicevms')
|
||||
vm_templates_path = os.path.join(dir, 'vm-templates')
|
||||
appvms_path = os.path.join(dir_path, 'appvms')
|
||||
servicevms_path = os.path.join(dir_path, 'servicevms')
|
||||
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(servicevms_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.dir = dir
|
||||
self.dir_path = dir_path
|
||||
|
||||
def getStorage(self):
|
||||
""" Returns an instantiated ``XenStorage``. """
|
||||
|
@ -42,13 +42,13 @@ class TC_00_Storage(SystemTestsMixin, QubesTestCase):
|
||||
self.assertEquals(result, expected)
|
||||
|
||||
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')
|
||||
self.assertTrue(result is XenStorage)
|
||||
|
||||
def test_002_default_pool_types(self):
|
||||
""" The only predifined pool type is xen """
|
||||
result = defaults['pool_types'].keys()
|
||||
def test_002_default_pool_drivers(self):
|
||||
""" The only predifined pool driver is xen """
|
||||
result = defaults['pool_drivers'].keys()
|
||||
expected = ["xen"]
|
||||
self.assertEquals(result, expected)
|
||||
|
||||
@ -73,7 +73,7 @@ class TC_00_Storage(SystemTestsMixin, QubesTestCase):
|
||||
# make sure it's really does not exist
|
||||
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))
|
||||
|
||||
qubes.storage.remove_pool(pool_name)
|
||||
@ -91,7 +91,7 @@ class TC_00_Pool(SystemTestsMixin, QubesTestCase):
|
||||
Data :data:``qubes.qubes.defaults['pool_config']``.
|
||||
"""
|
||||
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/'
|
||||
self.assertEquals(result, expected)
|
||||
|
||||
@ -126,7 +126,8 @@ class TC_01_Pool(SystemTestsMixin, QubesTestCase):
|
||||
def setUp(self):
|
||||
""" Add a test file based storage pool """
|
||||
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):
|
||||
""" Remove the file based storage pool after testing """
|
||||
@ -160,7 +161,7 @@ class TC_01_Pool(SystemTestsMixin, QubesTestCase):
|
||||
template = self.qc.get_default_template()
|
||||
vm = self.qc.add_new_vm('QubesAppVm', name=vmname, template=template,
|
||||
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)
|
||||
|
||||
def test_004_app_vmdir(self):
|
||||
|
Loading…
Reference in New Issue
Block a user