diff --git a/tests/suite/fixtures.py b/tests/suite/fixtures.py index 37e56e0ae5..8331262237 100644 --- a/tests/suite/fixtures.py +++ b/tests/suite/fixtures.py @@ -338,13 +338,13 @@ def virtual_server_setup(request, kube_apis, crd_ingress_controller, ingress_con test_namespace) vs_host = get_first_vs_host_from_yaml(vs_source) vs_paths = get_paths_from_vs_yaml(vs_source) - common_app = create_example_app(kube_apis, request.param['app_type'], test_namespace) + create_example_app(kube_apis, request.param['app_type'], test_namespace) wait_until_all_pods_are_ready(kube_apis.v1, test_namespace) def fin(): print("Clean up Virtual Server Example:") delete_virtual_server(kube_apis.custom_objects, vs_name, test_namespace) - delete_common_app(kube_apis.v1, kube_apis.apps_v1_api, common_app, test_namespace) + delete_common_app(kube_apis, request.param['app_type'], test_namespace) request.addfinalizer(fin) diff --git a/tests/suite/resources_utils.py b/tests/suite/resources_utils.py index 5e09a5c29d..fb2550f2f7 100644 --- a/tests/suite/resources_utils.py +++ b/tests/suite/resources_utils.py @@ -10,7 +10,6 @@ from kubernetes.stream import stream from kubernetes import client from settings import TEST_DATA, RECONFIGURATION_DELAY, DEPLOYMENTS -from suite.yaml_utils import get_names_from_yaml class RBACAuthorization: @@ -599,6 +598,24 @@ def replace_configmap(v1: CoreV1Api, name, namespace, body) -> None: print("ConfigMap replaced") +def delete_configmap(v1: CoreV1Api, name, namespace) -> None: + """ + Delete a ConfigMap. + + :param v1: CoreV1Api + :param name: ConfigMap name + :param namespace: namespace name + :return: + """ + print(f"Delete a ConfigMap: {name}") + delete_options = client.V1DeleteOptions() + delete_options.grace_period_seconds = 0 + delete_options.propagation_policy = 'Foreground' + v1.delete_namespaced_config_map(name, namespace, delete_options) + ensure_item_removal(v1.read_namespaced_config_map, name, namespace) + print(f"ConfigMap was removed with name '{name}'") + + def delete_namespace(v1: CoreV1Api, namespace) -> None: """ Delete a namespace. @@ -653,20 +670,7 @@ def get_ingress_nginx_template_conf(v1: CoreV1Api, ingress_namespace, ingress_na return get_file_contents(v1, file_path, pod_name, pod_namespace) -class CommonApp: - """ - Encapsulate Common Application details. - - Attributes: - services ([]): list of services names - deployments ([]): list of deployments names - """ - def __init__(self, services, deployments): - self.services = services - self.deployments = deployments - - -def create_example_app(kube_apis, app_type, namespace) -> CommonApp: +def create_example_app(kube_apis, app_type, namespace) -> None: """ Create a backend application. @@ -675,36 +679,21 @@ def create_example_app(kube_apis, app_type, namespace) -> CommonApp: :param kube_apis: client apis :param app_type: type of the application (simple|split) :param namespace: namespace name - :return: CommonApp + :return: """ create_items_from_yaml(kube_apis, f"{TEST_DATA}/common/app/{app_type}/app.yaml", namespace) - all_names = get_names_from_yaml(f"{TEST_DATA}/common/app/{app_type}/app.yaml") - service_names = [] - dep_names = [] - for _ in all_names: - if "svc" in _: - service_names.append(_) - else: - dep_names.append(_) - return CommonApp(service_names, dep_names) -def delete_common_app(v1: CoreV1Api, - apps_v1_api: AppsV1Api, - common_app: CommonApp, namespace) -> None: +def delete_common_app(kube_apis, app_type, namespace) -> None: """ Delete a common simple application. - :param v1: CoreV1Api - :param apps_v1_api: AppsV1Api - :param common_app: CommonApp + :param kube_apis: + :param app_type: :param namespace: namespace name :return: """ - for deployment in common_app.deployments: - delete_deployment(apps_v1_api, deployment, namespace) - for svc in common_app.services: - delete_service(v1, svc, namespace) + delete_items_from_yaml(kube_apis, f"{TEST_DATA}/common/app/{app_type}/app.yaml", namespace) def delete_service(v1: CoreV1Api, name, namespace) -> None: @@ -889,6 +878,8 @@ def delete_items_from_yaml(kube_apis, yaml_manifest, namespace) -> None: delete_deployment(kube_apis.apps_v1_api, doc['metadata']['name'], namespace) elif doc["kind"] == "DaemonSet": delete_daemon_set(kube_apis.apps_v1_api, doc['metadata']['name'], namespace) + elif doc["kind"] == "ConfigMap": + delete_configmap(kube_apis.v1, doc['metadata']['name'], namespace) def ensure_connection(request_url) -> None: diff --git a/tests/suite/test_annotations.py b/tests/suite/test_annotations.py index 5b9cee3530..c05cb4e0a4 100644 --- a/tests/suite/test_annotations.py +++ b/tests/suite/test_annotations.py @@ -78,7 +78,7 @@ def annotations_setup(request, test_namespace) ingress_name = get_names_from_yaml(f"{TEST_DATA}/annotations/{request.param}/annotations-ingress.yaml")[0] ingress_host = get_first_ingress_host_from_yaml(f"{TEST_DATA}/annotations/{request.param}/annotations-ingress.yaml") - common_app = create_example_app(kube_apis, "simple", test_namespace) + create_example_app(kube_apis, "simple", test_namespace) wait_until_all_pods_are_ready(kube_apis.v1, test_namespace) ensure_connection_to_public_endpoint(ingress_controller_endpoint.public_ip, ingress_controller_endpoint.port, @@ -97,7 +97,7 @@ def fin(): ingress_controller_prerequisites.config_map['metadata']['name'], ingress_controller_prerequisites.namespace, f"{DEPLOYMENTS}/common/nginx-config.yaml") - delete_common_app(kube_apis.v1, kube_apis.apps_v1_api, common_app, test_namespace) + delete_common_app(kube_apis, "simple", test_namespace) delete_items_from_yaml(kube_apis, f"{TEST_DATA}/annotations/{request.param}/annotations-ingress.yaml", test_namespace) diff --git a/tests/suite/test_jwt_auth_mergeable.py b/tests/suite/test_jwt_auth_mergeable.py index 707ea38c39..7afd1a24ae 100644 --- a/tests/suite/test_jwt_auth_mergeable.py +++ b/tests/suite/test_jwt_auth_mergeable.py @@ -39,7 +39,7 @@ def jwt_auth_setup(request, kube_apis, ingress_controller_endpoint, ingress_cont print("------------------------- Deploy JWT Auth Mergeable Minions Example -----------------------------------") create_items_from_yaml(kube_apis, f"{TEST_DATA}/jwt-auth-mergeable/mergeable/jwt-auth-ingress.yaml", test_namespace) ingress_host = get_first_ingress_host_from_yaml(f"{TEST_DATA}/jwt-auth-mergeable/mergeable/jwt-auth-ingress.yaml") - common_app = create_example_app(kube_apis, "simple", test_namespace) + create_example_app(kube_apis, "simple", test_namespace) wait_until_all_pods_are_ready(kube_apis.v1, test_namespace) ensure_connection_to_public_endpoint(ingress_controller_endpoint.public_ip, ingress_controller_endpoint.port, @@ -56,7 +56,7 @@ def fin(): delete_secret(kube_apis.v1, minion_secret_name, test_namespace) print("Clean up the JWT Auth Mergeable Minions Application:") - delete_common_app(kube_apis.v1, kube_apis.apps_v1_api, common_app, test_namespace) + delete_common_app(kube_apis, "simple", test_namespace) delete_items_from_yaml(kube_apis, f"{TEST_DATA}/jwt-auth-mergeable/mergeable/jwt-auth-ingress.yaml", test_namespace) diff --git a/tests/suite/test_jwt_secrets.py b/tests/suite/test_jwt_secrets.py index 312ecdc484..7fe11eaa0a 100644 --- a/tests/suite/test_jwt_secrets.py +++ b/tests/suite/test_jwt_secrets.py @@ -42,7 +42,7 @@ def jwt_secrets_setup(request, kube_apis, ingress_controller_endpoint, ingress_c print("------------------------- Deploy JWT Secrets Example -----------------------------------") create_items_from_yaml(kube_apis, f"{TEST_DATA}/jwt-secrets/{request.param}/jwt-secrets-ingress.yaml", test_namespace) ingress_host = get_first_ingress_host_from_yaml(f"{TEST_DATA}/jwt-secrets/{request.param}/jwt-secrets-ingress.yaml") - common_app = create_example_app(kube_apis, "simple", test_namespace) + create_example_app(kube_apis, "simple", test_namespace) wait_until_all_pods_are_ready(kube_apis.v1, test_namespace) ensure_connection_to_public_endpoint(ingress_controller_endpoint.public_ip, ingress_controller_endpoint.port, @@ -50,7 +50,7 @@ def jwt_secrets_setup(request, kube_apis, ingress_controller_endpoint, ingress_c def fin(): print("Clean up the JWT Secrets Application:") - delete_common_app(kube_apis.v1, kube_apis.apps_v1_api, common_app, test_namespace) + delete_common_app(kube_apis, "simple", test_namespace) delete_items_from_yaml(kube_apis, f"{TEST_DATA}/jwt-secrets/{request.param}/jwt-secrets-ingress.yaml", test_namespace) diff --git a/tests/suite/test_smoke.py b/tests/suite/test_smoke.py index 5de6703e3f..c67d4d9576 100644 --- a/tests/suite/test_smoke.py +++ b/tests/suite/test_smoke.py @@ -31,7 +31,7 @@ def smoke_setup(request, kube_apis, ingress_controller_endpoint, ingress_control secret_name = create_secret_from_yaml(kube_apis.v1, test_namespace, f"{TEST_DATA}/smoke/smoke-secret.yaml") create_items_from_yaml(kube_apis, f"{TEST_DATA}/smoke/{request.param}/smoke-ingress.yaml", test_namespace) ingress_host = get_first_ingress_host_from_yaml(f"{TEST_DATA}/smoke/{request.param}/smoke-ingress.yaml") - common_app = create_example_app(kube_apis, "simple", test_namespace) + create_example_app(kube_apis, "simple", test_namespace) wait_until_all_pods_are_ready(kube_apis.v1, test_namespace) ensure_connection_to_public_endpoint(ingress_controller_endpoint.public_ip, ingress_controller_endpoint.port, @@ -39,7 +39,7 @@ def smoke_setup(request, kube_apis, ingress_controller_endpoint, ingress_control def fin(): print("Clean up the Smoke Application:") - delete_common_app(kube_apis.v1, kube_apis.apps_v1_api, common_app, test_namespace) + delete_common_app(kube_apis, "simple", test_namespace) delete_items_from_yaml(kube_apis, f"{TEST_DATA}/smoke/{request.param}/smoke-ingress.yaml", test_namespace) delete_secret(kube_apis.v1, secret_name, test_namespace) diff --git a/tests/suite/test_wildcard_tls_secret.py b/tests/suite/test_wildcard_tls_secret.py index 781fcde41a..4239ab0d80 100644 --- a/tests/suite/test_wildcard_tls_secret.py +++ b/tests/suite/test_wildcard_tls_secret.py @@ -45,7 +45,7 @@ def wildcard_tls_secret_setup(request, kube_apis, ingress_controller_endpoint, t create_items_from_yaml(kube_apis, f"{TEST_DATA}/wildcard-tls-secret/{ing_type}/wildcard-secret-ingress.yaml", test_namespace) host = get_first_ingress_host_from_yaml(f"{TEST_DATA}/wildcard-tls-secret/{ing_type}/wildcard-secret-ingress.yaml") - common_app = create_example_app(kube_apis, "simple", test_namespace) + create_example_app(kube_apis, "simple", test_namespace) wait_until_all_pods_are_ready(kube_apis.v1, test_namespace) def fin(): @@ -53,7 +53,7 @@ def fin(): delete_items_from_yaml(kube_apis, f"{TEST_DATA}/wildcard-tls-secret/{ing_type}/wildcard-secret-ingress.yaml", test_namespace) - delete_common_app(kube_apis.v1, kube_apis.apps_v1_api, common_app, test_namespace) + delete_common_app(kube_apis, "simple", test_namespace) request.addfinalizer(fin)