From 589ca69a207b44d671d181e613603a8ae31286a9 Mon Sep 17 00:00:00 2001 From: TommyLike Date: Wed, 10 May 2017 10:13:23 +0800 Subject: [PATCH] Tempest for revert-to-snapshot Added tempest testcases for revert-to-snapshot feature. Depends-On: 16518c3b293561a2e9f4fa42a5247345ebd1e2b3 Change-Id: I97a9241ce53b144c30bc16d65dc8cf6e3f679743 --- .../tempest/api/volume/test_volume_revert.py | 77 +++++++++++++++++++ cinder/tests/tempest/cinder_clients.py | 3 + .../tempest/services/volume_revert_client.py | 34 ++++++++ 3 files changed, 114 insertions(+) create mode 100644 cinder/tests/tempest/api/volume/test_volume_revert.py create mode 100644 cinder/tests/tempest/services/volume_revert_client.py diff --git a/cinder/tests/tempest/api/volume/test_volume_revert.py b/cinder/tests/tempest/api/volume/test_volume_revert.py new file mode 100644 index 0000000..b5151c5 --- /dev/null +++ b/cinder/tests/tempest/api/volume/test_volume_revert.py @@ -0,0 +1,77 @@ +# Copyright (c) 2017 Huawei. +# 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 tempest.api.volume import base as volume_base +from tempest.common import waiters +from tempest import config +from tempest.lib import decorators + +from cinder.tests.tempest import cinder_clients + +CONF = config.CONF + + +class VolumeRevertTests(volume_base.BaseVolumeTest): + min_microversion = '3.40' + + @classmethod + def setup_clients(cls): + cls._api_version = 3 + super(VolumeRevertTests, cls).setup_clients() + + manager = cinder_clients.Manager(cls.os_primary) + cls.volume_revert_client = manager.volume_revet_client + + def setUp(self): + super(VolumeRevertTests, self).setUp() + # Create volume + self.volume = self.create_volume(size=1) + # Create snapshot + self.snapshot = self.create_snapshot(self.volume['id']) + + @decorators.idempotent_id('87b7dcb7-4950-4a3a-802c-ece55491846d') + def test_volume_revert_to_snapshot(self): + """Test revert to snapshot""" + # Revert to snapshot + self.volume_revert_client.revert_to_snapshot(self.volume, + self.snapshot['id']) + waiters.wait_for_volume_resource_status( + self.volumes_client, + self.volume['id'], 'available') + waiters.wait_for_volume_resource_status( + self.snapshots_client, + self.snapshot['id'], 'available') + volume = self.volumes_client.show_volume(self.volume['id'])['volume'] + + self.assertEqual(1, volume['size']) + + @decorators.idempotent_id('4e8b0788-87fe-430d-be7a-444d7f8e0347') + def test_volume_revert_to_snapshot_after_extended(self): + """Test revert to snapshot after extended""" + # Extend the volume + self.volumes_client.extend_volume(self.volume['id'], new_size=2) + waiters.wait_for_volume_resource_status(self.volumes_client, + self.volume['id'], 'available') + # Revert to snapshot + self.volume_revert_client.revert_to_snapshot(self.volume, + self.snapshot['id']) + waiters.wait_for_volume_resource_status( + self.volumes_client, + self.volume['id'], 'available') + waiters.wait_for_volume_resource_status( + self.snapshots_client, + self.snapshot['id'], 'available') + volume = self.volumes_client.show_volume(self.volume['id'])['volume'] + self.assertEqual(2, volume['size']) diff --git a/cinder/tests/tempest/cinder_clients.py b/cinder/tests/tempest/cinder_clients.py index 8f829ef..aad32d4 100644 --- a/cinder/tests/tempest/cinder_clients.py +++ b/cinder/tests/tempest/cinder_clients.py @@ -16,6 +16,7 @@ from tempest import config from cinder.tests.tempest.services import consistencygroups_client +from cinder.tests.tempest.services import volume_revert_client CONF = config.CONF @@ -35,3 +36,5 @@ class Manager(object): self.consistencygroups_adm_client = ( consistencygroups_client.ConsistencyGroupsClient(auth_provider, **params)) + self.volume_revet_client = ( + volume_revert_client.VolumeRevertClient(auth_provider, **params)) diff --git a/cinder/tests/tempest/services/volume_revert_client.py b/cinder/tests/tempest/services/volume_revert_client.py new file mode 100644 index 0000000..285494a --- /dev/null +++ b/cinder/tests/tempest/services/volume_revert_client.py @@ -0,0 +1,34 @@ +# Copyright (C) 2017 Huawei. +# 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 tempest.lib.common import rest_client +from tempest.lib.services.volume.v3 import base_client + + +class VolumeRevertClient(base_client.BaseClient): + """Client class to send revert to snapshot action API request""" + + def __init__(self, auth_provider, service, region, **kwargs): + super(VolumeRevertClient, self).__init__( + auth_provider, service, region, **kwargs) + + def revert_to_snapshot(self, volume, snapshot_id): + """Revert a volume to snapshot.""" + post_body = {'snapshot_id': snapshot_id} + post_body = json.dumps({'revert': post_body}) + resp, body = self.post('volumes/%s/action' % volume['id'], + post_body) + return rest_client.ResponseBody(resp, body)