From d0acb215d4dae2d12fd4ff4d850e3f7a11dff257 Mon Sep 17 00:00:00 2001 From: dubrovina Date: Fri, 21 Feb 2020 12:47:15 +0000 Subject: [PATCH] Fix imports and failing tests --- .../standard/virtual-server.yaml | 2 -- .../virtual-server-invalid.yaml | 4 +-- .../standard/virtual-server.yaml | 1 - .../virtual-server-invalid.yaml | 2 +- .../virtual-server-updated.yaml | 1 - .../route-multiple-invalid.yaml | 4 +-- .../route-multiple.yaml | 2 -- .../route-multiple-invalid.yaml | 2 +- .../route-multiple-updated.yaml | 1 - .../route-multiple.yaml | 1 - .../plus-route-m-invalid-keys.yaml | 1 + .../route-multiple.yaml | 4 --- .../route-single-disable-tls.yaml | 2 -- .../virtual-server-disable-tls.yaml | 4 --- tests/suite/fixtures.py | 31 +++++++++-------- tests/suite/resources_utils.py | 33 +++++++++++++++++++ .../suite/test_v_s_route_canned_responses.py | 10 +++--- tests/suite/test_v_s_route_focused_canary.py | 2 +- tests/suite/test_v_s_route_upstream_tls.py | 15 ++++++--- tests/suite/test_virtual_server.py | 2 +- .../test_virtual_server_canned_responses.py | 12 ++++--- .../suite/test_virtual_server_upstream_tls.py | 15 ++++++--- tests/suite/yaml_utils.py | 4 ++- 23 files changed, 96 insertions(+), 59 deletions(-) diff --git a/tests/data/virtual-server-canned-responses/standard/virtual-server.yaml b/tests/data/virtual-server-canned-responses/standard/virtual-server.yaml index 4ed5dcd2c5..27e1d69a17 100644 --- a/tests/data/virtual-server-canned-responses/standard/virtual-server.yaml +++ b/tests/data/virtual-server-canned-responses/standard/virtual-server.yaml @@ -38,8 +38,6 @@ spec: - path: "/canned-defaults" action: return: - code: - type: body: | line1 line2 diff --git a/tests/data/virtual-server-canned-responses/virtual-server-invalid.yaml b/tests/data/virtual-server-canned-responses/virtual-server-invalid.yaml index 3708331ba4..ff251629c2 100644 --- a/tests/data/virtual-server-canned-responses/virtual-server-invalid.yaml +++ b/tests/data/virtual-server-canned-responses/virtual-server-invalid.yaml @@ -9,5 +9,5 @@ spec: action: return: code: 301 - type: "text/html" - body: \ No newline at end of file + type: "anything will do" + body: "Variables must be enclosed in curly brackets: $request_uri" \ No newline at end of file diff --git a/tests/data/virtual-server-redirects/standard/virtual-server.yaml b/tests/data/virtual-server-redirects/standard/virtual-server.yaml index 816e8db644..a3659a403a 100644 --- a/tests/data/virtual-server-redirects/standard/virtual-server.yaml +++ b/tests/data/virtual-server-redirects/standard/virtual-server.yaml @@ -13,5 +13,4 @@ spec: - path: "/default-redirect" action: redirect: - code: url: "${scheme}://${host}${request_uri}?arg=${http_x_forwarded_proto}" \ No newline at end of file diff --git a/tests/data/virtual-server-redirects/virtual-server-invalid.yaml b/tests/data/virtual-server-redirects/virtual-server-invalid.yaml index ba4440ba69..8381a44311 100644 --- a/tests/data/virtual-server-redirects/virtual-server-invalid.yaml +++ b/tests/data/virtual-server-redirects/virtual-server-invalid.yaml @@ -13,5 +13,5 @@ spec: - path: "/default-redirect" action: redirect: - code: + code: 204 url: "${nginx_version}" \ No newline at end of file diff --git a/tests/data/virtual-server-redirects/virtual-server-updated.yaml b/tests/data/virtual-server-redirects/virtual-server-updated.yaml index 44bc860a05..be4ce18c24 100644 --- a/tests/data/virtual-server-redirects/virtual-server-updated.yaml +++ b/tests/data/virtual-server-redirects/virtual-server-updated.yaml @@ -8,7 +8,6 @@ spec: - path: "/custom-redirect" action: redirect: - code: url: "http://demo.nginx.com" - path: "/default-redirect" action: diff --git a/tests/data/virtual-server-route-canned-responses/route-multiple-invalid.yaml b/tests/data/virtual-server-route-canned-responses/route-multiple-invalid.yaml index 3e729edabf..766c32794f 100644 --- a/tests/data/virtual-server-route-canned-responses/route-multiple-invalid.yaml +++ b/tests/data/virtual-server-route-canned-responses/route-multiple-invalid.yaml @@ -9,5 +9,5 @@ spec: action: return: code: 301 - type: "text/html" - body: \ No newline at end of file + type: "anything will do" + body: "Variables must be inclosed in curly brackets: $request_uri" \ No newline at end of file diff --git a/tests/data/virtual-server-route-canned-responses/route-multiple.yaml b/tests/data/virtual-server-route-canned-responses/route-multiple.yaml index 8509bb6dae..3b009d7a02 100644 --- a/tests/data/virtual-server-route-canned-responses/route-multiple.yaml +++ b/tests/data/virtual-server-route-canned-responses/route-multiple.yaml @@ -38,8 +38,6 @@ spec: - path: "/backends/canned-defaults" action: return: - code: - type: body: | line1 line2 diff --git a/tests/data/virtual-server-route-redirects/route-multiple-invalid.yaml b/tests/data/virtual-server-route-redirects/route-multiple-invalid.yaml index b12adcdc63..f5f1c78cac 100644 --- a/tests/data/virtual-server-route-redirects/route-multiple-invalid.yaml +++ b/tests/data/virtual-server-route-redirects/route-multiple-invalid.yaml @@ -13,5 +13,5 @@ spec: - path: "/backends/default-redirect" action: redirect: - code: + code: 204 url: "${nginx_version}" \ No newline at end of file diff --git a/tests/data/virtual-server-route-redirects/route-multiple-updated.yaml b/tests/data/virtual-server-route-redirects/route-multiple-updated.yaml index e8c90cb122..adcdc72577 100644 --- a/tests/data/virtual-server-route-redirects/route-multiple-updated.yaml +++ b/tests/data/virtual-server-route-redirects/route-multiple-updated.yaml @@ -8,7 +8,6 @@ spec: - path: "/backends/custom-redirect" action: redirect: - code: url: "http://demo.nginx.com" - path: "/backends/default-redirect" action: diff --git a/tests/data/virtual-server-route-redirects/route-multiple.yaml b/tests/data/virtual-server-route-redirects/route-multiple.yaml index 34333f5460..1e4298191c 100644 --- a/tests/data/virtual-server-route-redirects/route-multiple.yaml +++ b/tests/data/virtual-server-route-redirects/route-multiple.yaml @@ -13,5 +13,4 @@ spec: - path: "/backends/default-redirect" action: redirect: - code: url: "${scheme}://${host}${request_uri}?arg=${http_x_forwarded_proto}" \ No newline at end of file diff --git a/tests/data/virtual-server-route-upstream-options/plus-route-m-invalid-keys.yaml b/tests/data/virtual-server-route-upstream-options/plus-route-m-invalid-keys.yaml index df4164e243..c5cbde755b 100644 --- a/tests/data/virtual-server-route-upstream-options/plus-route-m-invalid-keys.yaml +++ b/tests/data/virtual-server-route-upstream-options/plus-route-m-invalid-keys.yaml @@ -57,6 +57,7 @@ spec: statusMatch: "invalid" slow-start: "1.5m" queue: + size: 0 timeout: "hour" subroutes: - path: "/backends/backend1" diff --git a/tests/data/virtual-server-route-upstream-tls/route-multiple.yaml b/tests/data/virtual-server-route-upstream-tls/route-multiple.yaml index 11ef801535..dc620fcac8 100644 --- a/tests/data/virtual-server-route-upstream-tls/route-multiple.yaml +++ b/tests/data/virtual-server-route-upstream-tls/route-multiple.yaml @@ -8,13 +8,9 @@ spec: - name: backend1 service: backend1-svc port: 80 - tls: - enable: - name: backend3 service: backend3-svc port: 80 - tls: - enable: False subroutes: - path: "/backends/backend1" action: diff --git a/tests/data/virtual-server-route-upstream-tls/route-single-disable-tls.yaml b/tests/data/virtual-server-route-upstream-tls/route-single-disable-tls.yaml index 58b590dbca..3c5d8aec87 100644 --- a/tests/data/virtual-server-route-upstream-tls/route-single-disable-tls.yaml +++ b/tests/data/virtual-server-route-upstream-tls/route-single-disable-tls.yaml @@ -8,8 +8,6 @@ spec: - name: backend2 service: backend2-svc port: 80 - tls: - enable: subroutes: - path: "/backend2" action: diff --git a/tests/data/virtual-server-upstream-tls/virtual-server-disable-tls.yaml b/tests/data/virtual-server-upstream-tls/virtual-server-disable-tls.yaml index afc50699ea..177bc6cd1f 100644 --- a/tests/data/virtual-server-upstream-tls/virtual-server-disable-tls.yaml +++ b/tests/data/virtual-server-upstream-tls/virtual-server-disable-tls.yaml @@ -8,13 +8,9 @@ spec: - name: backend2 service: backend2-svc port: 80 - tls: - enable: - name: backend1 service: backend1-svc port: 80 - tls: - enable: False routes: - path: "/backend1" action: diff --git a/tests/suite/fixtures.py b/tests/suite/fixtures.py index 20af554467..88a1a936b9 100644 --- a/tests/suite/fixtures.py +++ b/tests/suite/fixtures.py @@ -10,18 +10,18 @@ ApiextensionsV1beta1Api, AppsV1Api from kubernetes.client.rest import ApiException -from suite.custom_resources_utils import create_crd_from_yaml, create_virtual_server_from_yaml, \ - delete_virtual_server, create_v_s_route_from_yaml, delete_v_s_route, delete_crd +from suite.custom_resources_utils import create_virtual_server_from_yaml, \ + delete_virtual_server, create_v_s_route_from_yaml, delete_v_s_route, create_crd_from_yaml, delete_crd from suite.kube_config_utils import ensure_context_in_config, get_current_context_name from suite.resources_utils import create_namespace_with_name_from_yaml, delete_namespace, create_ns_and_sa_from_yaml, \ patch_rbac, create_example_app, wait_until_all_pods_are_ready, delete_common_app, \ ensure_connection_to_public_endpoint, create_service_with_name, create_deployment_with_name, delete_deployment, \ - delete_service, replace_configmap_from_yaml, delete_testing_namespaces, \ - create_ingress_controller, delete_ingress_controller, configure_rbac, cleanup_rbac, \ - create_service_from_yaml, get_service_node_ports, wait_for_public_ip, \ - create_configmap_from_yaml, create_secret_from_yaml, \ - get_first_vs_host_from_yaml, get_paths_from_vs_yaml, get_paths_from_vsr_yaml, get_name_from_yaml, \ - get_route_namespace_from_vs_yaml + delete_service, replace_configmap_from_yaml, delete_testing_namespaces +from suite.resources_utils import create_ingress_controller, delete_ingress_controller, configure_rbac, cleanup_rbac +from suite.resources_utils import create_service_from_yaml, get_service_node_ports, wait_for_public_ip +from suite.resources_utils import create_configmap_from_yaml, create_secret_from_yaml +from suite.yaml_utils import get_first_vs_host_from_yaml, get_paths_from_vs_yaml, get_paths_from_vsr_yaml, \ + get_route_namespace_from_vs_yaml, get_name_from_yaml from settings import ALLOWED_SERVICE_TYPES, ALLOWED_IC_TYPES, DEPLOYMENTS, TEST_DATA, ALLOWED_DEPLOYMENT_TYPES @@ -302,15 +302,18 @@ def crd_ingress_controller(cli_arguments, kube_apis, ingress_controller_prerequi """ namespace = ingress_controller_prerequisites.namespace name = "nginx-ingress" - crd_name = get_name_from_yaml(f"{DEPLOYMENTS}/common/common/vs-definition.yaml") + vs_crd_name = get_name_from_yaml(f"{DEPLOYMENTS}/common/vs-definition.yaml") + vsr_crd_name = get_name_from_yaml(f"{DEPLOYMENTS}/common/vsr-definition.yaml") try: print("------------------------- Update ClusterRole -----------------------------------") if request.param['type'] == 'rbac-without-vs': patch_rbac(kube_apis.rbac_v1_beta1, f"{TEST_DATA}/virtual-server/rbac-without-vs.yaml") - print("------------------------- Register CRD -----------------------------------") - create_crd_from_yaml(kube_apis.api_extensions_v1_beta1, crd_name, + print("------------------------- Register CRDs -----------------------------------") + create_crd_from_yaml(kube_apis.api_extensions_v1_beta1, vs_crd_name, f"{DEPLOYMENTS}/common/vs-definition.yaml") + create_crd_from_yaml(kube_apis.api_extensions_v1_beta1, vsr_crd_name, + f"{DEPLOYMENTS}/common/vsr-definition.yaml") print("------------------------- Create IC -----------------------------------") name = create_ingress_controller(kube_apis.v1, kube_apis.apps_v1_api, cli_arguments, namespace, request.param.get('extra_args', None)) @@ -320,14 +323,16 @@ def crd_ingress_controller(cli_arguments, kube_apis, ingress_controller_prerequi except ApiException as ex: # Finalizer method doesn't start if fixture creation was incomplete, ensure clean up here print(f"Failed to complete CRD IC fixture: {ex}\nClean up the cluster as much as possible.") - delete_crd(kube_apis.api_extensions_v1_beta1, crd_name) + delete_crd(kube_apis.api_extensions_v1_beta1, vs_crd_name) + delete_crd(kube_apis.api_extensions_v1_beta1, vsr_crd_name) print("Restore the ClusterRole:") patch_rbac(kube_apis.rbac_v1_beta1, f"{DEPLOYMENTS}/rbac/rbac.yaml") print("Remove the IC:") delete_ingress_controller(kube_apis.apps_v1_api, name, cli_arguments['deployment-type'], namespace) def fin(): - delete_crd(kube_apis.api_extensions_v1_beta1, crd_name) + delete_crd(kube_apis.api_extensions_v1_beta1, vs_crd_name) + delete_crd(kube_apis.api_extensions_v1_beta1, vsr_crd_name) print("Restore the ClusterRole:") patch_rbac(kube_apis.rbac_v1_beta1, f"{DEPLOYMENTS}/rbac/rbac.yaml") print("Remove the IC:") diff --git a/tests/suite/resources_utils.py b/tests/suite/resources_utils.py index 23de08014c..a96820e25f 100644 --- a/tests/suite/resources_utils.py +++ b/tests/suite/resources_utils.py @@ -92,6 +92,21 @@ def cleanup_rbac(rbac_v1_beta1: RbacAuthorizationV1beta1Api, rbac: RBACAuthoriza rbac_v1_beta1.delete_cluster_role(rbac.role, delete_options) +def create_deployment_from_yaml(apps_v1_api: AppsV1Api, namespace, yaml_manifest) -> str: + """ + Create a deployment based on yaml file. + + :param apps_v1_api: AppsV1Api + :param namespace: namespace name + :param yaml_manifest: absolute path to file + :return: str + """ + print(f"Load {yaml_manifest}") + with open(yaml_manifest) as f: + dep = yaml.safe_load(f) + return create_deployment(apps_v1_api, namespace, dep) + + def create_deployment(apps_v1_api: AppsV1Api, namespace, body) -> str: """ Create a deployment based on a dict. @@ -529,6 +544,24 @@ def create_namespace(v1: CoreV1Api, body) -> str: return body['metadata']['name'] +def create_namespace_with_name_from_yaml(v1: CoreV1Api, name, yaml_manifest) -> str: + """ + Create a namespace with a specific name based on a yaml manifest. + + :param v1: CoreV1Api + :param name: name + :param yaml_manifest: an absolute path to file + :return: str + """ + print(f"Create a namespace with specific name:") + with open(yaml_manifest) as f: + dep = yaml.safe_load(f) + dep['metadata']['name'] = name + v1.create_namespace(dep) + print(f"Namespace created with name '{str(dep['metadata']['name'])}'") + return dep['metadata']['name'] + + def create_service_account(v1: CoreV1Api, namespace, body) -> None: """ Create a ServiceAccount based on a dict. diff --git a/tests/suite/test_v_s_route_canned_responses.py b/tests/suite/test_v_s_route_canned_responses.py index 40620d5de0..21a69f353f 100644 --- a/tests/suite/test_v_s_route_canned_responses.py +++ b/tests/suite/test_v_s_route_canned_responses.py @@ -5,7 +5,7 @@ from settings import TEST_DATA from suite.custom_assertions import assert_event_and_get_count, wait_and_assert_status_code, \ - assert_event, assert_event_count_increased + assert_event_count_increased, assert_event_starts_with_text_and_contains_errors from suite.custom_resources_utils import get_vs_nginx_template_conf, patch_v_s_route_from_yaml from suite.resources_utils import get_first_pod_name, get_events, wait_before_test @@ -95,11 +95,13 @@ def test_update(self, kube_apis, crd_ingress_controller, v_s_route_setup): assert_event_count_increased(vsr_event_text, initial_count_vsr, new_events_ns) def test_validation_flow(self, kube_apis, crd_ingress_controller, v_s_route_setup): + invalid_fields = [ + "spec.subroutes[0].action.return.code", "spec.subroutes[0].action.return.body" + ] req_host = f"{v_s_route_setup.public_endpoint.public_ip}:{v_s_route_setup.public_endpoint.port}" req_url = f"http://{req_host}{v_s_route_setup.route_s.paths[0]}" text = f"{v_s_route_setup.namespace}/{v_s_route_setup.route_m.name}" - event_text = f"VirtualServerRoute {text} is invalid and was rejected: " \ - f"spec.subroutes[0].action.return.body: Required value" + vsr_m_event_text = f"VirtualServerRoute {text} is invalid and was rejected: " vsr_src = f"{TEST_DATA}/virtual-server-route-canned-responses/route-multiple-invalid.yaml" patch_v_s_route_from_yaml(kube_apis.custom_objects, v_s_route_setup.route_m.name, vsr_src, v_s_route_setup.namespace) @@ -107,4 +109,4 @@ def test_validation_flow(self, kube_apis, crd_ingress_controller, v_s_route_setu wait_and_assert_status_code(404, req_url, v_s_route_setup.vs_host) events = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace) - assert_event(event_text, events) + assert_event_starts_with_text_and_contains_errors(vsr_m_event_text, events, invalid_fields) diff --git a/tests/suite/test_v_s_route_focused_canary.py b/tests/suite/test_v_s_route_focused_canary.py index c2f95a31d8..066bc4f3c8 100644 --- a/tests/suite/test_v_s_route_focused_canary.py +++ b/tests/suite/test_v_s_route_focused_canary.py @@ -62,7 +62,6 @@ def __init__(self, namespace, vs_host, vs_name, route: VirtualServerRoute, backe self.backends_url = backends_url -@pytest.mark.vsr @pytest.fixture(scope="class") def vsr_canary_setup(request, kube_apis, ingress_controller_prerequisites, ingress_controller_endpoint) -> VSRAdvancedRoutingSetup: @@ -109,6 +108,7 @@ def fin(): return VSRAdvancedRoutingSetup(ns_1, vs_host, vs_name, route, backends_url) +@pytest.mark.vsr @pytest.mark.parametrize('crd_ingress_controller, vsr_canary_setup', [({"type": "complete", "extra_args": [f"-enable-custom-resources"]}, {"example": "virtual-server-route-focused-canary"})], diff --git a/tests/suite/test_v_s_route_upstream_tls.py b/tests/suite/test_v_s_route_upstream_tls.py index 0284bfedbb..690e6215e8 100644 --- a/tests/suite/test_v_s_route_upstream_tls.py +++ b/tests/suite/test_v_s_route_upstream_tls.py @@ -1,5 +1,6 @@ import requests import pytest +from kubernetes.client.rest import ApiException from settings import TEST_DATA from suite.custom_assertions import assert_event_and_get_count, assert_event_count_increased, assert_response_codes, \ @@ -84,16 +85,20 @@ def test_events_after_setup(self, kube_apis, ingress_controller_prerequisites, assert_event(vsr_m_event_text, events_ns_m) assert_event(vs_event_text, events_ns_m) - def test_invalid_value_rejection(self, kube_apis, ingress_controller_prerequisites, + def test_validation_flow(self, kube_apis, ingress_controller_prerequisites, crd_ingress_controller, v_s_route_setup, v_s_route_secure_app_setup): ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace) initial_events_ns_m = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace) initial_events_ns_s = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace) - patch_v_s_route_from_yaml(kube_apis.custom_objects, - v_s_route_setup.route_s.name, - f"{TEST_DATA}/virtual-server-route-upstream-tls/route-single-invalid.yaml", - v_s_route_setup.route_s.namespace) + try: + patch_v_s_route_from_yaml(kube_apis.custom_objects, + v_s_route_setup.route_s.name, + f"{TEST_DATA}/virtual-server-route-upstream-tls/route-single-invalid.yaml", + v_s_route_setup.route_s.namespace) + except ApiException as ex: + assert ex.status == 422 and "spec.upstreams.tls.enable: Invalid value" in ex.body + wait_before_test(1) config = get_vs_nginx_template_conf(kube_apis.v1, v_s_route_setup.namespace, diff --git a/tests/suite/test_virtual_server.py b/tests/suite/test_virtual_server.py index 9e98858bb6..0c2b1057d1 100644 --- a/tests/suite/test_virtual_server.py +++ b/tests/suite/test_virtual_server.py @@ -158,7 +158,7 @@ def test_responses_after_rbac_misconfiguration_on_the_fly(self, kube_apis, crd_i def test_responses_after_crd_removal_on_the_fly(self, kube_apis, crd_ingress_controller, virtual_server_setup): print("\nStep 12: remove CRD and check") - crd_name = get_name_from_yaml(f"{DEPLOYMENTS}/common/common/vs-definition.yaml") + crd_name = get_name_from_yaml(f"{DEPLOYMENTS}/common/vs-definition.yaml") delete_crd(kube_apis.api_extensions_v1_beta1, crd_name) wait_and_assert_status_code(404, virtual_server_setup.backend_1_url, virtual_server_setup.vs_host) wait_and_assert_status_code(404, virtual_server_setup.backend_2_url, virtual_server_setup.vs_host) diff --git a/tests/suite/test_virtual_server_canned_responses.py b/tests/suite/test_virtual_server_canned_responses.py index 932e0a2c9b..8c12a54bb9 100644 --- a/tests/suite/test_virtual_server_canned_responses.py +++ b/tests/suite/test_virtual_server_canned_responses.py @@ -3,8 +3,8 @@ import json from settings import TEST_DATA -from suite.custom_assertions import wait_and_assert_status_code, assert_event, assert_event_and_get_count, \ - assert_event_count_increased +from suite.custom_assertions import wait_and_assert_status_code, assert_event_and_get_count, \ + assert_event_count_increased, assert_event_starts_with_text_and_contains_errors from suite.custom_resources_utils import patch_virtual_server_from_yaml, get_vs_nginx_template_conf from suite.resources_utils import get_first_pod_name, get_events, wait_before_test @@ -83,9 +83,11 @@ def test_update(self, kube_apis, crd_ingress_controller, virtual_server_setup): assert_event_count_increased(vs_event_text, initial_count, vs_events) def test_validation_flow(self, kube_apis, crd_ingress_controller, virtual_server_setup): + invalid_fields = [ + "spec.routes[0].action.return.code", "spec.routes[0].action.return.body" + ] text = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}" - event_text = f"VirtualServer {text} is invalid and was rejected: " \ - f"spec.routes[0].action.return.body: Required value" + vs_event_text = f"VirtualServer {text} is invalid and was rejected: " vs_src = f"{TEST_DATA}/virtual-server-canned-responses/virtual-server-invalid.yaml" patch_virtual_server_from_yaml(kube_apis.custom_objects, virtual_server_setup.vs_name, vs_src, virtual_server_setup.namespace) @@ -93,4 +95,4 @@ def test_validation_flow(self, kube_apis, crd_ingress_controller, virtual_server wait_and_assert_status_code(404, virtual_server_setup.backend_1_url, virtual_server_setup.vs_host) vs_events = get_events(kube_apis.v1, virtual_server_setup.namespace) - assert_event(event_text, vs_events) + assert_event_starts_with_text_and_contains_errors(vs_event_text, vs_events, invalid_fields) diff --git a/tests/suite/test_virtual_server_upstream_tls.py b/tests/suite/test_virtual_server_upstream_tls.py index 6a2c2e24b3..c0c7616712 100644 --- a/tests/suite/test_virtual_server_upstream_tls.py +++ b/tests/suite/test_virtual_server_upstream_tls.py @@ -1,5 +1,6 @@ import requests import pytest +from kubernetes.client.rest import ApiException from settings import TEST_DATA from suite.custom_assertions import assert_event_and_get_count, assert_event_count_increased, assert_response_codes, \ @@ -39,14 +40,18 @@ def test_event_after_setup(self, kube_apis, ingress_controller_prerequisites, events_vs = get_events(kube_apis.v1, virtual_server_setup.namespace) assert_event(vs_event_text, events_vs) - def test_invalid_value_rejection(self, kube_apis, ingress_controller_prerequisites, + def test_validation_flow(self, kube_apis, ingress_controller_prerequisites, crd_ingress_controller, virtual_server_setup): ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace) initial_events_vs = get_events(kube_apis.v1, virtual_server_setup.namespace) - patch_virtual_server_from_yaml(kube_apis.custom_objects, - virtual_server_setup.vs_name, - f"{TEST_DATA}/virtual-server-upstream-tls/virtual-server-invalid.yaml", - virtual_server_setup.namespace) + try: + patch_virtual_server_from_yaml(kube_apis.custom_objects, + virtual_server_setup.vs_name, + f"{TEST_DATA}/virtual-server-upstream-tls/virtual-server-invalid.yaml", + virtual_server_setup.namespace) + except ApiException as ex: + assert ex.status == 422 and "spec.upstreams.tls.enable: Invalid value" in ex.body + wait_before_test(1) config = get_vs_nginx_template_conf(kube_apis.v1, virtual_server_setup.namespace, diff --git a/tests/suite/yaml_utils.py b/tests/suite/yaml_utils.py index 0f93a4318e..2bab151b3b 100644 --- a/tests/suite/yaml_utils.py +++ b/tests/suite/yaml_utils.py @@ -18,15 +18,17 @@ def get_first_ingress_host_from_yaml(file) -> str: def get_name_from_yaml(file) -> str: """ - Parse yaml file and return all the found metadata.name. + Parse yaml file and return first metadata.name appeared. :param file: an absolute path to file :return: str """ + res = "" with open(file) as f: docs = yaml.safe_load_all(f) for dep in docs: return dep['metadata']['name'] + return res def get_paths_from_vs_yaml(file) -> []: