From f98aef09e2ac0191fb7fb6b949154fedde0bc525 Mon Sep 17 00:00:00 2001 From: Jan Horstmann Date: Mon, 10 Aug 2020 13:09:52 +0200 Subject: [PATCH] Bump MANILACLIENT_VERSION and use sharev2 endpoint This commit bumps MANILACLIENT_VERSION to 2.13 and changes the used service type to sharev2. In order to support the value of "cephx" in property '{"access_rules": [{"access_type": ""}]}' in ressource OS::Manila::Share, manilaclient needs to use at least version 2.13 of the manila API ([1]). The default minimum version in manilaclient, which is used when only a mayor version is specified is 2.0. Additionally the sharev2 service type endpoint has to be used to access the manila v2 API. The export_locations response was removed in version 2.9 of manila API from the "Show share details" request ([2]) and moved to its own endpoint in [3]. Thus it is requested from there now. Additionally the new endpoint is more verbose, so only its path attribute is returned, in order to match the previous behaviour. [1] https://docs.openstack.org/manila/latest/contributor/api_microversion_history.html [2] https://docs.openstack.org/api-ref/shared-file-system/?expanded=show-single-export-location-detail,show-share-details-detail#show-share-details [3] https://docs.openstack.org/api-ref/shared-file-system/?expanded=show-single-export-location-detail,list-export-locations-detail#list-export-locations Change-Id: I4c37be8fad1edb05d812fed260e97e9188fd23ce Story: 2007986 Task: 40612 --- heat/engine/clients/os/manila.py | 4 ++-- heat/engine/resources/openstack/manila/share.py | 14 ++++++++++++-- heat/tests/openstack/manila/test_share.py | 15 +++++++++++++-- ...ess-type-in-manila-share-71a416bf55aea214.yaml | 8 ++++++++ 4 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/support-cephx-access-type-in-manila-share-71a416bf55aea214.yaml diff --git a/heat/engine/clients/os/manila.py b/heat/engine/clients/os/manila.py index f5adf19370..43ff43c24d 100644 --- a/heat/engine/clients/os/manila.py +++ b/heat/engine/clients/os/manila.py @@ -18,7 +18,7 @@ from manilaclient import client as manila_client from manilaclient import exceptions from oslo_config import cfg -MANILACLIENT_VERSION = "2" +MANILACLIENT_VERSION = "2.13" CLIENT_NAME = 'manila' @@ -26,7 +26,7 @@ class ManilaClientPlugin(client_plugin.ClientPlugin): exceptions_module = exceptions - service_types = [SHARE] = ['share'] + service_types = [SHARE] = ['sharev2'] def _create(self): endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type') diff --git a/heat/engine/resources/openstack/manila/share.py b/heat/engine/resources/openstack/manila/share.py index 17b164a7c4..61e93163cc 100644 --- a/heat/engine/resources/openstack/manila/share.py +++ b/heat/engine/resources/openstack/manila/share.py @@ -192,11 +192,21 @@ class ManilaShare(resource.Resource): def _request_share(self): return self.client().shares.get(self.resource_id) + def _request_export_locations(self): + # Only return the "path" response parameter, because that is what was + # returned before API version "2.9" by the shares endpoint + return [export_location.to_dict()['path'] + for export_location in + self.client().share_export_locations.list(self.resource_id)] + def _resolve_attribute(self, name): if self.resource_id is None: return - share = self._request_share() - return str(getattr(share, name)) + if name == self.EXPORT_LOCATIONS_ATTR: + attr = self._request_export_locations() + else: + attr = getattr(self._request_share(), name) + return str(attr) def handle_create(self): # Request IDs of entities from manila diff --git a/heat/tests/openstack/manila/test_share.py b/heat/tests/openstack/manila/test_share.py index 9c23360a9e..cf4e787ed4 100644 --- a/heat/tests/openstack/manila/test_share.py +++ b/heat/tests/openstack/manila/test_share.py @@ -46,13 +46,22 @@ class DummyShare(object): def __init__(self): self.availability_zone = 'az' self.host = 'host' - self.export_locations = 'el' self.share_server_id = 'id' self.created_at = 'ca' self.status = 's' self.project_id = 'p_id' +class DummyShareExportLocation(object): + def __init__(self): + self.export_location = { + 'path': 'el' + } + + def to_dict(self): + return self.export_location + + class ManilaShareTest(common.HeatTestCase): def setUp(self): @@ -212,9 +221,11 @@ class ManilaShareTest(common.HeatTestCase): def test_attributes(self): share = self._create_share("share") share.client().shares.get.return_value = DummyShare() + share.client().share_export_locations.list.return_value = [ + DummyShareExportLocation()] self.assertEqual('az', share.FnGetAtt('availability_zone')) self.assertEqual('host', share.FnGetAtt('host')) - self.assertEqual('el', share.FnGetAtt('export_locations')) + self.assertEqual("['el']", share.FnGetAtt('export_locations')) self.assertEqual('id', share.FnGetAtt('share_server_id')) self.assertEqual('ca', share.FnGetAtt('created_at')) self.assertEqual('s', share.FnGetAtt('status')) diff --git a/releasenotes/notes/support-cephx-access-type-in-manila-share-71a416bf55aea214.yaml b/releasenotes/notes/support-cephx-access-type-in-manila-share-71a416bf55aea214.yaml new file mode 100644 index 0000000000..9ccb633708 --- /dev/null +++ b/releasenotes/notes/support-cephx-access-type-in-manila-share-71a416bf55aea214.yaml @@ -0,0 +1,8 @@ +--- +upgrade: + - | + Manila resources now use the 'sharev2' endpoint and API version '2.13'. +fixes: + - | + OS::Manila::Share now properly supports 'cephx' as a value for property + '{"access_rules": [{"access_type": ""}]}'.