Add support for volume types with Generic driver

Add configuration option cinder_volume_type which can be used
to set volume type for cinder. If that option is not None then
cinder volumes will be created with type from that option.

Implements blueprint cinder-volume-types-with-generic-driver

Change-Id: Ica171410bfdfa001da5188450a0c3740b4b8eb65
This commit is contained in:
Vladimir Vechkanov 2014-11-10 03:58:03 -05:00
parent 3f0a1adcc4
commit a7a517dec9
4 changed files with 29 additions and 3 deletions

View File

@ -74,6 +74,10 @@ share_opts = [
default='ext4', default='ext4',
choices=['ext4', 'ext3'], choices=['ext4', 'ext3'],
help='Filesystem type of the share volume.'), help='Filesystem type of the share volume.'),
cfg.StrOpt('cinder_volume_type',
default=None,
help='Name or id of cinder volume type which will be used '
'for all volumes created by driver.'),
] ]
CONF = cfg.CONF CONF = cfg.CONF
@ -395,11 +399,13 @@ class GenericShareDriver(driver.ExecuteMixin, driver.ShareDriver):
if snapshot: if snapshot:
volume_snapshot = self._get_volume_snapshot(context, volume_snapshot = self._get_volume_snapshot(context,
snapshot['id']) snapshot['id'])
volume = self.volume_api.create( volume = self.volume_api.create(
context, context,
share['size'], share['size'],
self.configuration.volume_name_template % share['id'], '', self.configuration.volume_name_template % share['id'], '',
snapshot=volume_snapshot) snapshot=volume_snapshot,
volume_type=self.configuration.cinder_volume_type)
t = time.time() t = time.time()
while time.time() - t < self.configuration.max_time_to_create_volume: while time.time() - t < self.configuration.max_time_to_create_volume:

View File

@ -558,6 +558,7 @@ class GenericShareDriverTestCase(test.TestCase):
def test_allocate_container(self): def test_allocate_container(self):
fake_vol = fake_volume.FakeVolume() fake_vol = fake_volume.FakeVolume()
self.fake_conf.cinder_volume_type = 'fake_volume_type'
self.stubs.Set(self._driver.volume_api, 'create', self.stubs.Set(self._driver.volume_api, 'create',
mock.Mock(return_value=fake_vol)) mock.Mock(return_value=fake_vol))
@ -568,7 +569,8 @@ class GenericShareDriverTestCase(test.TestCase):
self.share['size'], self.share['size'],
CONF.volume_name_template % self.share['id'], CONF.volume_name_template % self.share['id'],
'', '',
snapshot=None) snapshot=None,
volume_type='fake_volume_type')
def test_allocate_container_with_snaphot(self): def test_allocate_container_with_snaphot(self):
fake_vol = fake_volume.FakeVolume() fake_vol = fake_volume.FakeVolume()
@ -587,7 +589,8 @@ class GenericShareDriverTestCase(test.TestCase):
self.share['size'], self.share['size'],
CONF.volume_name_template % self.share['id'], CONF.volume_name_template % self.share['id'],
'', '',
snapshot=fake_vol_snap) snapshot=fake_vol_snap,
volume_type=None)
def test_allocate_container_error(self): def test_allocate_container_error(self):
fake_vol = fake_volume.FakeVolume(status='error') fake_vol = fake_volume.FakeVolume(status='error')

View File

@ -74,6 +74,16 @@ class CinderApiTestCase(test.TestCase):
self.assertRaises(exception.InvalidInput, self.assertRaises(exception.InvalidInput,
self.api.create, self.ctx, 1, '', '') self.api.create, self.ctx, 1, '', '')
def test_create_not_found_error(self):
cinder.cinderclient.side_effect = cinder_exception.NotFound(404)
self.assertRaises(exception.NotFound,
self.api.create, self.ctx, 1, '', '')
def test_create_failed_exception(self):
cinder.cinderclient.side_effect = Exception("error msg")
self.assertRaises(exception.ManilaException,
self.api.create, self.ctx, 1, '', '')
def test_get_all(self): def test_get_all(self):
cinder._untranslate_volume_summary_view.return_value = ['id1', 'id2'] cinder._untranslate_volume_summary_view.return_value = ['id1', 'id2']
self.assertEqual([{'id': 'id1'}, {'id': 'id2'}], self.assertEqual([{'id': 'id1'}, {'id': 'id2'}],

View File

@ -303,6 +303,13 @@ class API(base.Base):
return _untranslate_volume_summary_view(context, item) return _untranslate_volume_summary_view(context, item)
except cinder_exception.BadRequest as e: except cinder_exception.BadRequest as e:
raise exception.InvalidInput(reason=e.message) raise exception.InvalidInput(reason=e.message)
except cinder_exception.NotFound:
raise exception.NotFound(
_("Error in creating cinder "
"volume. Cinder volume type %s not exist. Check parameter "
"cinder_volume_type in configuration file.") % volume_type)
except Exception as e:
raise exception.ManilaException(e.message)
@translate_volume_exception @translate_volume_exception
def delete(self, context, volume_id): def delete(self, context, volume_id):