From ac1aaf6624728dc3c800248c2c2a113a3f95ca1e Mon Sep 17 00:00:00 2001 From: Rao Adnan Khan Date: Thu, 27 Apr 2017 08:01:18 -0500 Subject: [PATCH] Add client for assisted volume snapshots API. This will invoke post and delete calls on os-assisted-volume-snapshots endpoint. Closes-bug: #1668407 Co-Authored-By: Ghanshyam Mann Change-Id: I81e8fd9f89ec1cb00fc0116c31f9c0559406164 --- ...lume-snapshot-client-737f5cb35d58c1b6.yaml | 4 ++ tempest/api/compute/base.py | 2 + tempest/clients.py | 2 + tempest/lib/services/compute/__init__.py | 9 ++- .../assisted_volume_snapshots_client.py | 63 +++++++++++++++++++ .../test_assisted_volume_snapshots_client.py | 53 ++++++++++++++++ 6 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/add-assisted-volume-snapshot-client-737f5cb35d58c1b6.yaml create mode 100644 tempest/lib/services/compute/assisted_volume_snapshots_client.py create mode 100644 tempest/tests/lib/services/compute/test_assisted_volume_snapshots_client.py diff --git a/releasenotes/notes/add-assisted-volume-snapshot-client-737f5cb35d58c1b6.yaml b/releasenotes/notes/add-assisted-volume-snapshot-client-737f5cb35d58c1b6.yaml new file mode 100644 index 0000000000..5498688adb --- /dev/null +++ b/releasenotes/notes/add-assisted-volume-snapshot-client-737f5cb35d58c1b6.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Add a new client to handle requests to create and delete assisted volume snapshots. diff --git a/tempest/api/compute/base.py b/tempest/api/compute/base.py index bb0f5ada11..7900b77822 100644 --- a/tempest/api/compute/base.py +++ b/tempest/api/compute/base.py @@ -638,6 +638,8 @@ class BaseV2ComputeAdminTest(BaseV2ComputeTest): cls.admin_flavors_client = cls.os_admin.flavors_client cls.admin_servers_client = cls.os_admin.servers_client cls.image_client = cls.os_admin.image_client_v2 + cls.admin_assisted_volume_snapshots_client = \ + cls.os_admin.assisted_volume_snapshots_client def create_flavor(self, ram, vcpus, disk, name=None, is_public='True', **kwargs): diff --git a/tempest/clients.py b/tempest/clients.py index 6db43dbd85..c4e00fe1f1 100644 --- a/tempest/clients.py +++ b/tempest/clients.py @@ -133,6 +133,8 @@ class Manager(clients.ServiceClients): self.instance_usages_audit_log_client = ( self.compute.InstanceUsagesAuditLogClient()) self.tenant_networks_client = self.compute.TenantNetworksClient() + self.assisted_volume_snapshots_client = ( + self.compute.AssistedVolumeSnapshotsClient()) # NOTE: The following client needs special timeout values because # the API is a proxy for the other component. diff --git a/tempest/lib/services/compute/__init__.py b/tempest/lib/services/compute/__init__.py index 91e896af0e..8d07a45675 100644 --- a/tempest/lib/services/compute/__init__.py +++ b/tempest/lib/services/compute/__init__.py @@ -14,6 +14,8 @@ from tempest.lib.services.compute.agents_client import AgentsClient from tempest.lib.services.compute.aggregates_client import AggregatesClient +from tempest.lib.services.compute.assisted_volume_snapshots_client import \ + AssistedVolumeSnapshotsClient from tempest.lib.services.compute.availability_zone_client import \ AvailabilityZoneClient from tempest.lib.services.compute.baremetal_nodes_client import \ @@ -63,9 +65,10 @@ from tempest.lib.services.compute.versions_client import VersionsClient from tempest.lib.services.compute.volumes_client import \ VolumesClient -__all__ = ['AgentsClient', 'AggregatesClient', 'AvailabilityZoneClient', - 'BaremetalNodesClient', 'CertificatesClient', 'ExtensionsClient', - 'FixedIPsClient', 'FlavorsClient', 'FloatingIPPoolsClient', +__all__ = ['AgentsClient', 'AggregatesClient', 'AssistedVolumeSnapshotsClient', + 'AvailabilityZoneClient', 'BaremetalNodesClient', + 'CertificatesClient', 'ExtensionsClient', 'FixedIPsClient', + 'FlavorsClient', 'FloatingIPPoolsClient', 'FloatingIPsBulkClient', 'FloatingIPsClient', 'HostsClient', 'HypervisorClient', 'ImagesClient', 'InstanceUsagesAuditLogClient', 'InterfacesClient', 'KeyPairsClient', 'LimitsClient', diff --git a/tempest/lib/services/compute/assisted_volume_snapshots_client.py b/tempest/lib/services/compute/assisted_volume_snapshots_client.py new file mode 100644 index 0000000000..8b67491286 --- /dev/null +++ b/tempest/lib/services/compute/assisted_volume_snapshots_client.py @@ -0,0 +1,63 @@ +# Copyright 2017 AT&T Corp +# All Rights Reserved. +# +# 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 six.moves.urllib import parse as urllib + +from tempest.lib.common import rest_client +from tempest.lib.services.compute import base_compute_client + + +class AssistedVolumeSnapshotsClient(base_compute_client.BaseComputeClient): + """Service client for assisted volume snapshots""" + + def delete_assisted_volume_snapshot(self, volume_id, snapshot_id): + """Delete snapshot for the given volume id. + + For a full list of available parameters, please refer to the official + API reference: + https://docs.openstack.org/api-ref/compute/#delete-assisted-volume-snapshot + + :param volume_id: UUID of the volume + :param snapshot_id: The UUID of the snapshot + """ + query_param = {'delete_info': json.dumps({'volume_id': volume_id})} + resp, body = self.delete("os-assisted-volume-snapshots/%s?%s" + % (snapshot_id, + urllib.urlencode(query_param))) + return rest_client.ResponseBody(resp, body) + + def create_assisted_volume_snapshot(self, volume_id, snapshot_id, + **kwargs): + """Create a new assisted volume snapshot. + + For a full list of available parameters, please refer to the official + API reference: + https://docs.openstack.org/api-ref/compute/#create-assisted-volume-snapshots + + :param volume_id: the source volume ID + :param snapshot_id: the UUID for a snapshot + :param type: Type of snapshot, such as qcow2 + :param new_file: The name of image file that will be created + """ + url = "os-assisted-volume-snapshots" + info = {"snapshot_id": snapshot_id} + if kwargs: + info.update(kwargs) + body = {"snapshot": {"volume_id": volume_id, "create_info": info}} + post_body = json.dumps(body) + resp, body = self.post(url, post_body) + body = json.loads(body) + return rest_client.ResponseBody(resp, body) diff --git a/tempest/tests/lib/services/compute/test_assisted_volume_snapshots_client.py b/tempest/tests/lib/services/compute/test_assisted_volume_snapshots_client.py new file mode 100644 index 0000000000..79855ea25c --- /dev/null +++ b/tempest/tests/lib/services/compute/test_assisted_volume_snapshots_client.py @@ -0,0 +1,53 @@ +# Copyright 2017 AT&T. +# +# 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.compute import assisted_volume_snapshots_client +from tempest.tests.lib import fake_auth_provider +from tempest.tests.lib.services import base + + +class TestVolumesClient(base.BaseServiceTest): + + FAKE_SNAPSHOT = { + "id": "bf7b810c-70df-4c64-88a7-8588f7a6739c", + "volumeId": "59f17c4f-66d4-4271-be40-f200523423a9" + } + + def setUp(self): + super(TestVolumesClient, self).setUp() + fake_auth = fake_auth_provider.FakeAuthProvider() + self.client = assisted_volume_snapshots_client.\ + AssistedVolumeSnapshotsClient(fake_auth, 'compute', 'regionOne') + + def _test_create_assisted_volume_snapshot(self, bytes_body=False): + kwargs = {"type": "qcow2", "new_file": "fake_name"} + self.check_service_client_function( + self.client.create_assisted_volume_snapshot, + 'tempest.lib.common.rest_client.RestClient.post', + {"snapshot": self.FAKE_SNAPSHOT}, + bytes_body, status=200, volume_id=self.FAKE_SNAPSHOT['volumeId'], + snapshot_id=self.FAKE_SNAPSHOT['id'], **kwargs) + + def test_create_assisted_volume_snapshot_with_str_body(self): + self._test_create_assisted_volume_snapshot() + + def test_create_assisted_volume_snapshot_with_byte_body(self): + self._test_create_assisted_volume_snapshot(bytes_body=True) + + def test_delete_assisted_volume_snapshot(self): + self.check_service_client_function( + self.client.delete_assisted_volume_snapshot, + 'tempest.lib.common.rest_client.RestClient.delete', + {}, status=204, volume_id=self.FAKE_SNAPSHOT['volumeId'], + snapshot_id=self.FAKE_SNAPSHOT['id'])