def test_when_option_in_config_map_only(self, kube_apis, ingress_controller_prerequisites, crd_ingress_controller, virtual_server_setup, restore_configmap, config_map_file, expected_strings, unexpected_strings): text = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}" vs_event_text = f"Configuration for {text} was added or updated" print(f"Case 3: key specified in ConfigMap, no option in VS") patch_virtual_server_from_yaml(kube_apis.custom_objects, virtual_server_setup.vs_name, f"{TEST_DATA}/virtual-server-upstream-options/standard/virtual-server.yaml", virtual_server_setup.namespace) config_map_name = ingress_controller_prerequisites.config_map["metadata"]["name"] replace_configmap_from_yaml(kube_apis.v1, config_map_name, ingress_controller_prerequisites.namespace, config_map_file) 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(vs_event_text, vs_events) for _ in expected_strings: assert _ in config for _ in unexpected_strings: assert _ not in config assert_response_codes(resp_1, resp_2)
def test_slow_start_warning(self, kube_apis, ingress_controller_prerequisites, crd_ingress_controller, virtual_server_setup, options): 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 ; with warning(s): Slow start will be disabled" print(f"Case 0: verify a warning") 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) 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) vs_events = get_events(kube_apis.v1, virtual_server_setup.namespace) assert_event(vs_event_text, vs_events) assert "slow_start" not in config
def test_flow_for_invalid_vsr(self, kube_apis, ingress_controller_prerequisites, crd_ingress_controller, v_s_route_setup, v_s_route_app_setup): ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace) text_vs = f"{v_s_route_setup.namespace}/{v_s_route_setup.vs_name}" text_vsr_s = f"{v_s_route_setup.route_m.namespace}/{v_s_route_setup.route_m.name}" vs_event_text = f'Configuration for {text_vs} was added or updated with warning(s)' vsr_event_text = f'VirtualServerRoute {text_vsr_s} was rejected with error: ' \ f'spec.subroutes[1].path: Duplicate value: "=/backends/exact-match$request"' vs_src_yaml = f"{TEST_DATA}" \ f"/virtual-server-route-regexp-location/standard/virtual-server-exact.yaml" patch_virtual_server_from_yaml(kube_apis.custom_objects, v_s_route_setup.vs_name, vs_src_yaml, v_s_route_setup.namespace) vsr_src_yaml = f"{TEST_DATA}" \ f"/virtual-server-route-regexp-location/route-multiple-invalid-multiple-regexp-subroutes.yaml" patch_v_s_route_from_yaml(kube_apis.custom_objects, v_s_route_setup.route_m.name, vsr_src_yaml, v_s_route_setup.route_m.namespace) wait_before_test(2) 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) ns_events = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace) assert_event(vsr_event_text, ns_events) and assert_event(vs_event_text, ns_events) assert "location =/backends/exact-match$request {" not in config
def test_event_after_setup(self, kube_apis, ingress_controller_prerequisites, crd_ingress_controller, virtual_server_setup): 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) assert_event(vs_event_text, events_vs)
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
def test_snippet_annotation_ignored(self, kube_apis, ingress_controller_prerequisites, ingress_controller, test_namespace): file_name = f"{TEST_DATA}/annotations/standard/annotations-ingress-snippets.yaml" create_ingress_from_yaml(kube_apis.networking_v1, test_namespace, file_name) time.sleep(5) # Now we assert the status of the ingress has correctly added a warning event_text = f"annotations.nginx.org/server-snippets: Forbidden: snippet specified but snippets feature is not enabled" events = get_events(kube_apis.v1, test_namespace) assert_event(event_text, events)
def test_config_error_page_warning(self, kube_apis, ingress_controller_prerequisites, crd_ingress_controller, backend_setup, virtual_server_setup): text = f"{virtual_server_setup.namespace}/{virtual_server_setup.vs_name}" vs_event_warning_text = f"Configuration for {text} was added or updated ; with warning(s): " patch_virtual_server_from_yaml(kube_apis.custom_objects, virtual_server_setup.vs_name, f"{TEST_DATA}/virtual-server-grpc/virtual-server-error-page.yaml", virtual_server_setup.namespace) wait_before_test(5) events = get_events(kube_apis.v1, virtual_server_setup.namespace) assert_event(vs_event_warning_text, events) self.patch_valid_vs(kube_apis, virtual_server_setup) wait_before_test()
def test_validation_flow(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 = 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_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) wait_before_test(1) 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)
def test_validation_flow(self, kube_apis, crd_ingress_controller, virtual_server_setup): 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_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) wait_before_test(1) 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)
def test_update_to_ed_in_vs(self, kube_apis, crd_ingress_controller_with_ed, create_externaldns, virtual_server_setup): print("\nStep 1: Update VirtualServer") patch_src = f"{TEST_DATA}/virtual-server-external-dns/virtual-server-updated.yaml" patch_virtual_server_from_yaml( kube_apis.custom_objects, virtual_server_setup.vs_name, patch_src, virtual_server_setup.namespace, ) print("\nStep 2: Verify the DNSEndpoint was updated") vs_event_update_text = "Successfully updated DNSEndpoint" wait_before_test(5) events = get_events(kube_apis.v1, virtual_server_setup.namespace) assert_event(vs_event_update_text, events)
def test_flow_for_invalid_vs(self, kube_apis, ingress_controller_prerequisites, crd_ingress_controller, v_s_route_setup, v_s_route_app_setup): ic_pod_name = get_first_pod_name(kube_apis.v1, ingress_controller_prerequisites.namespace) text_vs = f"{v_s_route_setup.namespace}/{v_s_route_setup.vs_name}" vs_event_text = f'VirtualServer {text_vs} was rejected with error: ' \ f'spec.routes[1].path: Duplicate value: "=/exact-match$request"' vs_src_yaml = f"{TEST_DATA}" \ f"/virtual-server-route-regexp-location/standard/virtual-server-invalid-duplicate-routes.yaml" patch_virtual_server_from_yaml(kube_apis.custom_objects, v_s_route_setup.vs_name, vs_src_yaml, v_s_route_setup.namespace) wait_before_test(2) vs_events = get_events(kube_apis.v1, v_s_route_setup.namespace) assert_vs_conf_not_exists(kube_apis, ic_pod_name, ingress_controller_prerequisites.namespace, v_s_route_setup) assert_event(vs_event_text, vs_events)
def test_when_option_in_config_map_only( self, kube_apis, ingress_controller_prerequisites, crd_ingress_controller, v_s_route_setup, v_s_route_app_setup, restore_configmap, config_map_file, 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" print(f"Case 3: key specified in ConfigMap, no option in VS") 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.yaml", v_s_route_setup.route_m.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-options/route-single.yaml", v_s_route_setup.route_s.namespace) config_map_name = ingress_controller_prerequisites.config_map[ "metadata"]["name"] replace_configmap_from_yaml(kube_apis.v1, config_map_name, ingress_controller_prerequisites.namespace, config_map_file) 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(vsr_m_event_text, vsr_m_events) assert_event(vsr_s_event_text, 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)
def test_snippet_annotation_used(self, kube_apis, ingress_controller_prerequisites, ingress_controller, test_namespace): file_name = f"{TEST_DATA}/annotations/standard/annotations-ingress-snippets.yaml" ingress_name = create_ingress_from_yaml(kube_apis.networking_v1, test_namespace, file_name) time.sleep(5) pod_namespace = ingress_controller_prerequisites.namespace pod_name = get_first_pod_name( kube_apis.v1, ingress_controller_prerequisites.namespace) file_path = f"/etc/nginx/conf.d/{test_namespace}-{ingress_name}.conf" result_conf = get_file_contents(kube_apis.v1, file_path, pod_name, pod_namespace) snippet_annotation = "tcp_nodelay on;" assert snippet_annotation in result_conf, f"failed to find snippet ({snippet_annotation}) in nginx conf" # Now we assert the status of the ingress is correct event_text = f"Configuration for {test_namespace}/{ingress_name} was added or updated" events = get_events(kube_apis.v1, test_namespace) assert_event(event_text, events) delete_ingress(kube_apis.networking_v1, ingress_name, test_namespace)
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)