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
This commit is contained in:
John Griffith 2017-12-01 18:26:21 +00:00
parent 2fa6fdd784
commit 677f130dde
6 changed files with 30 additions and 5 deletions

View File

@ -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.

View File

@ -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"

View File

@ -385,3 +385,7 @@ user documentation.
3.47
----
Support create volume from backup.
3.48
----
Add ``shared_targets`` and ``service_uuid`` fields to volume.

View File

@ -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,

View File

@ -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()

View File

@ -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