Fix cinderclient compatibility of list filtering by name
Filtering name 'display_name' is deprecated, use proper new one 'name'. Change-Id: I254544b8b3879e4c7204e82d32fd0417f81bfd90 Closes-Bug: #1421200
This commit is contained in:
parent
da4a8a3d68
commit
75da4bc5b5
|
@ -350,7 +350,7 @@ class GenericShareDriver(driver.ExecuteMixin, driver.ShareDriver):
|
|||
def _get_volume(self, context, share_id):
|
||||
"""Finds volume, associated to the specific share."""
|
||||
volume_name = self.configuration.volume_name_template % share_id
|
||||
search_opts = {'display_name': volume_name}
|
||||
search_opts = {'name': volume_name}
|
||||
if context.is_admin:
|
||||
search_opts['all_tenants'] = True
|
||||
volumes_list = self.volume_api.get_all(context, search_opts)
|
||||
|
@ -358,6 +358,11 @@ class GenericShareDriver(driver.ExecuteMixin, driver.ShareDriver):
|
|||
if len(volumes_list) == 1:
|
||||
volume = volumes_list[0]
|
||||
elif len(volumes_list) > 1:
|
||||
LOG.error(
|
||||
_LE("Expected only one volume in volume list with name "
|
||||
"'%(name)s', but got more than one in a result - "
|
||||
"'%(result)s'."), {
|
||||
'name': volume_name, 'result': volumes_list})
|
||||
raise exception.ManilaException(_('Error. Ambiguous volumes'))
|
||||
return volume
|
||||
|
||||
|
@ -366,12 +371,17 @@ class GenericShareDriver(driver.ExecuteMixin, driver.ShareDriver):
|
|||
volume_snapshot_name = (
|
||||
self.configuration.volume_snapshot_name_template % snapshot_id)
|
||||
volume_snapshot_list = self.volume_api.get_all_snapshots(
|
||||
context,
|
||||
{'display_name': volume_snapshot_name})
|
||||
context, {'name': volume_snapshot_name})
|
||||
volume_snapshot = None
|
||||
if len(volume_snapshot_list) == 1:
|
||||
volume_snapshot = volume_snapshot_list[0]
|
||||
elif len(volume_snapshot_list) > 1:
|
||||
LOG.error(
|
||||
_LE("Expected only one volume snapshot in list with name "
|
||||
"'%(name)s', but got more than one in a result - "
|
||||
"'%(result)s'."), {
|
||||
'name': volume_snapshot_name,
|
||||
'result': volume_snapshot_list})
|
||||
raise exception.ManilaException(
|
||||
_('Error. Ambiguous volume snaphots'))
|
||||
return volume_snapshot
|
||||
|
|
|
@ -443,54 +443,71 @@ class GenericShareDriverTestCase(test.TestCase):
|
|||
|
||||
def test_get_volume(self):
|
||||
volume = fake_volume.FakeVolume(
|
||||
display_name=CONF.volume_name_template % self.share['id'])
|
||||
name=CONF.volume_name_template % self.share['id'])
|
||||
self.mock_object(self._driver.volume_api, 'get_all',
|
||||
mock.Mock(return_value=[volume]))
|
||||
result = self._driver._get_volume(self._context, self.share['id'])
|
||||
self.assertEqual(result, volume)
|
||||
self._driver.volume_api.get_all.assert_called_once_with(
|
||||
self._context, {'all_tenants': True, 'name': volume['name']})
|
||||
|
||||
def test_get_volume_none(self):
|
||||
vol_name = (
|
||||
self._driver.configuration.volume_name_template % self.share['id'])
|
||||
self.mock_object(self._driver.volume_api, 'get_all',
|
||||
mock.Mock(return_value=[]))
|
||||
result = self._driver._get_volume(self._context, self.share['id'])
|
||||
self.assertEqual(result, None)
|
||||
self._driver.volume_api.get_all.assert_called_once_with(
|
||||
self._context, {'all_tenants': True, 'name': vol_name})
|
||||
|
||||
def test_get_volume_error(self):
|
||||
volume = fake_volume.FakeVolume(
|
||||
display_name=CONF.volume_name_template % self.share['id'])
|
||||
name=CONF.volume_name_template % self.share['id'])
|
||||
self.mock_object(self._driver.volume_api, 'get_all',
|
||||
mock.Mock(return_value=[volume, volume]))
|
||||
self.assertRaises(exception.ManilaException,
|
||||
self._driver._get_volume,
|
||||
self._context, self.share['id'])
|
||||
self._driver.volume_api.get_all.assert_called_once_with(
|
||||
self._context, {'all_tenants': True, 'name': volume['name']})
|
||||
|
||||
def test_get_volume_snapshot(self):
|
||||
volume_snapshot = fake_volume.FakeVolumeSnapshot(
|
||||
display_name=CONF.volume_snapshot_name_template %
|
||||
name=self._driver.configuration.volume_snapshot_name_template %
|
||||
self.snapshot['id'])
|
||||
self.mock_object(self._driver.volume_api, 'get_all_snapshots',
|
||||
mock.Mock(return_value=[volume_snapshot]))
|
||||
result = self._driver._get_volume_snapshot(self._context,
|
||||
self.snapshot['id'])
|
||||
self.assertEqual(result, volume_snapshot)
|
||||
self._driver.volume_api.get_all_snapshots.assert_called_once_with(
|
||||
self._context, {'name': volume_snapshot['name']})
|
||||
|
||||
def test_get_volume_snapshot_none(self):
|
||||
snap_name = (
|
||||
self._driver.configuration.volume_snapshot_name_template %
|
||||
self.share['id'])
|
||||
self.mock_object(self._driver.volume_api, 'get_all_snapshots',
|
||||
mock.Mock(return_value=[]))
|
||||
result = self._driver._get_volume_snapshot(self._context,
|
||||
self.share['id'])
|
||||
self.assertEqual(result, None)
|
||||
self._driver.volume_api.get_all_snapshots.assert_called_once_with(
|
||||
self._context, {'name': snap_name})
|
||||
|
||||
def test_get_volume_snapshot_error(self):
|
||||
volume_snapshot = fake_volume.FakeVolumeSnapshot(
|
||||
display_name=CONF.volume_snapshot_name_template %
|
||||
name=self._driver.configuration.volume_snapshot_name_template %
|
||||
self.snapshot['id'])
|
||||
self.mock_object(self._driver.volume_api, 'get_all_snapshots',
|
||||
mock.Mock(return_value=[volume_snapshot,
|
||||
volume_snapshot]))
|
||||
self.assertRaises(exception.ManilaException,
|
||||
self._driver._get_volume_snapshot, self._context,
|
||||
self.share['id'])
|
||||
self.mock_object(
|
||||
self._driver.volume_api, 'get_all_snapshots',
|
||||
mock.Mock(return_value=[volume_snapshot, volume_snapshot]))
|
||||
self.assertRaises(
|
||||
exception.ManilaException, self._driver._get_volume_snapshot,
|
||||
self._context, self.snapshot['id'])
|
||||
self._driver.volume_api.get_all_snapshots.assert_called_once_with(
|
||||
self._context, {'name': volume_snapshot['name']})
|
||||
|
||||
def test_detach_volume(self):
|
||||
available_volume = fake_volume.FakeVolume()
|
||||
|
|
Loading…
Reference in New Issue