import math
+import mock
import mox
from oslo.config import cfg
super(CoraidDriverTestCase, self).setUp()
configuration = mox.MockObject(conf.Configuration)
configuration.append_config_values(mox.IgnoreArg())
+ configuration.coraid_default_repository = 'default_repository'
configuration.coraid_esm_address = fake_esm_ipaddress
configuration.coraid_user = fake_esm_username
configuration.coraid_group = fake_esm_group
self.mox.VerifyAll()
+ @mock.patch.object(volume_types, 'get_volume_type_extra_specs')
+ def test_create_volume_volume_type_no_repo_key(self, volume_specs_mock):
+ """Test volume creation without repo specified in volume type."""
+ volume_specs_mock.return_value = None
+
+ create_volume_request = {'addr': 'cms',
+ 'data': {
+ 'servers': [],
+ 'size':
+ coraid_volume_size(fake_volume_size),
+ 'repoName': 'default_repository',
+ 'lvName': fake_volume_name},
+ 'op': 'orchStrLun',
+ 'args': 'add'}
+ pack_data(create_volume_request)
+
+ self.fake_rpc.handle('configure', {}, [create_volume_request],
+ {'configState': 'completedSuccessfully',
+ 'firstParam': 'fake_first_param'})
+
+ self.driver.create_volume(fake_volume)
+
+ @mock.patch.object(volume_types, 'get_volume_type_extra_specs')
+ def test_create_volume_volume_type_no_repo_data(self, volume_specs_mock):
+ """Test volume creation w/o repo in volume type nor config."""
+ volume_specs_mock.return_value = None
+ self.driver.configuration.coraid_default_repository = None
+
+ create_volume_request = {'addr': 'cms',
+ 'data': {
+ 'servers': [],
+ 'size':
+ coraid_volume_size(fake_volume_size),
+ 'repoName': 'default_repository',
+ 'lvName': fake_volume_name},
+ 'op': 'orchStrLun',
+ 'args': 'add'}
+ pack_data(create_volume_request)
+
+ self.fake_rpc.handle('configure', {}, [create_volume_request],
+ {'configState': 'completedSuccessfully',
+ 'firstParam': 'fake_first_param'})
+
+ self.assertRaises(exception.CoraidException,
+ self.driver.create_volume, fake_volume)
+
def test_delete_volume(self):
delete_volume_request = {'addr': 'cms',
'data': {
cfg.StrOpt('coraid_repository_key',
default='coraid_repository',
help='Volume Type key name to store ESM Repository Name'),
+ cfg.StrOpt('coraid_default_repository',
+ help='ESM Repository Name to use if not specified in '
+ 'Volume Type keys'),
]
CONF = cfg.CONF
"""
volume_type_id = volume_type['id']
repository_key_name = self.configuration.coraid_repository_key
- repository = volume_types.get_volume_type_extra_specs(
- volume_type_id, repository_key_name)
+ repository = (volume_types.get_volume_type_extra_specs(
+ volume_type_id, repository_key_name) or
+ self.configuration.coraid_default_repository)
+
+ # if there's no repository still, we cannot move forward
+ if not repository:
+ message = ("The Coraid repository not specified neither "
+ "in Volume Type '%s' key nor in the "
+ "'coraid_default_repository' config option" %
+ self.configuration.coraid_repository_key)
+ raise exception.CoraidException(message=message)
+
# Remove <in> keyword from repository name if needed
if repository.startswith('<in> '):
return repository[len('<in> '):]