Fix resource leaks in IdentityPolicyAssociationRbacTest class
The IdentityPolicyAssociationRbacTest,
IdentityEndpointsV3RbacTest and EndpointFilterProjectsV3RbacTest
test cases were leaking region resources on the endpoint create
and just using tempest- in the region description.
The following changes to fix the leaks and make them easier to
find in the future, if they happen.
1) move setup_test_endpoint to the v3 class to have access to the
region client and get the region id created when the endpoint
created so I can add it to the resource clean-up.
2) add a rand_name for the region id not just the description
so we know that tempest- created it.
Change-Id: I3bd5bf02ef6d434ccba65a5a732e550b007a2309
diff --git a/patrole_tempest_plugin/tests/api/identity/rbac_base.py b/patrole_tempest_plugin/tests/api/identity/rbac_base.py
index e3fac27..6e76a72 100644
--- a/patrole_tempest_plugin/tests/api/identity/rbac_base.py
+++ b/patrole_tempest_plugin/tests/api/identity/rbac_base.py
@@ -28,30 +28,6 @@
base.BaseIdentityTest):
@classmethod
- def setup_test_endpoint(cls, service=None):
- """Creates a service and an endpoint for test."""
- interface = 'public'
- url = data_utils.rand_url()
- region_name = data_utils.rand_name(
- cls.__name__ + '-region')
- # Endpoint creation requires a service
- if service is None:
- service = cls.setup_test_service()
- params = {
- 'service_id': service['id'],
- 'region': region_name,
- 'interface': interface,
- 'url': url
- }
-
- endpoint = cls.endpoints_client.create_endpoint(**params)['endpoint']
- cls.addClassResourceCleanup(
- test_utils.call_and_ignore_notfound_exc,
- cls.endpoints_client.delete_endpoint, endpoint['id'])
-
- return endpoint
-
- @classmethod
def setup_test_role(cls):
"""Set up a test role."""
name = data_utils.rand_name(cls.__name__ + '-test_role')
@@ -182,6 +158,33 @@
super(BaseIdentityV3RbacTest, cls).resource_cleanup()
@classmethod
+ def setup_test_endpoint(cls, service=None):
+ """Creates a service and an endpoint for test."""
+ interface = 'public'
+ url = data_utils.rand_url()
+ region_name = data_utils.rand_name(
+ cls.__name__ + '-region')
+ # Endpoint creation requires a service
+ if service is None:
+ service = cls.setup_test_service()
+ params = {
+ 'service_id': service['id'],
+ 'region': region_name,
+ 'interface': interface,
+ 'url': url
+ }
+
+ endpoint = cls.endpoints_client.create_endpoint(**params)['endpoint']
+ cls.addClassResourceCleanup(
+ test_utils.call_and_ignore_notfound_exc,
+ cls.regions_client.delete_region, endpoint['region'])
+ cls.addClassResourceCleanup(
+ test_utils.call_and_ignore_notfound_exc,
+ cls.endpoints_client.delete_endpoint, endpoint['id'])
+
+ return endpoint
+
+ @classmethod
def setup_test_credential(cls, user=None):
"""Creates a credential for test."""
keys = [data_utils.rand_uuid_hex(),
@@ -249,8 +252,10 @@
"""Creates a region for test."""
description = data_utils.rand_name(
cls.__name__ + '-test_region_desc')
+ id = data_utils.rand_name(cls.__name__)
region = cls.regions_client.create_region(
+ id=id,
description=description)['region']
cls.regions.append(region)