Tempest for revert-to-snapshot

Added tempest testcases for revert-to-snapshot feature.

Depends-On: 16518c3b293561a2e9f4fa42a5247345ebd1e2b3
Change-Id: I97a9241ce53b144c30bc16d65dc8cf6e3f679743
This commit is contained in:
TommyLike 2017-05-10 10:13:23 +08:00
parent f5b4f473cb
commit 589ca69a20
3 changed files with 114 additions and 0 deletions

View File

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

View File

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

View File

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