Fix for unmanage and manage snapshot

The test for unmanage and manage snapshot in Tempest is only available
for the LVM driver now. This patch aims to make the test more generic,
and fit for more storage backend drivers.

Change-Id: I6a1c0c391ad3b6ac1cf15e440267eec61f42f845
This commit is contained in:
jeremy.zhang 2017-06-14 13:58:37 +08:00
parent 5aad8e753a
commit ebc752b59d
3 changed files with 43 additions and 22 deletions

View File

@ -0,0 +1,7 @@
---
features:
- |
A new config option 'manage_snapshot_ref' is added in the volume section,
to specify snapshot ref parameter for different storage backend drivers
when managing an existing snapshot. By default it is set to fit the LVM
driver.

View File

@ -13,8 +13,6 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import testtools
from tempest.api.volume import base from tempest.api.volume import base
from tempest.common import waiters from tempest.common import waiters
from tempest import config from tempest import config
@ -32,9 +30,18 @@ class SnapshotManageAdminTest(base.BaseVolumeAdminTest):
managed by Cinder from a storage back end to Cinder managed by Cinder from a storage back end to Cinder
""" """
@classmethod
def skip_checks(cls):
super(SnapshotManageAdminTest, cls).skip_checks()
if not CONF.volume_feature_enabled.manage_snapshot:
raise cls.skipException("Manage snapshot tests are disabled")
if len(CONF.volume.manage_snapshot_ref) != 2:
raise cls.skipException("Manage snapshot ref is not correctly "
"configured")
@decorators.idempotent_id('0132f42d-0147-4b45-8501-cc504bbf7810') @decorators.idempotent_id('0132f42d-0147-4b45-8501-cc504bbf7810')
@testtools.skipUnless(CONF.volume_feature_enabled.manage_snapshot,
"Manage snapshot tests are disabled")
def test_unmanage_manage_snapshot(self): def test_unmanage_manage_snapshot(self):
# Create a volume # Create a volume
volume = self.create_volume() volume = self.create_volume()
@ -48,15 +55,13 @@ class SnapshotManageAdminTest(base.BaseVolumeAdminTest):
self.admin_snapshots_client.unmanage_snapshot(snapshot['id']) self.admin_snapshots_client.unmanage_snapshot(snapshot['id'])
self.admin_snapshots_client.wait_for_resource_deletion(snapshot['id']) self.admin_snapshots_client.wait_for_resource_deletion(snapshot['id'])
# Fetch snapshot ids # Verify the original snapshot does not exist in snapshot list
snapshot_list = [ params = {'all_tenants': 1}
snap['id'] for snap in all_snapshots = self.admin_snapshots_client.list_snapshots(
self.snapshots_client.list_snapshots()['snapshots'] detail=True, params=params)['snapshots']
] self.assertNotIn(snapshot['id'], [v['id'] for v in all_snapshots])
# Verify snapshot does not exist in snapshot list
self.assertNotIn(snapshot['id'], snapshot_list)
# Manage the snapshot
name = data_utils.rand_name(self.__class__.__name__ + name = data_utils.rand_name(self.__class__.__name__ +
'-Managed-Snapshot') '-Managed-Snapshot')
description = data_utils.rand_name(self.__class__.__name__ + description = data_utils.rand_name(self.__class__.__name__ +
@ -64,12 +69,16 @@ class SnapshotManageAdminTest(base.BaseVolumeAdminTest):
metadata = {"manage-snap-meta1": "value1", metadata = {"manage-snap-meta1": "value1",
"manage-snap-meta2": "value2", "manage-snap-meta2": "value2",
"manage-snap-meta3": "value3"} "manage-snap-meta3": "value3"}
snapshot_ref = {
# Manage the snapshot 'volume_id': volume['id'],
snapshot_ref = '_snapshot-%s' % snapshot['id'] 'ref': {CONF.volume.manage_snapshot_ref[0]:
CONF.volume.manage_snapshot_ref[1] % snapshot['id']},
'name': name,
'description': description,
'metadata': metadata
}
new_snapshot = self.admin_snapshot_manage_client.manage_snapshot( new_snapshot = self.admin_snapshot_manage_client.manage_snapshot(
volume_id=volume['id'], ref={'source-name': snapshot_ref}, **snapshot_ref)['snapshot']
name=name, description=description, metadata=metadata)['snapshot']
self.addCleanup(self.delete_snapshot, new_snapshot['id'], self.addCleanup(self.delete_snapshot, new_snapshot['id'],
self.admin_snapshots_client) self.admin_snapshots_client)
@ -80,9 +89,8 @@ class SnapshotManageAdminTest(base.BaseVolumeAdminTest):
# Verify the managed snapshot has the expected parent volume # Verify the managed snapshot has the expected parent volume
# and the expected field values. # and the expected field values.
new_snap_info = self.admin_snapshots_client.show_snapshot( new_snapshot_info = self.admin_snapshots_client.show_snapshot(
new_snapshot['id'])['snapshot'] new_snapshot['id'])['snapshot']
self.assertEqual(volume['id'], new_snap_info['volume_id']) self.assertEqual(snapshot['size'], new_snapshot_info['size'])
self.assertEqual(name, new_snap_info['name']) for key in ['volume_id', 'name', 'description', 'metadata']:
self.assertEqual(description, new_snap_info['description']) self.assertEqual(snapshot_ref[key], new_snapshot_info[key])
self.assertEqual(metadata, new_snap_info['metadata'])

View File

@ -768,6 +768,12 @@ VolumeGroup = [
"It contains two elements, the first is ref type " "It contains two elements, the first is ref type "
"(like 'source-name', 'source-id', etc), the second is " "(like 'source-name', 'source-id', etc), the second is "
"volume name template used in storage backend"), "volume name template used in storage backend"),
cfg.ListOpt('manage_snapshot_ref',
default=['source-name', '_snapshot-%s'],
help="A reference to existing snapshot for snapshot manage. "
"It contains two elements, the first is ref type "
"(like 'source-name', 'source-id', etc), the second is "
"snapshot name template used in storage backend"),
cfg.StrOpt('min_microversion', cfg.StrOpt('min_microversion',
default=None, default=None,
help="Lower version of the test target microversion range. " help="Lower version of the test target microversion range. "