Improve Tempest tests for consistency groups

Resource setup for 'ConsistencyGroupActionsTest' test class is
inefficient. It creates three separate shares waiting for 'available'
status going one by one. It can be improved by creating three shares
at once and then waiting for their status. So, update resource setup
for mentioned class and do related minor updates for tests of that
class.

Change-Id: Ibd82796866851cba22b417fad34f41dc2aa756e8
Closes-Bug: #1493406
This commit is contained in:
Valeriy Ponomaryov 2015-11-18 19:17:46 +02:00
parent f15e0bf123
commit 429bd1fec6
2 changed files with 56 additions and 99 deletions

View File

@ -70,31 +70,16 @@ class ConsistencyGroupActionsTest(base.BaseSharesAdminTest):
def test_create_cg_from_multi_typed_populated_cgsnapshot_v2_4(self): def test_create_cg_from_multi_typed_populated_cgsnapshot_v2_4(self):
share_name = data_utils.rand_name("tempest-share-name") share_name = data_utils.rand_name("tempest-share-name")
share_desc = data_utils.rand_name("tempest-share-description") share_desc = data_utils.rand_name("tempest-share-description")
share_size = 1
share = self.create_share(
cleanup_in_class=False,
name=share_name,
description=share_desc,
size=share_size,
consistency_group_id=self.consistency_group['id'],
share_type_id=self.share_type['id'],
client=self.shares_v2_client,
version='2.4',
)
share_name2 = data_utils.rand_name("tempest-share-name") shares = self.create_shares([
share_desc2 = data_utils.rand_name("tempest-share-description") {'kwargs': {
share_size2 = 1 'cleanup_in_class': False,
share2 = self.create_share( 'name': share_name,
cleanup_in_class=False, 'description': share_desc,
name=share_name2, 'consistency_group_id': self.consistency_group['id'],
description=share_desc2, 'share_type_id': st_id,
size=share_size2, }} for st_id in (self.share_type['id'], self.share_type2['id'])
consistency_group_id=self.consistency_group['id'], ])
share_type_id=self.share_type2['id'],
client=self.shares_v2_client,
version='2.4',
)
cg_shares = self.shares_v2_client.list_shares( cg_shares = self.shares_v2_client.list_shares(
detailed=True, detailed=True,
@ -103,7 +88,7 @@ class ConsistencyGroupActionsTest(base.BaseSharesAdminTest):
) )
cg_share_ids = [s['id'] for s in cg_shares] cg_share_ids = [s['id'] for s in cg_shares]
for share_id in [share['id'], share2['id']]: for share_id in (shares[0]['id'], shares[1]['id']):
self.assertIn(share_id, cg_share_ids, 'Share %s not in ' self.assertIn(share_id, cg_share_ids, 'Share %s not in '
'consistency group %s.' % 'consistency group %s.' %
(share_id, self.consistency_group['id'])) (share_id, self.consistency_group['id']))

View File

@ -39,78 +39,52 @@ class ConsistencyGroupActionsTest(base.BaseSharesTest):
@classmethod @classmethod
def resource_setup(cls): def resource_setup(cls):
super(ConsistencyGroupActionsTest, cls).resource_setup() super(ConsistencyGroupActionsTest, cls).resource_setup()
# Create consistency group
# Create first consistency group
cls.cg_name = data_utils.rand_name("tempest-cg-name") cls.cg_name = data_utils.rand_name("tempest-cg-name")
cls.cg_desc = data_utils.rand_name("tempest-cg-description") cls.cg_desc = data_utils.rand_name("tempest-cg-description")
cls.consistency_group = cls.create_consistency_group( cls.cg = cls.create_consistency_group(
name=cls.cg_name, name=cls.cg_name, description=cls.cg_desc)
description=cls.cg_desc,
)
# Create 2 shares inside consistency group
cls.share_name = data_utils.rand_name("tempest-share-name")
cls.share_desc = data_utils.rand_name("tempest-share-description")
cls.share_size = 1
cls.share = cls.create_share(
name=cls.share_name,
description=cls.share_desc,
size=cls.share_size,
consistency_group_id=cls.consistency_group['id'],
metadata={'key': 'value'},
client=cls.shares_v2_client,
)
cls.share_name2 = data_utils.rand_name("tempest-share-name")
cls.share_desc2 = data_utils.rand_name("tempest-share-description")
cls.share_size2 = 2
cls.share2 = cls.create_share(
name=cls.share_name2,
description=cls.share_desc2,
size=cls.share_size2,
consistency_group_id=cls.consistency_group['id'],
client=cls.shares_v2_client,
)
cls.cgsnap_name = data_utils.rand_name("tempest-cgsnap-name")
cls.cgsnap_desc = data_utils.rand_name("tempest-cgsnap-description")
cls.cgsnapshot = cls.create_cgsnapshot_wait_for_active(
cls.consistency_group["id"],
name=cls.cgsnap_name,
description=cls.cgsnap_desc)
# Create second consistency group for purposes of sorting and snapshot # Create second consistency group for purposes of sorting and snapshot
# filtering # filtering
cls.cg_name2 = data_utils.rand_name("tempest-cg-name") cls.cg2 = cls.create_consistency_group(
cls.cg_desc2 = data_utils.rand_name("tempest-cg-description") name=cls.cg_name, description=cls.cg_desc)
cls.consistency_group2 = cls.create_consistency_group(
name=cls.cg_name2,
description=cls.cg_desc2,
)
# Create 1 share in second consistency group # Create 2 shares inside first CG and 1 inside second CG
cls.share_name3 = data_utils.rand_name("tempest-share-name") cls.share_name = data_utils.rand_name("tempest-share-name")
cls.share_desc3 = data_utils.rand_name("tempest-share-description") cls.share_desc = data_utils.rand_name("tempest-share-description")
cls.share3 = cls.create_share( cls.share_size = 1
name=cls.share_name3, cls.share_size2 = 2
description=cls.share_desc3, cls.shares = cls.create_shares([
size=cls.share_size, {'kwargs': {
consistency_group_id=cls.consistency_group2['id'], 'name': cls.share_name,
client=cls.shares_v2_client, 'description': cls.share_desc,
) 'size': size,
'consistency_group_id': cg_id,
}} for size, cg_id in ((cls.share_size, cls.cg['id']),
(cls.share_size2, cls.cg['id']),
(cls.share_size, cls.cg2['id']))
])
# Create CG snapshots
cls.cgsnap_name = data_utils.rand_name("tempest-cgsnap-name")
cls.cgsnap_desc = data_utils.rand_name("tempest-cgsnap-description")
cls.cgsnapshot = cls.create_cgsnapshot_wait_for_active(
cls.cg["id"],
name=cls.cgsnap_name,
description=cls.cgsnap_desc)
cls.cgsnap_name2 = data_utils.rand_name("tempest-cgsnap-name")
cls.cgsnap_desc2 = data_utils.rand_name("tempest-cgsnap-description")
cls.cgsnapshot2 = cls.create_cgsnapshot_wait_for_active( cls.cgsnapshot2 = cls.create_cgsnapshot_wait_for_active(
cls.consistency_group2['id'], cls.cg2['id'], name=cls.cgsnap_name, description=cls.cgsnap_desc)
name=cls.cgsnap_name2,
description=cls.cgsnap_desc2)
@test.attr(type=["gate", ]) @test.attr(type=["gate", ])
def test_get_consistency_group_v2_4(self): def test_get_consistency_group_v2_4(self):
# Get consistency group # Get consistency group
consistency_group = self.shares_v2_client.get_consistency_group( consistency_group = self.shares_v2_client.get_consistency_group(
self.consistency_group['id'], version='2.4') self.cg['id'], version='2.4')
# Verify keys # Verify keys
actual_keys = set(consistency_group.keys()) actual_keys = set(consistency_group.keys())
@ -135,7 +109,7 @@ class ConsistencyGroupActionsTest(base.BaseSharesTest):
def test_get_share_v2_4(self): def test_get_share_v2_4(self):
# Get share # Get share
share = self.shares_v2_client.get_share(self.share['id'], share = self.shares_v2_client.get_share(self.shares[0]['id'],
version='2.4') version='2.4')
# Verify keys # Verify keys
@ -164,9 +138,8 @@ class ConsistencyGroupActionsTest(base.BaseSharesTest):
self.assertEqual(self.share_size, int(share["size"]), msg) self.assertEqual(self.share_size, int(share["size"]), msg)
msg = "Expected consistency_group_id: '%s', actual value: '%s'" % ( msg = "Expected consistency_group_id: '%s', actual value: '%s'" % (
self.consistency_group["id"], share["consistency_group_id"]) self.cg["id"], share["consistency_group_id"])
self.assertEqual( self.assertEqual(self.cg["id"], share["consistency_group_id"], msg)
self.consistency_group["id"], share["consistency_group_id"], msg)
@test.attr(type=["gate", ]) @test.attr(type=["gate", ])
def test_list_consistency_groups_v2_4(self): def test_list_consistency_groups_v2_4(self):
@ -180,8 +153,7 @@ class ConsistencyGroupActionsTest(base.BaseSharesTest):
consistency_groups] consistency_groups]
# Consistency group ids are in list exactly once # Consistency group ids are in list exactly once
for cg_id in [self.consistency_group["id"], for cg_id in (self.cg["id"], self.cg2["id"]):
self.consistency_group2["id"]]:
gen = [cgid["id"] for cgid in consistency_groups gen = [cgid["id"] for cgid in consistency_groups
if cgid["id"] == cg_id] if cgid["id"] == cg_id]
msg = ("Expected id %s exactly once in consistency group list" % msg = ("Expected id %s exactly once in consistency group list" %
@ -200,8 +172,7 @@ class ConsistencyGroupActionsTest(base.BaseSharesTest):
for cg in consistency_groups] for cg in consistency_groups]
# Consistency group ids are in list exactly once # Consistency group ids are in list exactly once
for cg_id in [self.consistency_group["id"], for cg_id in (self.cg["id"], self.cg2["id"]):
self.consistency_group2["id"]]:
gen = [cgid["id"] for cgid in consistency_groups gen = [cgid["id"] for cgid in consistency_groups
if cgid["id"] == cg_id] if cgid["id"] == cg_id]
msg = ("Expected id %s exactly once in consistency group list" % msg = ("Expected id %s exactly once in consistency group list" %
@ -213,7 +184,7 @@ class ConsistencyGroupActionsTest(base.BaseSharesTest):
shares = self.shares_v2_client.list_shares( shares = self.shares_v2_client.list_shares(
detailed=True, detailed=True,
params={'consistency_group_id': self.consistency_group['id']}, params={'consistency_group_id': self.cg['id']},
version='2.4' version='2.4'
) )
@ -222,18 +193,19 @@ class ConsistencyGroupActionsTest(base.BaseSharesTest):
self.assertEqual(2, len(shares), self.assertEqual(2, len(shares),
'Incorrect number of shares returned. Expected 2, ' 'Incorrect number of shares returned. Expected 2, '
'got %s' % len(shares)) 'got %s' % len(shares))
self.assertIn(self.share['id'], share_ids, self.assertIn(self.shares[0]['id'], share_ids,
'Share %s expected in returned list, but got %s' 'Share %s expected in returned list, but got %s'
% (self.share['id'], share_ids)) % (self.shares[0]['id'], share_ids))
self.assertIn(self.share2['id'], share_ids, self.assertIn(self.shares[1]['id'], share_ids,
'Share %s expected in returned list, but got %s' 'Share %s expected in returned list, but got %s'
% (self.share['id'], share_ids)) % (self.shares[0]['id'], share_ids))
@test.attr(type=["gate", ]) @test.attr(type=["gate", ])
def test_get_cgsnapshot_v2_4(self): def test_get_cgsnapshot_v2_4(self):
# Get consistency group # Get consistency group
consistency_group = self.shares_v2_client.get_consistency_group( consistency_group = self.shares_v2_client.get_consistency_group(
self.consistency_group['id'], version='2.4') self.cg['id'], version='2.4')
# Verify keys # Verify keys
actual_keys = set(consistency_group.keys()) actual_keys = set(consistency_group.keys())
@ -265,11 +237,11 @@ class ConsistencyGroupActionsTest(base.BaseSharesTest):
'Unexpected number of cgsnapshot members. Expected ' 'Unexpected number of cgsnapshot members. Expected '
'2, got %s.' % len(cgsnapshot_members)) '2, got %s.' % len(cgsnapshot_members))
# Verify each share is represented in the cgsnapshot appropriately # Verify each share is represented in the cgsnapshot appropriately
for share_id in [self.share['id'], self.share2['id']]: for share_id in (self.shares[0]['id'], self.shares[1]['id']):
self.assertIn(share_id, member_share_ids, self.assertIn(share_id, member_share_ids,
'Share missing %s missing from cgsnapshot. Found %s.' 'Share missing %s missing from cgsnapshot. Found %s.'
% (share_id, member_share_ids)) % (share_id, member_share_ids))
for share in [self.share, self.share2]: for share in (self.shares[0], self.shares[1]):
for member in cgsnapshot_members: for member in cgsnapshot_members:
if share['id'] == member['share_id']: if share['id'] == member['share_id']:
self.assertEqual(share['size'], member['size']) self.assertEqual(share['size'], member['size'])