Remove Cinder API v1 compatibility

Since Cinder API v1 is removed in I03bf2db5bd7e2fdfb4f6032758ccaf2b348a82ba
we don't need _replace_v2_parameters function anymore.

Change-Id: I18c2787241f1dcbe4c0afc14a76630d9bfb1162a
This commit is contained in:
Ivan Kolodyazhny 2018-05-18 17:03:44 +03:00
parent e5fbf73411
commit 8ce6b37e5c
4 changed files with 14 additions and 35 deletions

View File

@ -74,7 +74,6 @@ class BaseCinderAPIResourceWrapper(base.APIResourceWrapper):
def name(self): def name(self):
# If a volume doesn't have a name, use its id. # If a volume doesn't have a name, use its id.
return (getattr(self._apiresource, 'name', None) or return (getattr(self._apiresource, 'name', None) or
getattr(self._apiresource, 'display_name', None) or
getattr(self._apiresource, 'id', None)) getattr(self._apiresource, 'id', None))
@property @property
@ -249,15 +248,6 @@ def get_microversion(request, features):
'cinder', features, api_versions.APIVersion, min_ver, max_ver)) 'cinder', features, api_versions.APIVersion, min_ver, max_ver))
def _replace_v2_parameters(data):
if VERSIONS.active < 2:
data['display_name'] = data['name']
data['display_description'] = data['description']
del data['name']
del data['description']
return data
def version_get(): def version_get():
api_version = VERSIONS.get_active_version() api_version = VERSIONS.get_active_version()
return api_version['version'] return api_version['version']
@ -365,7 +355,6 @@ def volume_create(request, size, name, description, volume_type,
'imageRef': image_id, 'imageRef': image_id,
'availability_zone': availability_zone, 'availability_zone': availability_zone,
'source_volid': source_volid} 'source_volid': source_volid}
data = _replace_v2_parameters(data)
volume = cinderclient(request).volumes.create(size, **data) volume = cinderclient(request).volumes.create(size, **data)
return Volume(volume) return Volume(volume)
@ -398,7 +387,6 @@ def volume_set_bootable(request, volume_id, bootable):
def volume_update(request, volume_id, name, description): def volume_update(request, volume_id, name, description):
vol_data = {'name': name, vol_data = {'name': name,
'description': description} 'description': description}
vol_data = _replace_v2_parameters(vol_data)
return cinderclient(request).volumes.update(volume_id, return cinderclient(request).volumes.update(volume_id,
**vol_data) **vol_data)
@ -493,7 +481,6 @@ def volume_snapshot_create(request, volume_id, name,
data = {'name': name, data = {'name': name,
'description': description, 'description': description,
'force': force} 'force': force}
data = _replace_v2_parameters(data)
return VolumeSnapshot(cinderclient(request).volume_snapshots.create( return VolumeSnapshot(cinderclient(request).volume_snapshots.create(
volume_id, **data)) volume_id, **data))
@ -508,7 +495,6 @@ def volume_snapshot_delete(request, snapshot_id):
def volume_snapshot_update(request, snapshot_id, name, description): def volume_snapshot_update(request, snapshot_id, name, description):
snapshot_data = {'name': name, snapshot_data = {'name': name,
'description': description} 'description': description}
snapshot_data = _replace_v2_parameters(snapshot_data)
return cinderclient(request).volume_snapshots.update(snapshot_id, return cinderclient(request).volume_snapshots.update(snapshot_id,
**snapshot_data) **snapshot_data)

View File

@ -87,7 +87,7 @@ def data(TEST):
{'id': "11023e92-8008-4c8b-8059-7f2293ff3887", {'id': "11023e92-8008-4c8b-8059-7f2293ff3887",
'status': 'available', 'status': 'available',
'size': 40, 'size': 40,
'display_name': 'Volume name', 'name': 'Volume name',
'display_description': 'Volume description', 'display_description': 'Volume description',
'created_at': '2014-01-27 10:30:00', 'created_at': '2014-01-27 10:30:00',
'volume_type': None, 'volume_type': None,
@ -97,7 +97,7 @@ def data(TEST):
{"id": "4b069dd0-6eaa-4272-8abc-5448a68f1cce", {"id": "4b069dd0-6eaa-4272-8abc-5448a68f1cce",
"status": 'available', "status": 'available',
"size": 10, "size": 10,
"display_name": '', "name": '',
"display_description": '', "display_description": '',
"device": "/dev/hda", "device": "/dev/hda",
"created_at": '2010-11-21 18:34:25', "created_at": '2010-11-21 18:34:25',
@ -108,7 +108,7 @@ def data(TEST):
{'id': "21023e92-8008-1234-8059-7f2293ff3889", {'id': "21023e92-8008-1234-8059-7f2293ff3889",
'status': 'in-use', 'status': 'in-use',
'size': 10, 'size': 10,
'display_name': u'my_volume', 'name': u'my_volume',
'display_description': '', 'display_description': '',
'created_at': '2013-04-01 10:30:00', 'created_at': '2013-04-01 10:30:00',
'volume_type': None, 'volume_type': None,
@ -120,7 +120,7 @@ def data(TEST):
'name': 'my_volume2', 'name': 'my_volume2',
'status': 'in-use', 'status': 'in-use',
'size': 10, 'size': 10,
'display_name': u'my_volume2', 'name': u'my_volume2',
'display_description': '', 'display_description': '',
'created_at': '2013-04-01 10:30:00', 'created_at': '2013-04-01 10:30:00',
'volume_type': 'vol_type_2', 'volume_type': 'vol_type_2',
@ -131,7 +131,7 @@ def data(TEST):
{'id': "21023e92-8008-1234-8059-7f2293ff3890", {'id': "21023e92-8008-1234-8059-7f2293ff3890",
'status': 'in-use', 'status': 'in-use',
'size': 10, 'size': 10,
'display_name': u'my_volume', 'name': u'my_volume',
'display_description': '', 'display_description': '',
'created_at': '2013-04-01 10:30:00', 'created_at': '2013-04-01 10:30:00',
'volume_type': None, 'volume_type': None,
@ -471,7 +471,7 @@ def data(TEST):
{'id': "11023e92-8008-4c8b-8059-7f2293ff3881", {'id': "11023e92-8008-4c8b-8059-7f2293ff3881",
'status': 'available', 'status': 'available',
'size': 40, 'size': 40,
'display_name': 'Volume name', 'name': 'Volume name',
'display_description': 'Volume description', 'display_description': 'Volume description',
'created_at': '2014-01-27 10:30:00', 'created_at': '2014-01-27 10:30:00',
'volume_type': 'vol_type_1', 'volume_type': 'vol_type_1',

View File

@ -496,7 +496,6 @@ class CinderApiVersionTests(test.TestCase):
# Get a v2 volume # Get a v2 volume
volume = self.cinder_volumes.get(name="v2_volume") volume = self.cinder_volumes.get(name="v2_volume")
self.assertTrue(hasattr(volume._apiresource, 'name')) self.assertTrue(hasattr(volume._apiresource, 'name'))
self.assertFalse(hasattr(volume._apiresource, 'display_name'))
name = "A v2 test volume name" name = "A v2 test volume name"
description = "A v2 volume description" description = "A v2 volume description"
@ -534,17 +533,4 @@ class CinderApiVersionTests(test.TestCase):
def test_get_id_for_nameless_volume(self): def test_get_id_for_nameless_volume(self):
volume = self.cinder_volumes.first() volume = self.cinder_volumes.first()
setattr(volume._apiresource, 'display_name', "") self.assertEqual('Volume name', volume.name)
self.assertEqual(volume.id, volume.name)
def test_adapt_dictionary_to_v2(self):
volume = self.cinder_volumes.first()
data = {'name': volume.name,
'description': volume.description,
'size': volume.size}
ret_data = api.cinder._replace_v2_parameters(data)
self.assertIn('name', ret_data.keys())
self.assertIn('description', ret_data.keys())
self.assertNotIn('display_name', ret_data.keys())
self.assertNotIn('display_description', ret_data.keys())

View File

@ -0,0 +1,7 @@
---
upgrade:
- |
Remove deprecated Cinder API V1 support. Cinder V1 API was deprecated for
a while and removed in Queens release. If you need to enable Cinder support
you should update the `OPENSTACK_API_VERSIONS` configuration option to use
Cinder V2 or V3 API.