From 677f130dde4ca7ddf99cc4e4cae1def3491e3912 Mon Sep 17 00:00:00 2001 From: John Griffith Date: Fri, 1 Dec 2017 18:26:21 +0000 Subject: [PATCH] Add shared_targets and service_uuid to volumes This adds the last bits to the shared_targets and service_uuid additions to volumes. The object and db models are already updated and this change simply introduces API MV 3.48 to expose the new fields to the Volume view. These fields are intended to be used for identifying if the back end device serving a volume is using shared targets, and provides the service_uuid to be used as a suggested/unique handle for locking. Change-Id: Ibd18c5f6c772f7265175a63ed2b598fcc3c87bc1 --- cinder/api/microversions.py | 2 ++ cinder/api/openstack/api_version_request.py | 3 ++- .../api/openstack/rest_api_version_history.rst | 4 ++++ cinder/api/v3/views/volumes.py | 7 +++++++ cinder/tests/unit/volume/test_volume.py | 16 ++++++++++++---- cinder/volume/api.py | 3 +++ 6 files changed, 30 insertions(+), 5 deletions(-) diff --git a/cinder/api/microversions.py b/cinder/api/microversions.py index f667784062d..c97b30d75e2 100644 --- a/cinder/api/microversions.py +++ b/cinder/api/microversions.py @@ -133,6 +133,8 @@ SUPPORT_NOVA_IMAGE = '3.46' VOLUME_CREATE_FROM_BACKUP = '3.47' +VOLUME_SHARED_TARGETS_AND_SERVICE_FIELDS = '3.48' + def get_mv_header(version): """Gets a formatted HTTP microversion header. diff --git a/cinder/api/openstack/api_version_request.py b/cinder/api/openstack/api_version_request.py index 1993507cdf7..3e0c4270ddf 100644 --- a/cinder/api/openstack/api_version_request.py +++ b/cinder/api/openstack/api_version_request.py @@ -111,6 +111,7 @@ REST_API_VERSION_HISTORY = """ detail APIs. * 3.46 - Support create volume by Nova specific image (0 size image). * 3.47 - Support create volume from backup. + * 3.48 - Add ``shared_targets`` and ``service_uuid`` fields to volume. """ # The minimum and maximum versions of the API supported @@ -118,7 +119,7 @@ REST_API_VERSION_HISTORY = """ # minimum version of the API supported. # Explicitly using /v2 endpoints will still work _MIN_API_VERSION = "3.0" -_MAX_API_VERSION = "3.47" +_MAX_API_VERSION = "3.48" _LEGACY_API_VERSION2 = "2.0" UPDATED = "2017-09-19T20:18:14Z" diff --git a/cinder/api/openstack/rest_api_version_history.rst b/cinder/api/openstack/rest_api_version_history.rst index 5cf45329791..20d37ad569b 100644 --- a/cinder/api/openstack/rest_api_version_history.rst +++ b/cinder/api/openstack/rest_api_version_history.rst @@ -385,3 +385,7 @@ user documentation. 3.47 ---- Support create volume from backup. + +3.48 +---- + Add ``shared_targets`` and ``service_uuid`` fields to volume. diff --git a/cinder/api/v3/views/volumes.py b/cinder/api/v3/views/volumes.py index 168a24a4e2e..e2bd03997e5 100644 --- a/cinder/api/v3/views/volumes.py +++ b/cinder/api/v3/views/volumes.py @@ -54,6 +54,13 @@ class ViewBuilder(views_v2.ViewBuilder): req_version.matches(mv.VOLUME_DETAIL_PROVIDER_ID, None)): volume_ref['volume']['provider_id'] = volume.get('provider_id') + if req_version.matches( + mv.VOLUME_SHARED_TARGETS_AND_SERVICE_FIELDS, None): + volume_ref['volume']['shared_targets'] = volume.get( + 'shared_targets', None) + volume_ref['volume']['service_uuid'] = volume.get( + 'service_uuid', None) + return volume_ref def _list_view(self, func, request, volumes, volume_count, diff --git a/cinder/tests/unit/volume/test_volume.py b/cinder/tests/unit/volume/test_volume.py index 2e108e7e525..1681ca49099 100644 --- a/cinder/tests/unit/volume/test_volume.py +++ b/cinder/tests/unit/volume/test_volume.py @@ -911,7 +911,9 @@ class VolumeTestCase(base.BaseVolumeTestCase): self.volume.delete_volume(self.context, volume_src) @mock.patch('cinder.volume.flows.api.create_volume.get_flow') - def test_create_volume_from_snapshot_with_types(self, _get_flow): + @mock.patch('cinder.objects.volume.Volume.get_by_id') + def test_create_volume_from_snapshot_with_types( + self, _get_by_id, _get_flow): """Test volume create from snapshot with types including mistmatch.""" volume_api = cinder.volume.api.API() @@ -973,7 +975,9 @@ class VolumeTestCase(base.BaseVolumeTestCase): snapshot=snapshot_obj) @mock.patch('cinder.volume.flows.api.create_volume.get_flow') - def test_create_volume_from_source_with_types(self, _get_flow): + @mock.patch('cinder.objects.volume.Volume.get_by_id') + def test_create_volume_from_source_with_types( + self, _get_by_id, _get_flow): """Test volume create from source with types including mistmatch.""" volume_api = cinder.volume.api.API() foo_type = fake_volume.fake_volume_type_obj( @@ -1025,7 +1029,9 @@ class VolumeTestCase(base.BaseVolumeTestCase): source_volume=source_vol) @mock.patch('cinder.volume.flows.api.create_volume.get_flow') - def test_create_volume_from_source_with_same_backend(self, _get_flow): + @mock.patch('cinder.objects.volume.Volume.get_by_id') + def test_create_volume_from_source_with_same_backend( + self, _get_by_id, _get_flow): """Test volume create from source with type mismatch same backend.""" volume_api = cinder.volume.api.API() @@ -1070,7 +1076,9 @@ class VolumeTestCase(base.BaseVolumeTestCase): source_volume=source_vol) @mock.patch('cinder.volume.flows.api.create_volume.get_flow') - def test_create_from_source_and_snap_only_one_backend(self, _get_flow): + @mock.patch('cinder.objects.volume.Volume.get_by_id') + def test_create_from_source_and_snap_only_one_backend( + self, _get_by_id, _get_flow): """Test create from source and snap with type mismatch one backend.""" volume_api = cinder.volume.api.API() diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 423402421f9..955df03db53 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -334,6 +334,9 @@ class API(base.Base): if flow_engine.storage.fetch('refresh_az'): self.list_availability_zones(enable_cache=True, refresh_cache=True) + # Refresh the object here, otherwise things ain't right + vref = objects.Volume.get_by_id( + context, vref['id']) LOG.info("Create volume request issued successfully.", resource=vref) return vref