def test_invalid_value_rejection(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)
        wait_before_test(1)
        config = get_vs_nginx_template_conf(
            kube_apis.v1, virtual_server_setup.namespace,
            virtual_server_setup.vs_name, ic_pod_name,
            ingress_controller_prerequisites.namespace)
        resp_1 = requests.get(virtual_server_setup.backend_1_url,
                              headers={"host": virtual_server_setup.vs_host})
        resp_2 = requests.get(virtual_server_setup.backend_2_url,
                              headers={"host": virtual_server_setup.vs_host})
        new_events_vs = get_events(kube_apis.v1,
                                   virtual_server_setup.namespace)

        proxy_host = f"vs_{virtual_server_setup.namespace}_{virtual_server_setup.vs_name}"
        assert f'proxy_pass https://{proxy_host}_backend1' not in config
        assert f'proxy_pass https://{proxy_host}_backend2' in config
        assert_response_codes(resp_1, resp_2)
        assert_no_new_events(initial_events_vs, new_events_vs)
Esempio n. 2
0
    def test_slow_start_warning(self, kube_apis,
                                ingress_controller_prerequisites, crd_ingress_controller,
                                v_s_route_setup, v_s_route_app_setup, options):
        ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace)
        text_s = f"{v_s_route_setup.route_s.namespace}/{v_s_route_setup.route_s.name}"
        text_m = f"{v_s_route_setup.route_m.namespace}/{v_s_route_setup.route_m.name}"
        vsr_s_event_text = f"Configuration for {text_s} was added or updated with warning(s): " \
            f"Slow start will be disabled"
        vsr_m_event_text = f"Configuration for {text_m} was added or updated with warning(s): " \
            f"Slow start will be disabled"
        print(f"Case 2: no key in ConfigMap, option specified in VSR")
        new_body_m = generate_item_with_upstream_options(
            f"{TEST_DATA}/virtual-server-route-upstream-options/route-multiple.yaml",
            options)
        new_body_s = generate_item_with_upstream_options(
            f"{TEST_DATA}/virtual-server-route-upstream-options/route-single.yaml",
            options)
        patch_v_s_route(kube_apis.custom_objects,
                        v_s_route_setup.route_m.name, v_s_route_setup.route_m.namespace, new_body_m)
        patch_v_s_route(kube_apis.custom_objects,
                        v_s_route_setup.route_s.name, v_s_route_setup.route_s.namespace, new_body_s)
        wait_before_test(1)

        config = get_vs_nginx_template_conf(kube_apis.v1,
                                            v_s_route_setup.namespace,
                                            v_s_route_setup.vs_name,
                                            ic_pod_name,
                                            ingress_controller_prerequisites.namespace)
        vsr_s_events = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace)
        vsr_m_events = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace)

        assert_event(vsr_s_event_text, vsr_s_events)
        assert_event(vsr_m_event_text, vsr_m_events)
        assert "slow_start" not in config
Esempio n. 3
0
    def test_invalid_value_rejection(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)
        wait_before_test(1)
        config = get_vs_nginx_template_conf(kube_apis.v1,
                                            v_s_route_setup.namespace,
                                            v_s_route_setup.vs_name,
                                            ic_pod_name,
                                            ingress_controller_prerequisites.namespace)
        req_url = f"http://{v_s_route_setup.public_endpoint.public_ip}:{v_s_route_setup.public_endpoint.port}"
        resp_1 = requests.get(f"{req_url}{v_s_route_setup.route_m.paths[0]}",
                              headers={"host": v_s_route_setup.vs_host})
        resp_2 = requests.get(f"{req_url}{v_s_route_setup.route_s.paths[0]}",
                              headers={"host": v_s_route_setup.vs_host})
        new_events_ns_m = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace)
        new_events_ns_s = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace)

        vs_line = f"vs_{v_s_route_setup.namespace}_{v_s_route_setup.vs_name}"
        proxy_host_s = f"{vs_line}_vsr_{v_s_route_setup.route_s.namespace}_{v_s_route_setup.route_s.name}"
        proxy_host_m = f"{vs_line}_vsr_{v_s_route_setup.route_m.namespace}_{v_s_route_setup.route_m.name}"
        assert f'proxy_pass https://{proxy_host_m}' not in config
        assert f'proxy_pass https://{proxy_host_s}' in config
        assert_response_codes(resp_1, resp_2)
        assert_no_new_events(initial_events_ns_m, new_events_ns_m)
        assert_no_new_events(initial_events_ns_s, new_events_ns_s)
Esempio n. 4
0
    def test_upstream_zone_size_0(self, cli_arguments, kube_apis,
                                  annotations_setup,
                                  ingress_controller_prerequisites,
                                  annotations):
        initial_events = get_events(kube_apis.v1, annotations_setup.namespace)
        initial_count = get_event_count(annotations_setup.ingress_event_text,
                                        initial_events)
        print("Edge Case: upstream-zone-size is 0")
        new_ing = generate_ingresses_with_annotation(
            annotations_setup.ingress_src_file, annotations)
        for ing in new_ing:
            # in mergeable case this will update master ingress only
            if ing['metadata']['name'] == annotations_setup.ingress_name:
                replace_ingress(kube_apis.extensions_v1_beta1,
                                annotations_setup.ingress_name,
                                annotations_setup.namespace, ing)
        wait_before_test(1)
        result_conf = get_ingress_nginx_template_conf(
            kube_apis.v1, annotations_setup.namespace,
            annotations_setup.ingress_name, annotations_setup.ingress_pod_name,
            ingress_controller_prerequisites.namespace)
        new_events = get_events(kube_apis.v1, annotations_setup.namespace)

        assert_event_count_increased(annotations_setup.ingress_event_text,
                                     initial_count, new_events)
        if cli_arguments["ic-type"] == "nginx-plus-ingress":
            print("Run assertions for Nginx Plus case")
            assert "zone " in result_conf
            assert " 256k;" in result_conf
        elif cli_arguments["ic-type"] == "nginx-ingress":
            print("Run assertions for Nginx OSS case")
            assert "zone " not in result_conf
            assert " 256k;" not in result_conf
Esempio n. 5
0
    def test_when_option_in_v_s_only(self, kube_apis,
                                     ingress_controller_prerequisites,
                                     crd_ingress_controller,
                                     virtual_server_setup, options,
                                     expected_strings):
        text = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}"
        vs_event_text = f"Configuration for {text} was added or updated"
        events_vs = get_events(kube_apis.v1, virtual_server_setup.namespace)
        initial_count = get_event_count(vs_event_text, events_vs)
        print(f"Case 2: no key in ConfigMap , option specified in VS")
        new_body = generate_item_with_upstream_options(
            f"{TEST_DATA}/virtual-server-upstream-options/standard/virtual-server.yaml",
            options)
        patch_virtual_server(kube_apis.custom_objects,
                             virtual_server_setup.vs_name,
                             virtual_server_setup.namespace, new_body)
        wait_before_test(1)
        ic_pod_name = get_first_pod_name(
            kube_apis.v1, ingress_controller_prerequisites.namespace)
        config = get_vs_nginx_template_conf(
            kube_apis.v1, virtual_server_setup.namespace,
            virtual_server_setup.vs_name, ic_pod_name,
            ingress_controller_prerequisites.namespace)
        resp_1 = requests.get(virtual_server_setup.backend_1_url,
                              headers={"host": virtual_server_setup.vs_host})
        resp_2 = requests.get(virtual_server_setup.backend_2_url,
                              headers={"host": virtual_server_setup.vs_host})
        vs_events = get_events(kube_apis.v1, virtual_server_setup.namespace)

        assert_event_count_increased(vs_event_text, initial_count, vs_events)
        for _ in expected_strings:
            assert _ in config
        assert_response_codes(resp_1, resp_2)
Esempio n. 6
0
    def test_make_existing_vsr_invalid(self, kube_apis,
                                       ingress_controller_prerequisites,
                                       crd_ingress_controller, v_s_route_setup,
                                       route_yaml):
        ic_pod_name = get_first_pod_name(
            kube_apis.v1, ingress_controller_prerequisites.namespace)
        patch_v_s_route_from_yaml(kube_apis.custom_objects,
                                  v_s_route_setup.route_s.name, route_yaml,
                                  v_s_route_setup.route_s.namespace)
        wait_before_test(1)
        new_config = get_vs_nginx_template_conf(
            kube_apis.v1, v_s_route_setup.namespace, v_s_route_setup.vs_name,
            ic_pod_name, ingress_controller_prerequisites.namespace)
        new_vs_events = get_events(kube_apis.v1, v_s_route_setup.namespace)
        new_vsr_events = get_events(kube_apis.v1,
                                    v_s_route_setup.route_s.namespace)
        assert_locations_not_in_config(new_config,
                                       v_s_route_setup.route_s.paths)
        text = f"{v_s_route_setup.route_s.namespace}/{v_s_route_setup.route_s.name}"
        assert_event_and_count(
            f"Configuration for {v_s_route_setup.namespace}/{v_s_route_setup.vs_name} was added or updated with warning(s)",
            1, new_vs_events)

        if route_yaml == f"{TEST_DATA}/virtual-server-route/route-single-invalid-host.yaml":
            assert_event_and_count(
                f"VirtualServer is invalid or doesn't exist", 1,
                new_vsr_events)
        else:
            assert_event_and_count(
                f"VirtualServerRoute {text} was rejected with error", 1,
                new_vsr_events)
    def test_update(self, kube_apis, crd_ingress_controller, v_s_route_setup):
        req_host = f"{v_s_route_setup.public_endpoint.public_ip}:{v_s_route_setup.public_endpoint.port}"
        req_url_1 = f"http://{req_host}{v_s_route_setup.route_m.paths[0]}"
        req_url_2 = f"http://{req_host}{v_s_route_setup.route_m.paths[1]}"
        wait_before_test(1)
        vs_name = f"{v_s_route_setup.namespace}/{v_s_route_setup.vs_name}"
        vsr_name = f"{v_s_route_setup.namespace}/{v_s_route_setup.route_m.name}"
        vsr_event_text = f"Configuration for {vsr_name} was added or updated"
        vs_event_text = f"Configuration for {vs_name} was added or updated"
        events_ns = get_events(kube_apis.v1, v_s_route_setup.namespace)
        initial_count_vs = assert_event_and_get_count(vs_event_text, events_ns)
        initial_count_vsr = assert_event_and_get_count(vsr_event_text, events_ns)
        vsr_src = f"{TEST_DATA}/virtual-server-route-canned-responses/route-multiple-updated.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)
        wait_and_assert_status_code(501, req_url_1, v_s_route_setup.vs_host)
        resp = requests.get(req_url_1, headers={"host": v_s_route_setup.vs_host})
        resp_content = resp.content.decode('utf-8')
        assert resp.headers['content-type'] == 'some/type' and resp_content == "{}"

        wait_and_assert_status_code(201, req_url_2, v_s_route_setup.vs_host)
        resp = requests.get(req_url_2, headers={"host": v_s_route_setup.vs_host})
        resp_content = resp.content.decode('utf-8')
        assert resp.headers['content-type'] == 'user-type' and resp_content == "line1\nline2"

        new_events_ns = get_events(kube_apis.v1, v_s_route_setup.namespace)
        assert_event_count_increased(vs_event_text, initial_count_vs, new_events_ns)
        assert_event_count_increased(vsr_event_text, initial_count_vsr, new_events_ns)
Esempio n. 8
0
 def test_validation(self, kube_apis, annotations_setup,
                     ingress_controller_prerequisites, annotations):
     initial_events = get_events(kube_apis.v1, annotations_setup.namespace)
     print("Case 6: IC doesn't validate, only nginx validates")
     initial_count = get_event_count(
         annotations_setup.ingress_error_event_text, initial_events)
     new_ing = generate_ingresses_with_annotation(
         annotations_setup.ingress_src_file, annotations)
     for ing in new_ing:
         # in mergeable case this will update master ingress only
         if ing['metadata']['name'] == annotations_setup.ingress_name:
             replace_ingress(kube_apis.networking_v1,
                             annotations_setup.ingress_name,
                             annotations_setup.namespace, ing)
     wait_before_test()
     result_conf = get_ingress_nginx_template_conf(
         kube_apis.v1, annotations_setup.namespace,
         annotations_setup.ingress_name, annotations_setup.ingress_pod_name,
         ingress_controller_prerequisites.namespace)
     new_events = get_events(kube_apis.v1, annotations_setup.namespace)
     assert "server {" not in result_conf
     assert "No such file or directory" in result_conf
     assert_event_count_increased(
         annotations_setup.ingress_error_event_text, initial_count,
         new_events)
Esempio n. 9
0
    def test_update(self, kube_apis, crd_ingress_controller,
                    virtual_server_setup):
        wait_before_test(1)
        text = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}"
        vs_event_text = f"Configuration for {text} was added or updated"
        events_vs = get_events(kube_apis.v1, virtual_server_setup.namespace)
        initial_count = assert_event_and_get_count(vs_event_text, events_vs)
        vs_src = f"{TEST_DATA}/virtual-server-canned-responses/virtual-server-updated.yaml"
        patch_virtual_server_from_yaml(kube_apis.custom_objects,
                                       virtual_server_setup.vs_name, vs_src,
                                       virtual_server_setup.namespace)
        wait_and_assert_status_code(501, virtual_server_setup.backend_1_url,
                                    virtual_server_setup.vs_host)
        resp = requests.get(virtual_server_setup.backend_1_url,
                            headers={"host": virtual_server_setup.vs_host})
        resp_content = resp.content.decode('utf-8')
        assert resp.headers[
            'content-type'] == 'some/type' and resp_content == "{}"

        wait_and_assert_status_code(201, virtual_server_setup.backend_2_url,
                                    virtual_server_setup.vs_host)
        resp = requests.get(virtual_server_setup.backend_2_url,
                            headers={"host": virtual_server_setup.vs_host})
        resp_content = resp.content.decode('utf-8')
        assert resp.headers[
            'content-type'] == 'user-type' and resp_content == "line1\nline2"

        vs_events = get_events(kube_apis.v1, virtual_server_setup.namespace)
        assert_event_count_increased(vs_event_text, initial_count, vs_events)
 def test_make_existing_vsr_invalid(self, kube_apis,
                                    ingress_controller_prerequisites,
                                    crd_ingress_controller,
                                    v_s_route_setup,
                                    route_yaml):
     ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace)
     patch_v_s_route_from_yaml(kube_apis.custom_objects,
                               v_s_route_setup.route_s.name,
                               route_yaml,
                               v_s_route_setup.route_s.namespace)
     wait_before_test(1)
     new_config = get_vs_nginx_template_conf(kube_apis.v1,
                                             v_s_route_setup.namespace,
                                             v_s_route_setup.vs_name,
                                             ic_pod_name,
                                             ingress_controller_prerequisites.namespace)
     new_vs_events = get_events(kube_apis.v1, v_s_route_setup.namespace)
     new_vsr_events = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace)
     assert_locations_not_in_config(new_config, v_s_route_setup.route_s.paths)
     text = f"{v_s_route_setup.route_s.namespace}/{v_s_route_setup.route_s.name}"
     assert_event_and_count(f"Ignored VirtualServerRoute {text}",
                            1,
                            new_vs_events)
     assert_event_and_count(f"Ignored by VirtualServer {v_s_route_setup.namespace}/{v_s_route_setup.vs_name}",
                            1,
                            new_vsr_events)
    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)
        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" in ex.body
        except Exception as ex:
            pytest.fail(f"An unexpected exception is raised: {ex}")
        else:
            pytest.fail("Expected an exception but there was none")

        wait_before_test(1)
        config = get_vs_nginx_template_conf(
            kube_apis.v1, virtual_server_setup.namespace,
            virtual_server_setup.vs_name, ic_pod_name,
            ingress_controller_prerequisites.namespace)
        resp_1 = requests.get(virtual_server_setup.backend_1_url,
                              headers={"host": virtual_server_setup.vs_host})
        resp_2 = requests.get(virtual_server_setup.backend_2_url,
                              headers={"host": virtual_server_setup.vs_host})
        new_events_vs = get_events(kube_apis.v1,
                                   virtual_server_setup.namespace)

        proxy_host = f"vs_{virtual_server_setup.namespace}_{virtual_server_setup.vs_name}"
        assert f'proxy_pass https://{proxy_host}_backend1' not in config
        assert f'proxy_pass https://{proxy_host}_backend2' in config
        assert_response_codes(resp_1, resp_2)
        assert_no_new_events(initial_events_vs, new_events_vs)
    def test_responses_and_config_after_disable_tls(
            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)
        text = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}"
        vs_event_text = f"Configuration for {text} was added or updated"
        initial_events_vs = get_events(kube_apis.v1,
                                       virtual_server_setup.namespace)
        initial_count = assert_event_and_get_count(vs_event_text,
                                                   initial_events_vs)
        patch_virtual_server_from_yaml(
            kube_apis.custom_objects, virtual_server_setup.vs_name,
            f"{TEST_DATA}/virtual-server-upstream-tls/virtual-server-disable-tls.yaml",
            virtual_server_setup.namespace)
        wait_before_test(1)
        config = get_vs_nginx_template_conf(
            kube_apis.v1, virtual_server_setup.namespace,
            virtual_server_setup.vs_name, ic_pod_name,
            ingress_controller_prerequisites.namespace)
        resp_1 = requests.get(virtual_server_setup.backend_1_url,
                              headers={"host": virtual_server_setup.vs_host})
        resp_2 = requests.get(virtual_server_setup.backend_2_url,
                              headers={"host": virtual_server_setup.vs_host})
        new_events_vs = get_events(kube_apis.v1,
                                   virtual_server_setup.namespace)

        assert 'proxy_pass https://' not in config
        assert_response_codes(resp_1, resp_2, 200, 400)
        assert_event_count_increased(vs_event_text, initial_count,
                                     new_events_vs)
    def test_create_invalid_vsr(self, kube_apis,
                                ingress_controller_prerequisites,
                                crd_ingress_controller, v_s_route_setup):
        route_yaml = f"{TEST_DATA}/virtual-server-route/route-single-duplicate-path.yaml"
        ic_pod_name = get_first_pod_name(
            kube_apis.v1, ingress_controller_prerequisites.namespace)
        text = f"{v_s_route_setup.route_s.namespace}/{v_s_route_setup.route_s.name}"
        vs_event_text = f"Ignored VirtualServerRoute {text}: spec.subroutes[1].path: Duplicate value: \"/backend2\""
        vsr_event_text = f"Ignored by VirtualServer {v_s_route_setup.namespace}/{v_s_route_setup.vs_name}"
        delete_v_s_route(kube_apis.custom_objects,
                         v_s_route_setup.route_s.name,
                         v_s_route_setup.route_s.namespace)

        create_v_s_route_from_yaml(kube_apis.custom_objects, route_yaml,
                                   v_s_route_setup.route_s.namespace)
        wait_before_test(1)
        new_config = get_vs_nginx_template_conf(
            kube_apis.v1, v_s_route_setup.namespace, v_s_route_setup.vs_name,
            ic_pod_name, ingress_controller_prerequisites.namespace)
        new_vs_events = get_events(kube_apis.v1, v_s_route_setup.namespace)
        new_vsr_events = get_events(kube_apis.v1,
                                    v_s_route_setup.route_s.namespace)
        assert_locations_not_in_config(new_config,
                                       v_s_route_setup.route_s.paths)
        assert_event_and_count(vs_event_text, 1, new_vs_events)
        assert_event_and_count(vsr_event_text, 1, new_vsr_events)
    def test_when_annotation_in_configmap_only(
            self, kube_apis, annotations_setup,
            ingress_controller_prerequisites, configmap_file, expected_strings,
            unexpected_strings):
        initial_events = get_events(kube_apis.v1, annotations_setup.namespace)
        initial_count = get_event_count(annotations_setup.ingress_event_text,
                                        initial_events)
        print("Case 3: keys in ConfigMap, no annotations in Ingress")
        replace_ingresses_from_yaml(kube_apis.extensions_v1_beta1,
                                    annotations_setup.namespace,
                                    annotations_setup.ingress_src_file)
        replace_configmap_from_yaml(
            kube_apis.v1,
            ingress_controller_prerequisites.config_map['metadata']['name'],
            ingress_controller_prerequisites.namespace, configmap_file)
        wait_before_test(1)
        result_conf = get_ingress_nginx_template_conf(
            kube_apis.v1, annotations_setup.namespace,
            annotations_setup.ingress_name, annotations_setup.ingress_pod_name,
            ingress_controller_prerequisites.namespace)
        new_events = get_events(kube_apis.v1, annotations_setup.namespace)

        assert_event_count_increased(annotations_setup.ingress_event_text,
                                     initial_count, new_events)
        for _ in expected_strings:
            assert _ in result_conf
        for _ in unexpected_strings:
            assert _ not in result_conf
Esempio n. 15
0
    def test_when_annotation_in_ing_only(self, kube_apis, annotations_setup,
                                         ingress_controller_prerequisites,
                                         annotations, expected_strings,
                                         unexpected_strings):
        initial_events = get_events(kube_apis.v1, annotations_setup.namespace)
        initial_count = get_event_count(annotations_setup.ingress_event_text,
                                        initial_events)
        print("Case 2: no ConfigMap keys, annotations in Ingress only")
        new_ing = generate_ingresses_with_annotation(
            annotations_setup.ingress_src_file, annotations)
        for ing in new_ing:
            # in mergeable case this will update master ingress only
            if ing['metadata']['name'] == annotations_setup.ingress_name:
                replace_ingress(kube_apis.networking_v1,
                                annotations_setup.ingress_name,
                                annotations_setup.namespace, ing)
        wait_before_test(1)
        result_conf = get_ingress_nginx_template_conf(
            kube_apis.v1, annotations_setup.namespace,
            annotations_setup.ingress_name, annotations_setup.ingress_pod_name,
            ingress_controller_prerequisites.namespace)
        new_events = get_events(kube_apis.v1, annotations_setup.namespace)

        assert_event_count_increased(annotations_setup.ingress_event_text,
                                     initial_count, new_events)
        for _ in expected_strings:
            assert _ in result_conf
        for _ in unexpected_strings:
            assert _ not in result_conf
    def test_ing_overrides_configmap(self, kube_apis, annotations_setup,
                                     ingress_controller_prerequisites,
                                     annotations, configmap_file,
                                     expected_strings, unexpected_strings):
        initial_events = get_events(kube_apis.v1, annotations_setup.namespace)
        initial_count = get_event_count(annotations_setup.ingress_event_text,
                                        initial_events)
        print("Case 4: keys in ConfigMap, annotations in Ingress")
        new_ing = generate_ingresses_with_annotation(
            annotations_setup.ingress_src_file, annotations)
        for ing in new_ing:
            # in mergeable case this will update master ingress only
            if ing['metadata']['name'] == annotations_setup.ingress_name:
                replace_ingress(kube_apis.extensions_v1_beta1,
                                annotations_setup.ingress_name,
                                annotations_setup.namespace, ing)
        replace_configmap_from_yaml(
            kube_apis.v1,
            ingress_controller_prerequisites.config_map['metadata']['name'],
            ingress_controller_prerequisites.namespace, configmap_file)
        wait_before_test(1)
        result_conf = get_ingress_nginx_template_conf(
            kube_apis.v1, annotations_setup.namespace,
            annotations_setup.ingress_name, annotations_setup.ingress_pod_name,
            ingress_controller_prerequisites.namespace)
        new_events = get_events(kube_apis.v1, annotations_setup.namespace)

        assert_event_count_increased(annotations_setup.ingress_event_text,
                                     initial_count, new_events)
        for _ in expected_strings:
            assert _ in result_conf
        for _ in unexpected_strings:
            assert _ not in result_conf
    def test_validation(self, kube_apis, annotations_setup,
                        ingress_controller_prerequisites, annotations,
                        expected_strings, unexpected_strings):
        initial_events = get_events(kube_apis.v1, annotations_setup.namespace)
        print("Case 6: IC doesn't validate, only nginx validates")
        initial_count = get_event_count(
            annotations_setup.ingress_error_event_text, initial_events)
        new_ing = generate_ingresses_with_annotation(
            annotations_setup.ingress_src_file, annotations)
        for ing in new_ing:
            # in mergeable case this will update master ingress only
            if ing['metadata']['name'] == annotations_setup.ingress_name:
                replace_ingress(kube_apis.extensions_v1_beta1,
                                annotations_setup.ingress_name,
                                annotations_setup.namespace, ing)
        wait_before_test(1)
        result_conf = get_ingress_nginx_template_conf(
            kube_apis.v1, annotations_setup.namespace,
            annotations_setup.ingress_name, annotations_setup.ingress_pod_name,
            ingress_controller_prerequisites.namespace)
        new_events = get_events(kube_apis.v1, annotations_setup.namespace)

        assert_event_count_increased(
            annotations_setup.ingress_error_event_text, initial_count,
            new_events)
        for _ in expected_strings:
            assert _ in result_conf
        for _ in unexpected_strings:
            assert _ not in result_conf
    def test_update(self, kube_apis, crd_ingress_controller,
                    virtual_server_setup):
        wait_before_test(1)
        text = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}"
        vs_event_text = f"Configuration for {text} was added or updated"
        events_vs = get_events(kube_apis.v1, virtual_server_setup.namespace)
        initial_count = assert_event_and_get_count(vs_event_text, events_vs)
        vs_src = f"{TEST_DATA}/virtual-server-redirects/virtual-server-updated.yaml"
        patch_virtual_server_from_yaml(kube_apis.custom_objects,
                                       virtual_server_setup.vs_name, vs_src,
                                       virtual_server_setup.namespace)
        wait_and_assert_status_code(301,
                                    virtual_server_setup.backend_1_url,
                                    virtual_server_setup.vs_host,
                                    allow_redirects=False)
        resp = requests.get(virtual_server_setup.backend_1_url,
                            headers={"host": virtual_server_setup.vs_host},
                            allow_redirects=False)
        assert resp.headers['location'] == "http://demo.nginx.com"
        wait_and_assert_status_code(302,
                                    virtual_server_setup.backend_2_url,
                                    virtual_server_setup.vs_host,
                                    allow_redirects=False)
        resp = requests.get(virtual_server_setup.backend_2_url,
                            headers={"host": virtual_server_setup.vs_host},
                            allow_redirects=False)
        assert resp.headers['location'] == "http://demo.nginx.com"

        vs_events = get_events(kube_apis.v1, virtual_server_setup.namespace)
        assert_event_count_increased(vs_event_text, initial_count, vs_events)
    def test_grpc_flow(self, kube_apis, annotations_grpc_setup,
                       ingress_controller_prerequisites, annotations,
                       expected_strings, unexpected_strings):
        initial_events = get_events(kube_apis.v1,
                                    annotations_grpc_setup.namespace)
        initial_count = get_event_count(
            annotations_grpc_setup.ingress_event_text, initial_events)
        print("Case 5: grpc annotations override http ones")
        new_ing = generate_ingresses_with_annotation(
            annotations_grpc_setup.ingress_src_file, annotations)
        for ing in new_ing:
            if ing['metadata']['name'] == annotations_grpc_setup.ingress_name:
                replace_ingress(kube_apis.extensions_v1_beta1,
                                annotations_grpc_setup.ingress_name,
                                annotations_grpc_setup.namespace, ing)
        wait_before_test(1)
        result_conf = get_ingress_nginx_template_conf(
            kube_apis.v1, annotations_grpc_setup.namespace,
            annotations_grpc_setup.ingress_name,
            annotations_grpc_setup.ingress_pod_name,
            ingress_controller_prerequisites.namespace)
        new_events = get_events(kube_apis.v1, annotations_grpc_setup.namespace)

        assert_event_count_increased(annotations_grpc_setup.ingress_event_text,
                                     initial_count, new_events)
        for _ in expected_strings:
            assert _ in result_conf
        for _ in unexpected_strings:
            assert _ not in result_conf
    def test_events_flows(self, kube_apis, ingress_controller_prerequisites,
                          crd_ingress_controller, vsr_externalname_setup):
        text_vsr = f"{vsr_externalname_setup.route.namespace}/{vsr_externalname_setup.route.name}"
        text_vs = f"{vsr_externalname_setup.namespace}/{vsr_externalname_setup.vs_name}"
        vsr_event_text = f"Configuration for {text_vsr} was added or updated"
        vs_event_text = f"Configuration for {text_vs} was added or updated"
        initial_events = get_events(kube_apis.v1,
                                    vsr_externalname_setup.route.namespace)
        initial_count_vsr = assert_event_and_get_count(vsr_event_text,
                                                       initial_events)
        initial_count_vs = assert_event_and_get_count(vs_event_text,
                                                      initial_events)

        print("Step 1: Update external host in externalName service")
        external_svc = read_service(kube_apis.v1,
                                    vsr_externalname_setup.external_svc,
                                    vsr_externalname_setup.namespace)
        external_svc.spec.external_name = "demo.nginx.com"
        replace_service(kube_apis.v1, vsr_externalname_setup.external_svc,
                        vsr_externalname_setup.namespace, external_svc)
        wait_before_test(1)

        new_events = get_events(kube_apis.v1,
                                vsr_externalname_setup.route.namespace)
        assert_event_and_count(vsr_event_text, initial_count_vsr + 1,
                               new_events)
        assert_event_and_count(vs_event_text, initial_count_vs + 1, new_events)
    def test_virtual_server_behavior(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)

        print("Step 1: initial check")
        step_1_list = get_events(kube_apis.v1, virtual_server_setup.namespace)
        assert_vs_conf_exists(kube_apis, ic_pod_name, ingress_controller_prerequisites.namespace,
                              virtual_server_setup)
        assert_response_200(virtual_server_setup)

        print("Step 2: make a valid VirtualServer invalid and check")
        patch_virtual_server_from_yaml(kube_apis.custom_objects,
                                       virtual_server_setup.vs_name,
                                       f"{TEST_DATA}/virtual-server-validation/virtual-server-invalid-cookie.yaml",
                                       virtual_server_setup.namespace)
        wait_before_test(1)
        step_2_list = get_events(kube_apis.v1, virtual_server_setup.namespace)
        assert_reject_event_emitted(virtual_server_setup, step_2_list, step_1_list)
        assert_vs_conf_not_exists(kube_apis, ic_pod_name, ingress_controller_prerequisites.namespace,
                                  virtual_server_setup)
        assert_response_404(virtual_server_setup)

        print("Step 3: update an invalid VirtualServer with another invalid and check")
        patch_virtual_server_from_yaml(kube_apis.custom_objects,
                                       virtual_server_setup.vs_name,
                                       f"{TEST_DATA}/virtual-server-validation/virtual-server-no-default-action.yaml",
                                       virtual_server_setup.namespace)
        wait_before_test(1)
        step_3_list = get_events(kube_apis.v1, virtual_server_setup.namespace)
        assert_reject_event_emitted(virtual_server_setup, step_3_list, step_2_list)
        assert_vs_conf_not_exists(kube_apis, ic_pod_name, ingress_controller_prerequisites.namespace,
                                  virtual_server_setup)
        assert_response_404(virtual_server_setup)

        print("Step 4: make an invalid VirtualServer valid and check")
        patch_virtual_server_from_yaml(kube_apis.custom_objects,
                                       virtual_server_setup.vs_name,
                                       f"{TEST_DATA}/virtual-server-validation/standard/virtual-server.yaml",
                                       virtual_server_setup.namespace)
        wait_before_test(1)
        step_4_list = get_events(kube_apis.v1, virtual_server_setup.namespace)
        assert_vs_conf_exists(kube_apis, ic_pod_name, ingress_controller_prerequisites.namespace,
                              virtual_server_setup)
        assert_event_count_increased_in_list(virtual_server_setup, step_4_list, step_3_list)
        assert_response_200(virtual_server_setup)

        print("Step 5: delete VS and then create an invalid and check")
        delete_virtual_server(kube_apis.custom_objects, virtual_server_setup.vs_name, virtual_server_setup.namespace)
        create_virtual_server_from_yaml(kube_apis.custom_objects,
                                        f"{TEST_DATA}/virtual-server-validation/virtual-server-invalid-cookie.yaml",
                                        virtual_server_setup.namespace)
        wait_before_test(1)
        step_5_list = get_events(kube_apis.v1, virtual_server_setup.namespace)
        assert_reject_event_emitted(virtual_server_setup, step_5_list, step_4_list)
        assert_vs_conf_not_exists(kube_apis, ic_pod_name, ingress_controller_prerequisites.namespace,
                                  virtual_server_setup)
        assert_response_404(virtual_server_setup)
    def test_events_flows(self, kube_apis, ingress_controller_prerequisites,
                          crd_ingress_controller, virtual_server_setup, vs_externalname_setup):
        text = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}"
        vs_event_text = f"Configuration for {text} was added or updated"
        vs_event_update_text = f"Configuration for {text} was updated"
        events_vs = get_events(kube_apis.v1, virtual_server_setup.namespace)
        initial_count = assert_event_and_get_count(vs_event_text, events_vs)
        initial_count_up = assert_event_and_get_count(vs_event_update_text, events_vs)

        print("Step 1: Update external host in externalName service")
        external_svc = read_service(kube_apis.v1, vs_externalname_setup.external_svc, virtual_server_setup.namespace)
        external_svc.spec.external_name = "demo.nginx.com"
        replace_service(kube_apis.v1, vs_externalname_setup.external_svc, virtual_server_setup.namespace, external_svc)
        wait_before_test(1)

        wait_for_event_count_increases(kube_apis, vs_event_text, initial_count, virtual_server_setup.namespace)
        events_step_1 = get_events(kube_apis.v1, virtual_server_setup.namespace)
        assert_event_and_count(vs_event_text, initial_count + 1, events_step_1)
        assert_event_and_count(vs_event_update_text, initial_count_up, events_step_1)

        print("Step 2: Remove resolver from ConfigMap to trigger an error")
        config_map_name = ingress_controller_prerequisites.config_map["metadata"]["name"]
        vs_event_warning_text = f"Configuration for {text} was updated with warning(s):"
        replace_configmap(kube_apis.v1, config_map_name,
                          ingress_controller_prerequisites.namespace,
                          ingress_controller_prerequisites.config_map)
        wait_before_test(1)

        events_step_2 = get_events(kube_apis.v1, virtual_server_setup.namespace)
        assert_event_and_count(vs_event_warning_text, 1, events_step_2)
        assert_event_and_count(vs_event_update_text, initial_count_up, events_step_2)
    def test_ssl_keys(self, kube_apis, ingress_controller_prerequisites, crd_ingress_controller,
                      virtual_server_setup, clean_up):
        ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace)
        initial_list = get_events(kube_apis.v1, virtual_server_setup.namespace)

        print("Step 1: update ConfigMap with valid ssl keys")
        replace_configmap_from_yaml(kube_apis.v1,
                                    ingress_controller_prerequisites.config_map['metadata']['name'],
                                    ingress_controller_prerequisites.namespace,
                                    f"{TEST_DATA}/virtual-server-configmap-keys/configmap-ssl-keys.yaml")
        wait_before_test(1)
        step_1_events = get_events(kube_apis.v1, virtual_server_setup.namespace)
        step_1_config = get_vs_nginx_template_conf(kube_apis.v1,
                                                   virtual_server_setup.namespace,
                                                   virtual_server_setup.vs_name,
                                                   ic_pod_name,
                                                   ingress_controller_prerequisites.namespace)
        assert_valid_event_emitted(virtual_server_setup, step_1_events, initial_list)
        assert_ssl_keys(step_1_config)

        print("Step 2: update ConfigMap with invalid ssl keys")
        replace_configmap_from_yaml(kube_apis.v1,
                                    ingress_controller_prerequisites.config_map['metadata']['name'],
                                    ingress_controller_prerequisites.namespace,
                                    f"{TEST_DATA}/virtual-server-configmap-keys/configmap-ssl-keys-invalid.yaml")
        wait_before_test(1)
        step_2_events = get_events(kube_apis.v1, virtual_server_setup.namespace)
        step_2_config = get_vs_nginx_template_conf(kube_apis.v1,
                                                   virtual_server_setup.namespace,
                                                   virtual_server_setup.vs_name,
                                                   ic_pod_name,
                                                   ingress_controller_prerequisites.namespace)
        assert_valid_event_count_increased(virtual_server_setup, step_2_events, step_1_events)
        assert_defaults_of_ssl_keys(step_2_config)
Esempio n. 24
0
    def test_event_message_and_config(self, kube_apis,
                                      ingress_controller_prerequisites,
                                      crd_ingress_controller, v_s_route_setup):
        invalid_fields_s = [
            "upstreams[0].lb-method", "upstreams[0].fail-timeout",
            "upstreams[0].max-fails", "upstreams[0].connect-timeout",
            "upstreams[0].read-timeout", "upstreams[0].send-timeout",
            "upstreams[0].keepalive", "upstreams[0].max-conns",
            "upstreams[0].next-upstream", "upstreams[0].next-upstream-timeout",
            "upstreams[0].next-upstream-tries",
            "upstreams[0].client-max-body-size", "upstreams[0].buffers.number",
            "upstreams[0].buffers.size", "upstreams[0].buffer-size"
        ]
        invalid_fields_m = [
            "upstreams[0].lb-method", "upstreams[0].fail-timeout",
            "upstreams[0].max-fails", "upstreams[0].connect-timeout",
            "upstreams[0].read-timeout", "upstreams[0].send-timeout",
            "upstreams[0].keepalive", "upstreams[0].max-conns",
            "upstreams[0].next-upstream", "upstreams[0].next-upstream-timeout",
            "upstreams[0].next-upstream-tries",
            "upstreams[0].client-max-body-size", "upstreams[0].buffers.number",
            "upstreams[0].buffers.size", "upstreams[0].buffer-size",
            "upstreams[1].lb-method", "upstreams[1].fail-timeout",
            "upstreams[1].max-fails", "upstreams[1].connect-timeout",
            "upstreams[1].read-timeout", "upstreams[1].send-timeout",
            "upstreams[1].keepalive", "upstreams[1].max-conns",
            "upstreams[1].next-upstream", "upstreams[1].next-upstream-timeout",
            "upstreams[1].next-upstream-tries",
            "upstreams[1].client-max-body-size", "upstreams[1].buffers.number",
            "upstreams[1].buffers.size", "upstreams[1].buffer-size"
        ]
        text_s = f"{v_s_route_setup.route_s.namespace}/{v_s_route_setup.route_s.name}"
        text_m = f"{v_s_route_setup.route_m.namespace}/{v_s_route_setup.route_m.name}"
        vsr_s_event_text = f"VirtualServerRoute {text_s} is invalid and was rejected: "
        vsr_m_event_text = f"VirtualServerRoute {text_m} is invalid and was rejected: "
        patch_v_s_route_from_yaml(
            kube_apis.custom_objects, v_s_route_setup.route_s.name,
            f"{TEST_DATA}/virtual-server-route-upstream-options/route-single-invalid-keys.yaml",
            v_s_route_setup.route_s.namespace)
        patch_v_s_route_from_yaml(
            kube_apis.custom_objects, v_s_route_setup.route_m.name,
            f"{TEST_DATA}/virtual-server-route-upstream-options/route-multiple-invalid-keys.yaml",
            v_s_route_setup.route_m.namespace)
        wait_before_test(2)
        ic_pod_name = get_first_pod_name(
            kube_apis.v1, ingress_controller_prerequisites.namespace)
        config = get_vs_nginx_template_conf(
            kube_apis.v1, v_s_route_setup.namespace, v_s_route_setup.vs_name,
            ic_pod_name, ingress_controller_prerequisites.namespace)
        vsr_s_events = get_events(kube_apis.v1,
                                  v_s_route_setup.route_s.namespace)
        vsr_m_events = get_events(kube_apis.v1,
                                  v_s_route_setup.route_m.namespace)

        assert_event_starts_with_text_and_contains_errors(
            vsr_s_event_text, vsr_s_events, invalid_fields_s)
        assert_event_starts_with_text_and_contains_errors(
            vsr_m_event_text, vsr_m_events, invalid_fields_m)
        assert "upstream" not in config
    def test_v_s_r_overrides_config_map(self, kube_apis,
                                        ingress_controller_prerequisites,
                                        crd_ingress_controller,
                                        v_s_route_setup, v_s_route_app_setup,
                                        options, expected_strings,
                                        unexpected_strings):
        req_url = f"http://{v_s_route_setup.public_endpoint.public_ip}:{v_s_route_setup.public_endpoint.port}"
        text_s = f"{v_s_route_setup.route_s.namespace}/{v_s_route_setup.route_s.name}"
        text_m = f"{v_s_route_setup.route_m.namespace}/{v_s_route_setup.route_m.name}"
        vsr_s_event_text = f"Configuration for {text_s} was added or updated"
        vsr_m_event_text = f"Configuration for {text_m} was added or updated"
        events_ns_m = get_events(kube_apis.v1,
                                 v_s_route_setup.route_m.namespace)
        events_ns_s = get_events(kube_apis.v1,
                                 v_s_route_setup.route_s.namespace)
        initial_count_vsr_m = get_event_count(vsr_m_event_text, events_ns_m)
        initial_count_vsr_s = get_event_count(vsr_s_event_text, events_ns_s)
        print(f"Case 4: key specified in ConfigMap, option specified in VS")
        new_body_m = generate_item_with_upstream_options(
            f"{TEST_DATA}/virtual-server-route-upstream-options/route-multiple.yaml",
            options)
        new_body_s = generate_item_with_upstream_options(
            f"{TEST_DATA}/virtual-server-route-upstream-options/route-single.yaml",
            options)
        patch_v_s_route(kube_apis.custom_objects, v_s_route_setup.route_m.name,
                        v_s_route_setup.route_m.namespace, new_body_m)
        patch_v_s_route(kube_apis.custom_objects, v_s_route_setup.route_s.name,
                        v_s_route_setup.route_s.namespace, new_body_s)
        config_map_name = ingress_controller_prerequisites.config_map[
            "metadata"]["name"]
        replace_configmap_from_yaml(
            kube_apis.v1, config_map_name,
            ingress_controller_prerequisites.namespace,
            f"{TEST_DATA}/virtual-server-route-upstream-options/configmap-with-keys.yaml"
        )
        wait_before_test(1)
        ic_pod_name = get_first_pod_name(
            kube_apis.v1, ingress_controller_prerequisites.namespace)
        config = get_vs_nginx_template_conf(
            kube_apis.v1, v_s_route_setup.namespace, v_s_route_setup.vs_name,
            ic_pod_name, ingress_controller_prerequisites.namespace)
        resp_1 = requests.get(f"{req_url}{v_s_route_setup.route_m.paths[0]}",
                              headers={"host": v_s_route_setup.vs_host})
        resp_2 = requests.get(f"{req_url}{v_s_route_setup.route_s.paths[0]}",
                              headers={"host": v_s_route_setup.vs_host})
        vsr_s_events = get_events(kube_apis.v1,
                                  v_s_route_setup.route_s.namespace)
        vsr_m_events = get_events(kube_apis.v1,
                                  v_s_route_setup.route_m.namespace)

        assert_event_count_increased(vsr_m_event_text, initial_count_vsr_m,
                                     vsr_m_events)
        assert_event_count_increased(vsr_s_event_text, initial_count_vsr_s,
                                     vsr_s_events)
        for _ in expected_strings:
            assert _ in config
        for _ in unexpected_strings:
            assert _ not in config
        assert_response_codes(resp_1, resp_2)
Esempio n. 26
0
    def test_validation_flow(self, kube_apis, ingress_controller_prerequisites,
                             crd_ingress_controller, v_s_route_setup):
        invalid_fields_s = [
            "upstreams[0].healthCheck.path", "upstreams[0].healthCheck.interval", "upstreams[0].healthCheck.jitter",
            "upstreams[0].healthCheck.fails", "upstreams[0].healthCheck.passes",
            "upstreams[0].healthCheck.connect-timeout",
            "upstreams[0].healthCheck.read-timeout", "upstreams[0].healthCheck.send-timeout",
            "upstreams[0].healthCheck.headers[0].name", "upstreams[0].healthCheck.headers[0].value",
            "upstreams[0].healthCheck.statusMatch",
            "upstreams[0].slow-start"
        ]
        invalid_fields_m = [
            "upstreams[0].healthCheck.path", "upstreams[0].healthCheck.interval", "upstreams[0].healthCheck.jitter",
            "upstreams[0].healthCheck.fails", "upstreams[0].healthCheck.passes",
            "upstreams[0].healthCheck.connect-timeout",
            "upstreams[0].healthCheck.read-timeout", "upstreams[0].healthCheck.send-timeout",
            "upstreams[0].healthCheck.headers[0].name", "upstreams[0].healthCheck.headers[0].value",
            "upstreams[0].healthCheck.statusMatch",
            "upstreams[0].slow-start",
            "upstreams[1].healthCheck.path", "upstreams[1].healthCheck.interval", "upstreams[1].healthCheck.jitter",
            "upstreams[1].healthCheck.fails", "upstreams[1].healthCheck.passes",
            "upstreams[1].healthCheck.connect-timeout",
            "upstreams[1].healthCheck.read-timeout", "upstreams[1].healthCheck.send-timeout",
            "upstreams[1].healthCheck.headers[0].name", "upstreams[0].healthCheck.headers[0].value",
            "upstreams[1].healthCheck.statusMatch",
            "upstreams[1].slow-start"
        ]
        text_s = f"{v_s_route_setup.route_s.namespace}/{v_s_route_setup.route_s.name}"
        text_m = f"{v_s_route_setup.route_m.namespace}/{v_s_route_setup.route_m.name}"
        vsr_s_event_text = f"VirtualServerRoute {text_s} is invalid and was rejected: "
        vsr_m_event_text = f"VirtualServerRoute {text_m} is invalid and was rejected: "
        patch_v_s_route_from_yaml(kube_apis.custom_objects,
                                  v_s_route_setup.route_s.name,
                                  f"{TEST_DATA}/virtual-server-route-upstream-options/plus-route-s-invalid-keys.yaml",
                                  v_s_route_setup.route_s.namespace)
        patch_v_s_route_from_yaml(kube_apis.custom_objects,
                                  v_s_route_setup.route_m.name,
                                  f"{TEST_DATA}/virtual-server-route-upstream-options/plus-route-m-invalid-keys.yaml",
                                  v_s_route_setup.route_m.namespace)
        wait_before_test(2)
        ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace)
        config = get_vs_nginx_template_conf(kube_apis.v1,
                                            v_s_route_setup.namespace,
                                            v_s_route_setup.vs_name,
                                            ic_pod_name,
                                            ingress_controller_prerequisites.namespace)
        vsr_s_events = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace)
        vsr_m_events = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace)

        assert_event_starts_with_text_and_contains_errors(vsr_s_event_text, vsr_s_events, invalid_fields_s)
        assert_event_starts_with_text_and_contains_errors(vsr_m_event_text, vsr_m_events, invalid_fields_m)
        assert "upstream" not in config
Esempio n. 27
0
 def test_events_after_setup(self, kube_apis, ingress_controller_prerequisites,
                             crd_ingress_controller, v_s_route_setup, v_s_route_secure_app_setup):
     text_s = f"{v_s_route_setup.route_s.namespace}/{v_s_route_setup.route_s.name}"
     text_m = f"{v_s_route_setup.route_m.namespace}/{v_s_route_setup.route_m.name}"
     text_vs = f"{v_s_route_setup.namespace}/{v_s_route_setup.vs_name}"
     vsr_s_event_text = f"Configuration for {text_s} was added or updated"
     vsr_m_event_text = f"Configuration for {text_m} was added or updated"
     vs_event_text = f"Configuration for {text_vs} was added or updated"
     events_ns_m = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace)
     events_ns_s = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace)
     assert_event(vsr_s_event_text, events_ns_s)
     assert_event(vsr_m_event_text, events_ns_m)
     assert_event(vs_event_text, events_ns_m)
    def test_responses_and_config_after_disable_tls(
            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)
        text_s = f"{v_s_route_setup.route_s.namespace}/{v_s_route_setup.route_s.name}"
        text_m = f"{v_s_route_setup.route_m.namespace}/{v_s_route_setup.route_m.name}"
        text_vs = f"{v_s_route_setup.namespace}/{v_s_route_setup.vs_name}"
        vsr_s_event_text = f"Configuration for {text_s} was added or updated"
        vsr_m_event_text = f"Configuration for {text_m} was added or updated"
        vs_event_text = f"Configuration for {text_vs} was added or updated"
        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)
        initial_count_vsr_m = assert_event_and_get_count(
            vsr_m_event_text, initial_events_ns_m)
        initial_count_vsr_s = assert_event_and_get_count(
            vsr_s_event_text, initial_events_ns_s)
        initial_count_vs = assert_event_and_get_count(vs_event_text,
                                                      initial_events_ns_m)
        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-disable-tls.yaml",
            v_s_route_setup.route_s.namespace)
        wait_before_test(1)
        config = get_vs_nginx_template_conf(
            kube_apis.v1, v_s_route_setup.namespace, v_s_route_setup.vs_name,
            ic_pod_name, ingress_controller_prerequisites.namespace)
        req_url = f"http://{v_s_route_setup.public_endpoint.public_ip}:{v_s_route_setup.public_endpoint.port}"
        resp_1 = requests.get(f"{req_url}{v_s_route_setup.route_m.paths[0]}",
                              headers={"host": v_s_route_setup.vs_host})
        resp_2 = requests.get(f"{req_url}{v_s_route_setup.route_s.paths[0]}",
                              headers={"host": v_s_route_setup.vs_host})
        new_events_ns_m = get_events(kube_apis.v1,
                                     v_s_route_setup.route_m.namespace)
        new_events_ns_s = get_events(kube_apis.v1,
                                     v_s_route_setup.route_s.namespace)

        assert 'proxy_pass https://' not in config
        assert_response_codes(resp_1, resp_2, 200, 400)
        assert_event_count_increased(vsr_m_event_text, initial_count_vsr_m,
                                     new_events_ns_m)
        assert_event_count_increased(vs_event_text, initial_count_vs,
                                     new_events_ns_m)
        assert_event_count_increased(vsr_s_event_text, initial_count_vsr_s,
                                     new_events_ns_s)
    def test_when_option_in_v_s_r_only(self, kube_apis,
                                       ingress_controller_prerequisites,
                                       crd_ingress_controller, v_s_route_setup,
                                       v_s_route_app_setup, option,
                                       option_value, expected_string):
        req_url = f"http://{v_s_route_setup.public_endpoint.public_ip}:{v_s_route_setup.public_endpoint.port}"
        text_s = f"{v_s_route_setup.route_s.namespace}/{v_s_route_setup.route_s.name}"
        text_m = f"{v_s_route_setup.route_m.namespace}/{v_s_route_setup.route_m.name}"
        vsr_s_event_text = f"Configuration for {text_s} was added or updated"
        vsr_m_event_text = f"Configuration for {text_m} was added or updated"
        events_ns_m = get_events(kube_apis.v1,
                                 v_s_route_setup.route_m.namespace)
        events_ns_s = get_events(kube_apis.v1,
                                 v_s_route_setup.route_s.namespace)
        initial_count_vsr_m = get_event_count(vsr_m_event_text, events_ns_m)
        initial_count_vsr_s = get_event_count(vsr_s_event_text, events_ns_s)
        print(f"Case 2: no {option} in ConfigMap, {option} specified in VSR")
        new_body_m = generate_item_with_upstream_option(
            f"{TEST_DATA}/virtual-server-route-upstream-options/route-multiple.yaml",
            option, option_value)
        new_body_s = generate_item_with_upstream_option(
            f"{TEST_DATA}/virtual-server-route-upstream-options/route-single.yaml",
            option, option_value)
        patch_v_s_route(kube_apis.custom_objects, v_s_route_setup.route_m.name,
                        v_s_route_setup.route_m.namespace, new_body_m)
        patch_v_s_route(kube_apis.custom_objects, v_s_route_setup.route_s.name,
                        v_s_route_setup.route_s.namespace, new_body_s)
        wait_before_test(1)
        ic_pod_name = get_first_pod_name(
            kube_apis.v1, ingress_controller_prerequisites.namespace)
        config = get_vs_nginx_template_conf(
            kube_apis.v1, v_s_route_setup.namespace, v_s_route_setup.vs_name,
            ic_pod_name, ingress_controller_prerequisites.namespace)
        resp_1 = requests.get(f"{req_url}{v_s_route_setup.route_m.paths[0]}",
                              headers={"host": v_s_route_setup.vs_host})
        resp_2 = requests.get(f"{req_url}{v_s_route_setup.route_s.paths[0]}",
                              headers={"host": v_s_route_setup.vs_host})
        vsr_s_events = get_events(kube_apis.v1,
                                  v_s_route_setup.route_s.namespace)
        vsr_m_events = get_events(kube_apis.v1,
                                  v_s_route_setup.route_m.namespace)

        assert_event_count_increased(vsr_m_event_text, initial_count_vsr_m,
                                     vsr_m_events)
        assert_event_count_increased(vsr_s_event_text, initial_count_vsr_s,
                                     vsr_s_events)
        assert expected_string in config
        assert_response_codes(resp_1, resp_2)
    def test_keys_in_main_config(self, cli_arguments, kube_apis, ingress_controller_prerequisites,
                                 crd_ingress_controller, virtual_server_setup, clean_up):
        wait_before_test(1)
        ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace)
        initial_list = get_events(kube_apis.v1, virtual_server_setup.namespace)
        data_file = f"{TEST_DATA}/virtual-server-configmap-keys/configmap-validation-keys.yaml"
        data_file_invalid = f"{TEST_DATA}/virtual-server-configmap-keys/configmap-validation-keys-invalid.yaml"
        config_path = "/etc/nginx/nginx.conf"

        print("Step 5: main config: update ConfigMap with valid keys with validation rules")
        replace_configmap_from_yaml(kube_apis.v1,
                                    ingress_controller_prerequisites.config_map['metadata']['name'],
                                    ingress_controller_prerequisites.namespace,
                                    data_file)
        expected_values = get_configmap_fields_from_yaml(data_file)
        wait_before_test(1)
        step_5_config = get_file_contents(kube_apis.v1,
                                          config_path, ic_pod_name, ingress_controller_prerequisites.namespace)
        step_5_events = get_events(kube_apis.v1, virtual_server_setup.namespace)
        assert_update_event_count_increased(virtual_server_setup, step_5_events, initial_list)
        assert_keys_with_validation_in_main_config(step_5_config, expected_values)

        print("Step 6: main config: update ConfigMap with invalid keys")
        replace_configmap_from_yaml(kube_apis.v1,
                                    ingress_controller_prerequisites.config_map['metadata']['name'],
                                    ingress_controller_prerequisites.namespace,
                                    data_file_invalid)
        unexpected_values = get_configmap_fields_from_yaml(data_file_invalid)
        wait_before_test(1)
        step_6_config = get_file_contents(kube_apis.v1,
                                          config_path, ic_pod_name, ingress_controller_prerequisites.namespace)
        step_6_events = get_events(kube_apis.v1, virtual_server_setup.namespace)
        assert_update_event_count_increased(virtual_server_setup, step_6_events, step_5_events)
        assert_defaults_of_keys_with_validation_in_main_config(step_6_config, unexpected_values)

        print("Step 7: main config: special case for hash variables")
        data_file = f"{TEST_DATA}/virtual-server-configmap-keys/configmap-global-variables.yaml"
        expected_values = get_configmap_fields_from_yaml(data_file)
        replace_configmap_from_yaml(kube_apis.v1,
                                    ingress_controller_prerequisites.config_map['metadata']['name'],
                                    ingress_controller_prerequisites.namespace,
                                    data_file)
        wait_before_test(1)
        step_7_config = get_file_contents(kube_apis.v1,
                                          config_path, ic_pod_name, ingress_controller_prerequisites.namespace)
        step_7_events = get_events(kube_apis.v1, virtual_server_setup.namespace)
        assert_not_applied_event_emitted(virtual_server_setup, step_7_events, step_6_events)
        assert_keys_with_validation_in_main_config(step_7_config, expected_values)