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 <gmann@ghanshyammann.com>

Change-Id: I81e8fd9f89ec1cb00fc0116c31f9c0559406164
This commit is contained in:
Rao Adnan Khan 2017-04-27 08:01:18 -05:00 committed by Ghanshyam Mann
parent 5f54db93eb
commit ac1aaf6624
6 changed files with 130 additions and 3 deletions

View File

@ -0,0 +1,4 @@
---
features:
- |
Add a new client to handle requests to create and delete assisted volume snapshots.

View File

@ -638,6 +638,8 @@ class BaseV2ComputeAdminTest(BaseV2ComputeTest):
cls.admin_flavors_client = cls.os_admin.flavors_client cls.admin_flavors_client = cls.os_admin.flavors_client
cls.admin_servers_client = cls.os_admin.servers_client cls.admin_servers_client = cls.os_admin.servers_client
cls.image_client = cls.os_admin.image_client_v2 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, def create_flavor(self, ram, vcpus, disk, name=None,
is_public='True', **kwargs): is_public='True', **kwargs):

View File

@ -133,6 +133,8 @@ class Manager(clients.ServiceClients):
self.instance_usages_audit_log_client = ( self.instance_usages_audit_log_client = (
self.compute.InstanceUsagesAuditLogClient()) self.compute.InstanceUsagesAuditLogClient())
self.tenant_networks_client = self.compute.TenantNetworksClient() self.tenant_networks_client = self.compute.TenantNetworksClient()
self.assisted_volume_snapshots_client = (
self.compute.AssistedVolumeSnapshotsClient())
# NOTE: The following client needs special timeout values because # NOTE: The following client needs special timeout values because
# the API is a proxy for the other component. # the API is a proxy for the other component.

View File

@ -14,6 +14,8 @@
from tempest.lib.services.compute.agents_client import AgentsClient from tempest.lib.services.compute.agents_client import AgentsClient
from tempest.lib.services.compute.aggregates_client import AggregatesClient 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 \ from tempest.lib.services.compute.availability_zone_client import \
AvailabilityZoneClient AvailabilityZoneClient
from tempest.lib.services.compute.baremetal_nodes_client import \ 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 \ from tempest.lib.services.compute.volumes_client import \
VolumesClient VolumesClient
__all__ = ['AgentsClient', 'AggregatesClient', 'AvailabilityZoneClient', __all__ = ['AgentsClient', 'AggregatesClient', 'AssistedVolumeSnapshotsClient',
'BaremetalNodesClient', 'CertificatesClient', 'ExtensionsClient', 'AvailabilityZoneClient', 'BaremetalNodesClient',
'FixedIPsClient', 'FlavorsClient', 'FloatingIPPoolsClient', 'CertificatesClient', 'ExtensionsClient', 'FixedIPsClient',
'FlavorsClient', 'FloatingIPPoolsClient',
'FloatingIPsBulkClient', 'FloatingIPsClient', 'HostsClient', 'FloatingIPsBulkClient', 'FloatingIPsClient', 'HostsClient',
'HypervisorClient', 'ImagesClient', 'InstanceUsagesAuditLogClient', 'HypervisorClient', 'ImagesClient', 'InstanceUsagesAuditLogClient',
'InterfacesClient', 'KeyPairsClient', 'LimitsClient', 'InterfacesClient', 'KeyPairsClient', 'LimitsClient',

View File

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

View File

@ -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'])