diff --git a/testsuite/tests/apicast/parameters/apicast_path_routing/conftest.py b/testsuite/tests/apicast/parameters/apicast_path_routing/conftest.py index 01cb18b4f..cc117536b 100644 --- a/testsuite/tests/apicast/parameters/apicast_path_routing/conftest.py +++ b/testsuite/tests/apicast/parameters/apicast_path_routing/conftest.py @@ -78,7 +78,9 @@ def service2(request, custom_service, lifecycle_hooks, backends_mapping2, servic proxy.mapping_rules.create(rawobj.Mapping(metric, service2_mapping)) proxy.update() - return service2 + yield service2 + for usage in service2.backend_usages.list(): + usage.delete() @pytest.fixture(scope="module") diff --git a/testsuite/tests/apicast/parameters/apicast_path_routing/test_apicast_path_routing_query.py b/testsuite/tests/apicast/parameters/apicast_path_routing/test_apicast_path_routing_query.py index e6786f819..acf2ae04e 100644 --- a/testsuite/tests/apicast/parameters/apicast_path_routing/test_apicast_path_routing_query.py +++ b/testsuite/tests/apicast/parameters/apicast_path_routing/test_apicast_path_routing_query.py @@ -40,7 +40,9 @@ def service2(service2): proxy.mapping_rules.create(rawobj.Mapping(metric, pattern="/anything/foo?baz={baz}", http_method="GET")) proxy.deploy() - return service2 + yield service2 + for usage in service2.backend_usages.list(): + usage.delete() def test_args(client2): diff --git a/testsuite/tests/apicast/parameters/test_apicast_service.py b/testsuite/tests/apicast/parameters/test_apicast_service.py index 5e2c1d550..5abb11e7f 100644 --- a/testsuite/tests/apicast/parameters/test_apicast_service.py +++ b/testsuite/tests/apicast/parameters/test_apicast_service.py @@ -17,9 +17,12 @@ @pytest.fixture(scope="module") def service_pass(request, service_proxy_settings, custom_service, lifecycle_hooks, backends_mapping): """Create custom service that should pass upon request""" - return custom_service( + service = custom_service( {"name": blame(request, "svc")}, service_proxy_settings, backends_mapping, hooks=lifecycle_hooks ) + yield service + for usage in service.backend_usages.list(): + usage.delete() @pytest.fixture(scope="module") @@ -38,9 +41,12 @@ def api_client_pass(application_pass, api_client): @pytest.fixture(scope="module") def service_fail(request, service_proxy_settings, custom_service, lifecycle_hooks, backends_mapping): """Create custom service that should fail upon request""" - return custom_service( + service = custom_service( {"name": blame(request, "svc")}, service_proxy_settings, backends_mapping, hooks=lifecycle_hooks ) + yield service + for usage in service.backend_usages.list(): + usage.delete() @pytest.fixture(scope="module") diff --git a/testsuite/tests/apicast/parameters/test_apicast_services_list.py b/testsuite/tests/apicast/parameters/test_apicast_services_list.py index dbc12f877..e8999508a 100644 --- a/testsuite/tests/apicast/parameters/test_apicast_services_list.py +++ b/testsuite/tests/apicast/parameters/test_apicast_services_list.py @@ -25,7 +25,9 @@ def listed_service(service_proxy_settings, custom_service, request, lifecycle_ho staging_gateway.environ["APICAST_SERVICES_LIST"] = service["id"] - return service + yield service + for usage in service.backend_usages.list(): + usage.delete() @pytest.fixture(scope="module") diff --git a/testsuite/tests/apicast/policy/custom_metric/test_custom_metric_policy_parametrized.py b/testsuite/tests/apicast/policy/custom_metric/test_custom_metric_policy_parametrized.py index 1c206a904..2fdec3281 100644 --- a/testsuite/tests/apicast/policy/custom_metric/test_custom_metric_policy_parametrized.py +++ b/testsuite/tests/apicast/policy/custom_metric/test_custom_metric_policy_parametrized.py @@ -52,7 +52,9 @@ def config(custom_service, case_data, request, backends_mapping, lifecycle_hooks proxy.policies.insert(0, policy_config) proxy.deploy() - return service, calls, metrics + yield service, calls, metrics + for usage in service.backend_usages.list(): + usage.delete() @pytest_cases.fixture diff --git a/testsuite/tests/apicast/policy/rate_limit/conftest.py b/testsuite/tests/apicast/policy/rate_limit/conftest.py index 263c0f71d..40c4ba79e 100644 --- a/testsuite/tests/apicast/policy/rate_limit/conftest.py +++ b/testsuite/tests/apicast/policy/rate_limit/conftest.py @@ -31,7 +31,9 @@ def service_plus(custom_service, service_proxy_settings, request, policy_setting svc.proxy.list().policies.append(policy_settings) elif policy_settings is not None: svc.proxy.list().policies.append(*policy_settings) - return svc + yield svc + for usage in svc.backend_usages.list(): + usage.delete() @pytest_cases.fixture diff --git a/testsuite/tests/apicast/policy/rate_limit/fixed_window/test_fixed_window_policy.py b/testsuite/tests/apicast/policy/rate_limit/fixed_window/test_fixed_window_policy.py index 00157bdad..01f65904c 100644 --- a/testsuite/tests/apicast/policy/rate_limit/fixed_window/test_fixed_window_policy.py +++ b/testsuite/tests/apicast/policy/rate_limit/fixed_window/test_fixed_window_policy.py @@ -34,7 +34,10 @@ @pytest_cases.fixture def service_plus2(service_proxy_settings, custom_service, request, backends_mapping): """Service configured with parametrized config""" - return custom_service({"name": blame(request, "svc")}, service_proxy_settings, backends_mapping) + service = custom_service({"name": blame(request, "svc")}, service_proxy_settings, backends_mapping) + yield service + for usage in service.backend_usages.list(): + usage.delete() @pytest_cases.fixture diff --git a/testsuite/tests/apicast/policy/rate_limit/leaky_bucket/test_leaky_bucket_policy.py b/testsuite/tests/apicast/policy/rate_limit/leaky_bucket/test_leaky_bucket_policy.py index ff820c1a0..720f01971 100644 --- a/testsuite/tests/apicast/policy/rate_limit/leaky_bucket/test_leaky_bucket_policy.py +++ b/testsuite/tests/apicast/policy/rate_limit/leaky_bucket/test_leaky_bucket_policy.py @@ -48,13 +48,19 @@ def setup_async_client(lifecycle_hooks): @pytest_cases.fixture def service(service_proxy_settings, custom_service, request, backends_mapping): """Service configured with config""" - return custom_service({"name": blame(request, "svc")}, service_proxy_settings, backends_mapping) + service = custom_service({"name": blame(request, "svc")}, service_proxy_settings, backends_mapping) + yield service + for usage in service.backend_usages.list(): + usage.delete() @pytest.fixture def service2(service_proxy_settings, custom_service, request, backends_mapping): """Service configured with parametrized config""" - return custom_service({"name": blame(request, "svc")}, service_proxy_settings, backends_mapping) + service = custom_service({"name": blame(request, "svc")}, service_proxy_settings, backends_mapping) + yield service + for usage in service.backend_usages.list(): + usage.delete() @pytest_cases.fixture diff --git a/testsuite/tests/apicast/policy/rate_limit_headers/test_rate_limit_headers.py b/testsuite/tests/apicast/policy/rate_limit_headers/test_rate_limit_headers.py index e8f7e0b17..275a8dd96 100644 --- a/testsuite/tests/apicast/policy/rate_limit_headers/test_rate_limit_headers.py +++ b/testsuite/tests/apicast/policy/rate_limit_headers/test_rate_limit_headers.py @@ -25,7 +25,7 @@ @pytest_cases.fixture -def service(custom_service, service_proxy_settings, request, lifecycle_hooks, backends_mapping): +def service2(custom_service, service_proxy_settings, request, lifecycle_hooks, backends_mapping): """ Function-scoped service with the rate limit headers policy The caching policy is added, so the reported numbers will be 100% accurate @@ -39,26 +39,28 @@ def service(custom_service, service_proxy_settings, request, lifecycle_hooks, ba proxy.policies.insert(0, rawobj.PolicyConfig("rate_limit_headers", {})) proxy.policies.insert(0, rawobj.PolicyConfig("caching", {"caching_type": "none"})) - return svc + yield svc + for usage in svc.backend_usages.list(): + usage.delete() @pytest_cases.fixture -def app_plan_backend(service, custom_app_plan, threescale, request): +def app_plan_backend(service2, backend_usages, custom_app_plan, threescale, request): """ Creates a mapped metric on a backend and on a service, so the default 'hits', that are interconnected are not used. Creates an app plan with a limits on those metric, one 'minute' and the other 'hour' scoped. """ - backend = threescale.backends.read(service.backend_usages.list()[0]["backend_id"]) + backend = threescale.backends.read(backend_usages[0]["backend_id"]) backend_metric = backend.metrics.list()[0] backend.mapping_rules.create(rawobj.Mapping(backend_metric, "/anything")) - service_metric = service.metrics.create(rawobj.Metric("metric_svc")) - proxy = service.proxy.list() + service_metric = service2.metrics.create(rawobj.Metric("metric_svc")) + proxy = service2.proxy.list() proxy.mapping_rules.create(rawobj.Mapping(service_metric, pattern="/anything/foo")) proxy.deploy() - plan = custom_app_plan(rawobj.ApplicationPlan(blame(request, "app")), service) + plan = custom_app_plan(rawobj.ApplicationPlan(blame(request, "app")), service2) plan.limits(backend_metric).create({"metric_id": backend_metric["id"], "period": "minute", "value": 10}) plan.limits(service_metric).create({"metric_id": service_metric["id"], "period": "minute", "value": 5}) @@ -66,7 +68,7 @@ def app_plan_backend(service, custom_app_plan, threescale, request): @pytest_cases.fixture -def app_plan_service(service, custom_app_plan, request): +def app_plan_service(service2, custom_app_plan, request): """ Creates metrics and mapping rules for those metrics. The second mapping rule is a subset of the first one. When the second (foo) metric is increased, @@ -74,15 +76,15 @@ def app_plan_service(service, custom_app_plan, request): Creates an app plan with two limits on the created metrics. """ - metric_anything = service.metrics.create(rawobj.Metric("anything")) - metric_anything_foo = service.metrics.create(rawobj.Metric("foo")) + metric_anything = service2.metrics.create(rawobj.Metric("anything")) + metric_anything_foo = service2.metrics.create(rawobj.Metric("foo")) - proxy = service.proxy.list() + proxy = service2.proxy.list() proxy.mapping_rules.create(rawobj.Mapping(metric_anything, pattern="/anything")) proxy.mapping_rules.create(rawobj.Mapping(metric_anything_foo, pattern="/anything/foo")) proxy.deploy() - plan = custom_app_plan(rawobj.ApplicationPlan(blame(request, "app")), service) + plan = custom_app_plan(rawobj.ApplicationPlan(blame(request, "app")), service2) plan.limits(metric_anything).create({"metric_id": metric_anything["id"], "period": "minute", "value": 10}) plan.limits(metric_anything_foo).create({"metric_id": metric_anything_foo["id"], "period": "minute", "value": 5}) diff --git a/testsuite/tests/conftest.py b/testsuite/tests/conftest.py index fb59cdfce..8dd5b06c7 100644 --- a/testsuite/tests/conftest.py +++ b/testsuite/tests/conftest.py @@ -11,13 +11,12 @@ from itertools import chain from typing import List -import backoff import importlib_resources as resources import openshift_client as oc import pytest from dynaconf.vendor.box.exceptions import BoxKeyError from pytest_metadata.plugin import metadata_key -from threescale_api import client, errors +from threescale_api import client from weakget import weakget # to actually initialize all the providers @@ -765,7 +764,10 @@ def httpx(): @pytest.fixture(scope="module") def service(backends_mapping, custom_service, service_settings, service_proxy_settings, lifecycle_hooks): "Preconfigured service with backend defined existing over whole testsing session" - return custom_service(service_settings, service_proxy_settings, backends_mapping, hooks=lifecycle_hooks) + service = custom_service(service_settings, service_proxy_settings, backends_mapping, hooks=lifecycle_hooks) + yield service + for usage in service.backend_usages.list(): + usage.delete() @pytest.fixture(scope="module") @@ -978,7 +980,8 @@ def finalizer(): hook(svc) except Exception: # pylint: disable=broad-except pass - + for usage in svc.backend_usages.list(): + usage.delete() svc.delete() with self._lock: @@ -1007,15 +1010,6 @@ def __call__(self, *args, **kwargs): return _CustomService() -@backoff.on_exception(backoff.fibo, errors.ApiClientError, max_tries=14, jitter=None) -def _backend_delete(backend): - """reliable backend delete""" - - for usage in backend.usages(): - usage.delete() - backend.delete() - - @pytest.fixture(scope="module") # pylint: disable=too-many-arguments def custom_backend(threescale, request, testconfig, private_base_url): @@ -1050,7 +1044,7 @@ def finalizer(): hook(backend) except Exception: # pylint: disable=broad-except pass - _backend_delete(backend) + backend.delete() request.addfinalizer(finalizer) diff --git a/testsuite/tests/ui/apiap/test_product.py b/testsuite/tests/ui/apiap/test_product.py index e7a6493a6..90dc6061b 100644 --- a/testsuite/tests/ui/apiap/test_product.py +++ b/testsuite/tests/ui/apiap/test_product.py @@ -24,7 +24,10 @@ def service(custom_service, custom_backend, private_base_url, lifecycle_hooks, r """Preconfigured service with backend defined existing over one test run""" name = {"name": blame(request, "svc")} backend = custom_backend("backend_default", endpoint=private_base_url("echo_api")) - return custom_service(name, backends={"/": backend}, hooks=lifecycle_hooks) + svc = custom_service(name, backends={"/": backend}, hooks=lifecycle_hooks) + yield svc + for usage in svc.backend_usages.list(): + usage.delete() @pytest.fixture(scope="function")