From 1eadb5a51cd67610fab9bc5a82b2e6cbd1cbd12c Mon Sep 17 00:00:00 2001 From: tpsilva Date: Mon, 7 Nov 2016 10:03:39 -0200 Subject: [PATCH] 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 --- .../tests/api/admin/test_share_manage.py | 112 +++++++++--------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/manila_tempest_tests/tests/api/admin/test_share_manage.py b/manila_tempest_tests/tests/api/admin/test_share_manage.py index b8577bc41c..810004039a 100644 --- a/manila_tempest_tests/tests/api/admin/test_share_manage.py +++ b/manila_tempest_tests/tests/api/admin/test_share_manage.py @@ -72,42 +72,26 @@ class ManageNFSShareTest(base.BaseSharesAdminTest): cleanup_in_class=True, extra_specs=cls.extra_specs_invalid) - creation_data = {'kwargs': { - 'share_type_id': cls.st['share_type']['id'], - 'share_protocol': cls.protocol, - }} + def _test_manage(self, is_public=False, + version=CONF.share.max_api_microversion, + check_manage=False): - # Data for creating shares in parallel - 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) + share = self._create_share_for_manage() - 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'] 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 managed_share = self.shares_v2_client.manage_share( service_host=share['host'], @@ -160,31 +144,43 @@ class ManageNFSShareTest(base.BaseSharesAdminTest): self.shares_v2_client.get_share, 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) @base.skip_if_microversion_not_supported("2.5") 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) @base.skip_if_microversion_not_supported("2.8") 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) @base.skip_if_microversion_not_supported("2.16") 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) def test_manage(self): - # 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(self.shares[0]['id'], share_ids) - - self._test_manage(share=self.shares[0]) + self._test_manage(check_manage=True) @tc.attr(base.TAG_NEGATIVE, base.TAG_API_WITH_BACKEND) def test_manage_invalid(self): @@ -203,29 +199,33 @@ class ManageNFSShareTest(base.BaseSharesAdminTest): self.shares_v2_client.get_share, share_id) - share = self.shares_v2_client.manage_share( - service_host=self.shares[1]['host'], - export_path=self.shares[1]['export_locations'][0], - protocol=self.shares[1]['share_proto'], + share = self._create_share_for_manage() + + self._unmanage_share_and_wait(share) + + 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']) - self.addCleanup(_delete_share, share['id']) + self.addCleanup(_delete_share, managed_share['id']) self.shares_v2_client.wait_for_share_status( - share['id'], 'manage_error') - share = self.shares_v2_client.get_share(share['id']) - self.assertEqual(1, int(share['size'])) + managed_share['id'], 'manage_error') + managed_share = self.shares_v2_client.get_share(managed_share['id']) + self.assertEqual(1, int(managed_share['size'])) # Delete resource from backend. We need to manage the share properly # so it can be removed. - share = self.shares_v2_client.manage_share( - service_host=self.shares[1]['host'], - export_path=self.shares[1]['export_locations'][0], - 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['share_type']['id']) - self.addCleanup(_delete_share, share['id']) + self.addCleanup(_delete_share, managed_share['id']) self.shares_v2_client.wait_for_share_status( - share['id'], 'available') + managed_share['id'], 'available') class ManageCIFSShareTest(ManageNFSShareTest):