diff --git a/releasenotes/notes/introduce-attachments-client-add-show-attachment-api-c3111f7e560a87b3.yaml b/releasenotes/notes/introduce-attachments-client-add-show-attachment-api-c3111f7e560a87b3.yaml new file mode 100644 index 0000000000..a058137f50 --- /dev/null +++ b/releasenotes/notes/introduce-attachments-client-add-show-attachment-api-c3111f7e560a87b3.yaml @@ -0,0 +1,8 @@ +--- +features: + - | + A new attachments client library has been introduced for the volume + service. + + Initially only the show_attachment API is provided. This API requires a + minimum volume API microversion of ``3.27``. diff --git a/tempest/clients.py b/tempest/clients.py index 6aed92e8e0..1db93a07f4 100644 --- a/tempest/clients.py +++ b/tempest/clients.py @@ -263,6 +263,8 @@ class Manager(clients.ServiceClients): self.volume_v3.MessagesClient()) self.volume_versions_client_latest = ( self.volume_v3.VersionsClient()) + self.attachments_client_latest = ( + self.volume_v3.AttachmentsClient()) # TODO(gmann): Below alias for service clients have been # deprecated and will be removed in future. Start using the alias diff --git a/tempest/lib/services/volume/v3/__init__.py b/tempest/lib/services/volume/v3/__init__.py index a1b7de31f8..e2fa836131 100644 --- a/tempest/lib/services/volume/v3/__init__.py +++ b/tempest/lib/services/volume/v3/__init__.py @@ -11,6 +11,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations under # the License. +from tempest.lib.services.volume.v3.attachments_client import AttachmentsClient from tempest.lib.services.volume.v3.availability_zone_client \ import AvailabilityZoneClient from tempest.lib.services.volume.v3.backups_client import BackupsClient @@ -43,12 +44,11 @@ from tempest.lib.services.volume.v3.versions_client import VersionsClient from tempest.lib.services.volume.v3.volume_manage_client import \ VolumeManageClient from tempest.lib.services.volume.v3.volumes_client import VolumesClient - -__all__ = ['AvailabilityZoneClient', 'BackupsClient', 'BaseClient', - 'CapabilitiesClient', 'EncryptionTypesClient', 'ExtensionsClient', - 'GroupSnapshotsClient', 'GroupTypesClient', 'GroupsClient', - 'HostsClient', 'LimitsClient', 'MessagesClient', 'QosSpecsClient', - 'QuotaClassesClient', 'QuotasClient', 'SchedulerStatsClient', - 'ServicesClient', 'SnapshotManageClient', 'SnapshotsClient', - 'TransfersClient', 'TypesClient', 'VersionsClient', - 'VolumeManageClient', 'VolumesClient'] +__all__ = ['AttachmentsClient', 'AvailabilityZoneClient', 'BackupsClient', + 'BaseClient', 'CapabilitiesClient', 'EncryptionTypesClient', + 'ExtensionsClient', 'GroupSnapshotsClient', 'GroupTypesClient', + 'GroupsClient', 'HostsClient', 'LimitsClient', 'MessagesClient', + 'QosSpecsClient', 'QuotaClassesClient', 'QuotasClient', + 'SchedulerStatsClient', 'ServicesClient', 'SnapshotManageClient', + 'SnapshotsClient', 'TransfersClient', 'TypesClient', + 'VersionsClient', 'VolumeManageClient', 'VolumesClient'] diff --git a/tempest/lib/services/volume/v3/attachments_client.py b/tempest/lib/services/volume/v3/attachments_client.py new file mode 100644 index 0000000000..5e448f715a --- /dev/null +++ b/tempest/lib/services/volume/v3/attachments_client.py @@ -0,0 +1,28 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from oslo_serialization import jsonutils as json + +from tempest.lib.common import rest_client +from tempest.lib.services.volume import base_client + + +class AttachmentsClient(base_client.BaseClient): + """Client class to send CRUD attachment V3 API requests""" + + def show_attachment(self, attachment_id): + """Show volume attachment.""" + url = "attachments/%s" % (attachment_id) + resp, body = self.get(url) + body = json.loads(body) + self.expected_success(200, resp.status) + return rest_client.ResponseBody(resp, body) diff --git a/tempest/tests/lib/services/volume/v3/test_attachments_client.py b/tempest/tests/lib/services/volume/v3/test_attachments_client.py new file mode 100644 index 0000000000..52c94e588f --- /dev/null +++ b/tempest/tests/lib/services/volume/v3/test_attachments_client.py @@ -0,0 +1,46 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from tempest.lib.services.volume.v3 import attachments_client +from tempest.tests.lib import fake_auth_provider +from tempest.tests.lib.services import base + +from oslo_utils.fixture import uuidsentinel as uuids + + +class TestAttachmentsClient(base.BaseServiceTest): + + FAKE_ATTACHMENT_INFO = { + "attachment": { + "status": "attaching", + "detached_at": "2015-09-16T09:28:52.000000", + "connection_info": {}, + "attached_at": "2015-09-16T09:28:52.000000", + "attach_mode": "ro", + "instance": uuids.instance_id, + "volume_id": uuids.volume_id, + "id": uuids.id, + } + } + + def setUp(self): + super(TestAttachmentsClient, self).setUp() + fake_auth = fake_auth_provider.FakeAuthProvider() + self.client = attachments_client.AttachmentsClient(fake_auth, + 'volume', + 'regionOne') + + def test_show_attachment(self): + self.check_service_client_function( + self.client.show_attachment, + 'tempest.lib.common.rest_client.RestClient.get', + self.FAKE_ATTACHMENT_INFO, attachment_id=uuids.id)