Add storage add_pool & remove_pool

This commit is contained in:
Bahtiar `kalkin-` Gadimov 2015-11-07 20:53:50 +01:00
父節點 26711e7e9a
當前提交 16d480cf4c
共有 3 個檔案被更改,包括 46 行新增14 行删除

查看文件

@ -258,6 +258,32 @@ def get_pool(name, vm):
return klass(vm, **kwargs)
def pool_exists(name):
""" Check if the specified pool exists """
try:
_get_pool_klass(name)
return True
except StoragePoolException:
return False
def add_pool(name, **kwargs):
""" Add a storage pool to config."""
config = _get_storage_config_parser()
config.add_section(name)
for key, value in kwargs.iteritems():
config.set(name, key, value)
_write_config(config)
def remove_pool(name):
""" Remove a storage pool from config file. """
config = _get_storage_config_parser()
config.remove_section(name)
_write_config(config)
def _write_config(config):
with open(CONFIG_FILE, 'w') as configfile:
config.write(configfile)
def _get_storage_config_parser():
""" Instantiates a `ConfigParaser` for specified storage config file.
@ -297,14 +323,6 @@ def _get_pool_klass(name, config=None):
return klass
def pool_exists(name):
""" Check if the specified pool exists """
try:
_get_pool_klass(name)
return True
except StoragePoolException:
return False
class StoragePoolException(QubesException):
pass

查看文件

@ -7,5 +7,6 @@ type=xen ; the default xen storage
; [pool-b]
; class = foo.bar.MyStorage
;
; [test-dummy]
; type=dummy

查看文件

@ -17,11 +17,11 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
from qubes.tests import QubesTestCase, SystemTestsMixin
from qubes.qubes import defaults
import qubes.storage
from qubes.storage.xen import XenStorage, XenPool
from qubes.qubes import defaults
from qubes.tests import QubesTestCase, SystemTestsMixin
from qubes.storage.xen import XenPool, XenStorage
class TC_00_Storage(SystemTestsMixin, QubesTestCase):
@ -62,6 +62,19 @@ class TC_00_Storage(SystemTestsMixin, QubesTestCase):
self.assertFalse(
qubes.storage.pool_exists('asdh312096r832598213iudhas'))
def test_006_add_remove_pool(self):
""" Tries to adding and removing a pool. """
pool_name = 'asdjhrp89132'
# make sure it's really does not exist
qubes.storage.remove_pool(pool_name)
qubes.storage.add_pool(pool_name, type='xen')
self.assertTrue(qubes.storage.pool_exists(pool_name))
qubes.storage.remove_pool(pool_name)
self.assertFalse(qubes.storage.pool_exists(pool_name))
class TC_00_Pool(SystemTestsMixin, QubesTestCase):