Codebase list cinder-tempest-plugin / 589ca69
Tempest for revert-to-snapshot Added tempest testcases for revert-to-snapshot feature. Depends-On: 16518c3b293561a2e9f4fa42a5247345ebd1e2b3 Change-Id: I97a9241ce53b144c30bc16d65dc8cf6e3f679743 TommyLike 8 years ago
3 changed file(s) with 114 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 # Copyright (c) 2017 Huawei.
1 # All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 from tempest.api.volume import base as volume_base
16 from tempest.common import waiters
17 from tempest import config
18 from tempest.lib import decorators
19
20 from cinder.tests.tempest import cinder_clients
21
22 CONF = config.CONF
23
24
25 class VolumeRevertTests(volume_base.BaseVolumeTest):
26 min_microversion = '3.40'
27
28 @classmethod
29 def setup_clients(cls):
30 cls._api_version = 3
31 super(VolumeRevertTests, cls).setup_clients()
32
33 manager = cinder_clients.Manager(cls.os_primary)
34 cls.volume_revert_client = manager.volume_revet_client
35
36 def setUp(self):
37 super(VolumeRevertTests, self).setUp()
38 # Create volume
39 self.volume = self.create_volume(size=1)
40 # Create snapshot
41 self.snapshot = self.create_snapshot(self.volume['id'])
42
43 @decorators.idempotent_id('87b7dcb7-4950-4a3a-802c-ece55491846d')
44 def test_volume_revert_to_snapshot(self):
45 """Test revert to snapshot"""
46 # Revert to snapshot
47 self.volume_revert_client.revert_to_snapshot(self.volume,
48 self.snapshot['id'])
49 waiters.wait_for_volume_resource_status(
50 self.volumes_client,
51 self.volume['id'], 'available')
52 waiters.wait_for_volume_resource_status(
53 self.snapshots_client,
54 self.snapshot['id'], 'available')
55 volume = self.volumes_client.show_volume(self.volume['id'])['volume']
56
57 self.assertEqual(1, volume['size'])
58
59 @decorators.idempotent_id('4e8b0788-87fe-430d-be7a-444d7f8e0347')
60 def test_volume_revert_to_snapshot_after_extended(self):
61 """Test revert to snapshot after extended"""
62 # Extend the volume
63 self.volumes_client.extend_volume(self.volume['id'], new_size=2)
64 waiters.wait_for_volume_resource_status(self.volumes_client,
65 self.volume['id'], 'available')
66 # Revert to snapshot
67 self.volume_revert_client.revert_to_snapshot(self.volume,
68 self.snapshot['id'])
69 waiters.wait_for_volume_resource_status(
70 self.volumes_client,
71 self.volume['id'], 'available')
72 waiters.wait_for_volume_resource_status(
73 self.snapshots_client,
74 self.snapshot['id'], 'available')
75 volume = self.volumes_client.show_volume(self.volume['id'])['volume']
76 self.assertEqual(2, volume['size'])
1515 from tempest import config
1616
1717 from cinder.tests.tempest.services import consistencygroups_client
18 from cinder.tests.tempest.services import volume_revert_client
1819
1920 CONF = config.CONF
2021
3435 self.consistencygroups_adm_client = (
3536 consistencygroups_client.ConsistencyGroupsClient(auth_provider,
3637 **params))
38 self.volume_revet_client = (
39 volume_revert_client.VolumeRevertClient(auth_provider, **params))
0 # Copyright (C) 2017 Huawei.
1 # All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 from oslo_serialization import jsonutils as json
16 from tempest.lib.common import rest_client
17 from tempest.lib.services.volume.v3 import base_client
18
19
20 class VolumeRevertClient(base_client.BaseClient):
21 """Client class to send revert to snapshot action API request"""
22
23 def __init__(self, auth_provider, service, region, **kwargs):
24 super(VolumeRevertClient, self).__init__(
25 auth_provider, service, region, **kwargs)
26
27 def revert_to_snapshot(self, volume, snapshot_id):
28 """Revert a volume to snapshot."""
29 post_body = {'snapshot_id': snapshot_id}
30 post_body = json.dumps({'revert': post_body})
31 resp, body = self.post('volumes/%s/action' % volume['id'],
32 post_body)
33 return rest_client.ResponseBody(resp, body)