diff --git a/manila/share/drivers/generic.py b/manila/share/drivers/generic.py index 10af4652ff..0b931ac81a 100644 --- a/manila/share/drivers/generic.py +++ b/manila/share/drivers/generic.py @@ -74,6 +74,10 @@ share_opts = [ default='ext4', choices=['ext4', 'ext3'], 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 @@ -395,11 +399,13 @@ class GenericShareDriver(driver.ExecuteMixin, driver.ShareDriver): if snapshot: volume_snapshot = self._get_volume_snapshot(context, snapshot['id']) + volume = self.volume_api.create( context, share['size'], self.configuration.volume_name_template % share['id'], '', - snapshot=volume_snapshot) + snapshot=volume_snapshot, + volume_type=self.configuration.cinder_volume_type) t = time.time() while time.time() - t < self.configuration.max_time_to_create_volume: diff --git a/manila/tests/share/drivers/test_generic.py b/manila/tests/share/drivers/test_generic.py index 6795ea901a..ef88e6b587 100644 --- a/manila/tests/share/drivers/test_generic.py +++ b/manila/tests/share/drivers/test_generic.py @@ -558,6 +558,7 @@ class GenericShareDriverTestCase(test.TestCase): def test_allocate_container(self): fake_vol = fake_volume.FakeVolume() + self.fake_conf.cinder_volume_type = 'fake_volume_type' self.stubs.Set(self._driver.volume_api, 'create', mock.Mock(return_value=fake_vol)) @@ -568,7 +569,8 @@ class GenericShareDriverTestCase(test.TestCase): self.share['size'], CONF.volume_name_template % self.share['id'], '', - snapshot=None) + snapshot=None, + volume_type='fake_volume_type') def test_allocate_container_with_snaphot(self): fake_vol = fake_volume.FakeVolume() @@ -587,7 +589,8 @@ class GenericShareDriverTestCase(test.TestCase): self.share['size'], CONF.volume_name_template % self.share['id'], '', - snapshot=fake_vol_snap) + snapshot=fake_vol_snap, + volume_type=None) def test_allocate_container_error(self): fake_vol = fake_volume.FakeVolume(status='error') diff --git a/manila/tests/volume/test_cinder.py b/manila/tests/volume/test_cinder.py index bd13acbea0..ceeeecccb7 100644 --- a/manila/tests/volume/test_cinder.py +++ b/manila/tests/volume/test_cinder.py @@ -74,6 +74,16 @@ class CinderApiTestCase(test.TestCase): self.assertRaises(exception.InvalidInput, 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): cinder._untranslate_volume_summary_view.return_value = ['id1', 'id2'] self.assertEqual([{'id': 'id1'}, {'id': 'id2'}], diff --git a/manila/volume/cinder.py b/manila/volume/cinder.py index cef4ab271b..d7c2c2bcb8 100644 --- a/manila/volume/cinder.py +++ b/manila/volume/cinder.py @@ -303,6 +303,13 @@ class API(base.Base): return _untranslate_volume_summary_view(context, item) except cinder_exception.BadRequest as e: 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 def delete(self, context, volume_id):