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