Fix share manage tempest test cleanup

test_share_manage.ManageNFSShareTest might leave undeleted shares on
backend if some tests are not run. This happens because the shares are
created and unmanaged on resource_setup and are expected to be managed
and deleted on the tests. If the tests don't run, the cleanup will not
delete the shares because they are already unmanaged, thus leaving them
created on the backend.

This patch fixes this issue by moving the share creation and unmanage
operations from resource_setup to the tests themselves.

Closes-bug: #1639848

Change-Id: I2d1790f0a323fdc7b11805842985ca5907dd23c3
This commit is contained in:
tpsilva 2016-11-07 10:03:39 -02:00
parent 5dfeebb536
commit 1eadb5a51c

View File

@ -72,42 +72,26 @@ class ManageNFSShareTest(base.BaseSharesAdminTest):
cleanup_in_class=True, cleanup_in_class=True,
extra_specs=cls.extra_specs_invalid) extra_specs=cls.extra_specs_invalid)
creation_data = {'kwargs': { def _test_manage(self, is_public=False,
'share_type_id': cls.st['share_type']['id'], version=CONF.share.max_api_microversion,
'share_protocol': cls.protocol, check_manage=False):
}}
# Data for creating shares in parallel share = self._create_share_for_manage()
data = [creation_data, creation_data]
if utils.is_microversion_ge(CONF.share.max_api_microversion, "2.5"):
data.append(creation_data)
if utils.is_microversion_ge(CONF.share.max_api_microversion, "2.8"):
data.append(creation_data)
if utils.is_microversion_ge(CONF.share.max_api_microversion, "2.16"):
data.append(creation_data)
shares_created = cls.create_shares(data)
cls.shares = []
# Load all share data (host, etc.)
for share in shares_created:
# Unmanage shares from manila
get_share = cls.shares_v2_client.get_share(share['id'])
if utils.is_microversion_ge(
CONF.share.max_api_microversion, "2.9"):
get_share["export_locations"] = (
cls.shares_v2_client.list_share_export_locations(
share["id"])
)
cls.shares.append(get_share)
cls.shares_client.unmanage_share(share['id'])
cls.shares_client.wait_for_resource_deletion(
share_id=share['id'])
def _test_manage(self, share, is_public=False,
version=CONF.share.max_api_microversion):
name = "Name for 'managed' share that had ID %s" % share['id'] name = "Name for 'managed' share that had ID %s" % share['id']
description = "Description for 'managed' share" description = "Description for 'managed' share"
# Unmanage share
self._unmanage_share_and_wait(share)
if check_manage:
# After 'unmanage' operation, share instance should be deleted.
# Assert not related to 'manage' test, but placed here for
# resource optimization.
share_instance_list = self.shares_v2_client.list_share_instances()
share_ids = [si['share_id'] for si in share_instance_list]
self.assertNotIn(share['id'], share_ids)
# Manage share # Manage share
managed_share = self.shares_v2_client.manage_share( managed_share = self.shares_v2_client.manage_share(
service_host=share['host'], service_host=share['host'],
@ -160,31 +144,43 @@ class ManageNFSShareTest(base.BaseSharesAdminTest):
self.shares_v2_client.get_share, self.shares_v2_client.get_share,
managed_share['id']) managed_share['id'])
def _create_share_for_manage(self):
creation_data = {
'share_type_id': self.st['share_type']['id'],
'share_protocol': self.protocol,
}
share = self.create_share(**creation_data)
share = self.shares_v2_client.get_share(share['id'])
if utils.is_microversion_ge(CONF.share.max_api_microversion, "2.9"):
el = self.shares_v2_client.list_share_export_locations(share["id"])
share["export_locations"] = el
return share
def _unmanage_share_and_wait(self, share):
self.shares_v2_client.unmanage_share(share['id'])
self.shares_v2_client.wait_for_resource_deletion(share_id=share['id'])
@tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND) @tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND)
@base.skip_if_microversion_not_supported("2.5") @base.skip_if_microversion_not_supported("2.5")
def test_manage_with_os_share_manage_url(self): def test_manage_with_os_share_manage_url(self):
self._test_manage(share=self.shares[2], version="2.5") self._test_manage(version="2.5")
@tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND) @tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND)
@base.skip_if_microversion_not_supported("2.8") @base.skip_if_microversion_not_supported("2.8")
def test_manage_with_is_public_True(self): def test_manage_with_is_public_True(self):
self._test_manage(share=self.shares[3], is_public=True, version="2.8") self._test_manage(is_public=True, version="2.8")
@tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND) @tc.attr(base.TAG_POSITIVE, base.TAG_API_WITH_BACKEND)
@base.skip_if_microversion_not_supported("2.16") @base.skip_if_microversion_not_supported("2.16")
def test_manage_show_user_id(self): def test_manage_show_user_id(self):
self._test_manage(share=self.shares[4], version="2.16") self._test_manage(version="2.16")
@tc.attr(base.TAG_POSITIVE, base.TAG_BACKEND) @tc.attr(base.TAG_POSITIVE, base.TAG_BACKEND)
def test_manage(self): def test_manage(self):
# After 'unmanage' operation, share instance should be deleted. self._test_manage(check_manage=True)
# Assert not related to 'manage' test, but placed here for
# resource optimization.
share_instance_list = self.shares_v2_client.list_share_instances()
share_ids = [si['share_id'] for si in share_instance_list]
self.assertNotIn(self.shares[0]['id'], share_ids)
self._test_manage(share=self.shares[0])
@tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND) @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND)
def test_manage_invalid(self): def test_manage_invalid(self):
@ -203,29 +199,33 @@ class ManageNFSShareTest(base.BaseSharesAdminTest):
self.shares_v2_client.get_share, self.shares_v2_client.get_share,
share_id) share_id)
share = self.shares_v2_client.manage_share( share = self._create_share_for_manage()
service_host=self.shares[1]['host'],
export_path=self.shares[1]['export_locations'][0], self._unmanage_share_and_wait(share)
protocol=self.shares[1]['share_proto'],
managed_share = self.shares_v2_client.manage_share(
service_host=share['host'],
export_path=share['export_locations'][0],
protocol=share['share_proto'],
share_type_id=self.st_invalid['share_type']['id']) share_type_id=self.st_invalid['share_type']['id'])
self.addCleanup(_delete_share, share['id']) self.addCleanup(_delete_share, managed_share['id'])
self.shares_v2_client.wait_for_share_status( self.shares_v2_client.wait_for_share_status(
share['id'], 'manage_error') managed_share['id'], 'manage_error')
share = self.shares_v2_client.get_share(share['id']) managed_share = self.shares_v2_client.get_share(managed_share['id'])
self.assertEqual(1, int(share['size'])) self.assertEqual(1, int(managed_share['size']))
# Delete resource from backend. We need to manage the share properly # Delete resource from backend. We need to manage the share properly
# so it can be removed. # so it can be removed.
share = self.shares_v2_client.manage_share( managed_share = self.shares_v2_client.manage_share(
service_host=self.shares[1]['host'], service_host=share['host'],
export_path=self.shares[1]['export_locations'][0], export_path=share['export_locations'][0],
protocol=self.shares[1]['share_proto'], protocol=share['share_proto'],
share_type_id=self.st['share_type']['id']) share_type_id=self.st['share_type']['id'])
self.addCleanup(_delete_share, share['id']) self.addCleanup(_delete_share, managed_share['id'])
self.shares_v2_client.wait_for_share_status( self.shares_v2_client.wait_for_share_status(
share['id'], 'available') managed_share['id'], 'available')
class ManageCIFSShareTest(ManageNFSShareTest): class ManageCIFSShareTest(ManageNFSShareTest):