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"Configuration for {v_s_route_setup.namespace}/{v_s_route_setup.vs_name} was added or updated with warning(s)" vsr_event_text = f"VirtualServerRoute {text} was rejected with error: spec.subroutes[1].path: Duplicate value: \"/backend2\"" 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 vsr_rewrites_setup(request, kube_apis, test_namespace, hello_app, ingress_controller_endpoint, crd_ingress_controller): vs_parent = create_virtual_server_from_yaml(kube_apis.custom_objects, vs_parent_yaml, test_namespace) vsr_prefixes = create_v_s_route_from_yaml(kube_apis.custom_objects, vsr_prefixes_yaml, test_namespace) vsr_regex1 = create_v_s_route_from_yaml(kube_apis.custom_objects, vsr_regex1_yaml, test_namespace) vsr_regex2 = create_v_s_route_from_yaml(kube_apis.custom_objects, vsr_regex2_yaml, test_namespace) wait_before_test() def fin(): delete_virtual_server(kube_apis.custom_objects, vs_parent, test_namespace) delete_v_s_route(kube_apis.custom_objects, vsr_prefixes, test_namespace) delete_v_s_route(kube_apis.custom_objects, vsr_regex1, test_namespace) delete_v_s_route(kube_apis.custom_objects, vsr_regex2, test_namespace) request.addfinalizer(fin) return RewritesSetup(ingress_controller_endpoint)
def vsr_adv_routing_setup( request, kube_apis, ingress_controller_prerequisites, ingress_controller_endpoint) -> VSRAdvancedRoutingSetup: """ Prepare an example app for advanced routing VSR. Single namespace with VS+VSR and advanced-routing app. :param request: internal pytest fixture :param kube_apis: client apis :param ingress_controller_endpoint: :param ingress_controller_prerequisites: :return: """ vs_routes_ns = get_route_namespace_from_vs_yaml( f"{TEST_DATA}/{request.param['example']}/standard/virtual-server.yaml") ns_1 = create_namespace_with_name_from_yaml(kube_apis.v1, vs_routes_ns[0], f"{TEST_DATA}/common/ns.yaml") print( "------------------------- Deploy Virtual Server -----------------------------------" ) vs_name = create_virtual_server_from_yaml( kube_apis.custom_objects, f"{TEST_DATA}/{request.param['example']}/standard/virtual-server.yaml", ns_1) vs_host = get_first_host_from_yaml( f"{TEST_DATA}/{request.param['example']}/standard/virtual-server.yaml") print( "------------------------- Deploy Virtual Server Route -----------------------------------" ) vsr_name = create_v_s_route_from_yaml( kube_apis.custom_objects, f"{TEST_DATA}/{request.param['example']}/virtual-server-route-header.yaml", ns_1) vsr_paths = get_paths_from_vsr_yaml( f"{TEST_DATA}/{request.param['example']}/virtual-server-route-header.yaml" ) route = VirtualServerRoute(ns_1, vsr_name, vsr_paths) backends_url = f"http://{ingress_controller_endpoint.public_ip}:{ingress_controller_endpoint.port}{vsr_paths[0]}" print( "---------------------- Deploy advanced-routing app ----------------------------" ) create_example_app(kube_apis, "advanced-routing", ns_1) wait_until_all_pods_are_ready(kube_apis.v1, ns_1) def fin(): print("Delete test namespace") delete_namespace(kube_apis.v1, ns_1) request.addfinalizer(fin) return VSRAdvancedRoutingSetup(ns_1, vs_host, vs_name, route, backends_url)
def vsr_regexp_setup(request, kube_apis, ingress_controller_prerequisites, ingress_controller_endpoint, test_namespace) -> VSRRegexpSetup: """ Prepare an example app for advanced routing VSR. Single namespace with VS+VSR and simple app. :param request: internal pytest fixture :param kube_apis: client apis :param ingress_controller_endpoint: :param ingress_controller_prerequisites: :param test_namespace: :return: """ print( "------------------------- Deploy Virtual Server -----------------------------------" ) vs_src_yaml = f"{TEST_DATA}/{request.param['example']}/additional-case/virtual-server-exact-over-all.yaml" vs_name = create_virtual_server_from_yaml(kube_apis.custom_objects, vs_src_yaml, test_namespace) vs_host = get_first_host_from_yaml(vs_src_yaml) print( "------------------------- Deploy VSRs -----------------------------------" ) for item in ['prefix', 'exact', 'regexp']: create_v_s_route_from_yaml( kube_apis.custom_objects, f"{TEST_DATA}/{request.param['example']}/additional-case/route-{item}.yaml", test_namespace) print( "---------------------- Deploy simple app ----------------------------" ) create_example_app(kube_apis, "extended", test_namespace) wait_until_all_pods_are_ready(kube_apis.v1, test_namespace) return VSRRegexpSetup(test_namespace, vs_host, vs_name)
def ap_vsr_setup(kube_apis, test_namespace, policy_method) -> tuple: print( f"------------------------- Deploy namespace ---------------------------" ) vs_routes_ns = "grpcs" vsr_ns = create_namespace_with_name_from_yaml( kube_apis.v1, vs_routes_ns, f"{TEST_DATA}/common/ns.yaml") src_pol_name, vs_name = ap_generic_setup(kube_apis, vsr_ns, test_namespace, policy_method, vsr_vs_yaml) vs_host = get_first_host_from_yaml(vsr_vs_yaml) print( "------------------------- Deploy Virtual Server Route ----------------------------" ) vsr_name = create_v_s_route_from_yaml(kube_apis.custom_objects, waf_subroute_vsr_src, vsr_ns) vsr_paths = get_paths_from_vsr_yaml(waf_subroute_vsr_src) vsr = VirtualServerRoute(vsr_ns, vsr_name, vsr_paths) return (src_pol_name, vsr_ns, vs_host, vs_name, vsr)
def test_vsr_without_vs(self, kube_apis, ingress_controller_prerequisites, crd_ingress_controller, v_s_route_setup, test_namespace): ic_pod_name = get_first_pod_name( kube_apis.v1, ingress_controller_prerequisites.namespace) vsr_name = create_v_s_route_from_yaml( kube_apis.custom_objects, f"{TEST_DATA}/virtual-server-route/route-orphan.yaml", test_namespace) vsr_paths = get_paths_from_vsr_yaml( f"{TEST_DATA}/virtual-server-route/route-orphan.yaml") 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_list_ns_3 = get_events(kube_apis.v1, test_namespace) assert_locations_not_in_config(new_config, vsr_paths) assert_event_and_count( f"VirtualServer {v_s_route_setup.namespace}/{v_s_route_setup.vs_name} ignores VirtualServerRoute", 1, new_list_ns_3)
def test_responses_and_events_in_flow(self, kube_apis, ingress_controller_prerequisites, crd_ingress_controller, v_s_route_setup, v_s_route_app_setup): req_url = f"http://{v_s_route_setup.public_endpoint.public_ip}:{v_s_route_setup.public_endpoint.port}" ic_pod_name = get_first_pod_name( kube_apis.v1, ingress_controller_prerequisites.namespace) vs_name = f"{v_s_route_setup.namespace}/{v_s_route_setup.vs_name}" vsr_1_name = f"{v_s_route_setup.namespace}/{v_s_route_setup.route_m.name}" vsr_2_name = f"{v_s_route_setup.route_s.namespace}/{v_s_route_setup.route_s.name}" vsr_1_event_text = f"Configuration for {vsr_1_name} was added or updated" vs_event_text = f"Configuration for {vs_name} was added or updated" vs_warning_event_text = f"Configuration for {vs_name} was added or updated with warning(s): VirtualServerRoute {vsr_1_name} doesn't exist or invalid" vsr_2_event_text = f"Configuration for {vsr_2_name} was added or updated" initial_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) print("\nStep 1: initial check") 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_m.paths[1]}", headers={"host": v_s_route_setup.vs_host}) resp_3 = requests.get(f"{req_url}{v_s_route_setup.route_s.paths[0]}", headers={"host": v_s_route_setup.vs_host}) events_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace) events_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace) assert_responses_and_server_name(resp_1, resp_2, resp_3) assert_locations_in_config(initial_config, v_s_route_setup.route_m.paths) assert_locations_in_config(initial_config, v_s_route_setup.route_s.paths) initial_count_vsr_1 = assert_event_and_get_count( vsr_1_event_text, events_ns_1) initial_count_vs = assert_event_and_get_count(vs_event_text, events_ns_1) initial_count_vsr_2 = assert_event_and_get_count( vsr_2_event_text, events_ns_2) print("\nStep 2: update multiple VSRoute and check") patch_v_s_route_from_yaml( kube_apis.custom_objects, v_s_route_setup.route_m.name, f"{TEST_DATA}/virtual-server-route/route-multiple-updated.yaml", v_s_route_setup.route_m.namespace) new_vsr_paths = get_paths_from_vsr_yaml( f"{TEST_DATA}/virtual-server-route/route-multiple-updated.yaml") wait_before_test(1) resp_1 = requests.get(f"{req_url}{new_vsr_paths[0]}", headers={"host": v_s_route_setup.vs_host}) resp_2 = requests.get(f"{req_url}{new_vsr_paths[1]}", headers={"host": v_s_route_setup.vs_host}) resp_3 = requests.get(f"{req_url}{v_s_route_setup.route_s.paths[0]}", headers={"host": v_s_route_setup.vs_host}) assert_responses_and_server_name(resp_1, resp_2, resp_3) events_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace) events_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace) assert_event_and_count(vsr_1_event_text, initial_count_vsr_1 + 1, events_ns_1) assert_event_with_full_equality_and_count(vs_event_text, initial_count_vs + 1, events_ns_1) # 2nd VSRoute gets an event about update too assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 1, events_ns_2) print("\nStep 3: restore VSRoute and check") patch_v_s_route_from_yaml( kube_apis.custom_objects, v_s_route_setup.route_m.name, f"{TEST_DATA}/virtual-server-route/route-multiple.yaml", v_s_route_setup.route_m.namespace) wait_before_test(1) 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_m.paths[1]}", headers={"host": v_s_route_setup.vs_host}) resp_3 = requests.get(f"{req_url}{v_s_route_setup.route_s.paths[0]}", headers={"host": v_s_route_setup.vs_host}) assert_responses_and_server_name(resp_1, resp_2, resp_3) events_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace) events_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace) assert_event_and_count(vsr_1_event_text, initial_count_vsr_1 + 2, events_ns_1) assert_event_with_full_equality_and_count(vs_event_text, initial_count_vs + 2, events_ns_1) assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 2, events_ns_2) print("\nStep 4: update one backend service port and check") svc_1 = read_service(kube_apis.v1, "backend1-svc", v_s_route_setup.route_m.namespace) svc_1.spec.ports[0].port = 8080 replace_service(kube_apis.v1, "backend1-svc", v_s_route_setup.route_m.namespace, svc_1) wait_before_test(1) 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_m.paths[1]}", headers={"host": v_s_route_setup.vs_host}) assert resp_1.status_code == 502 assert resp_2.status_code == 200 events_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace) events_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace) assert_event_and_count(vsr_1_event_text, initial_count_vsr_1 + 3, events_ns_1) assert_event_with_full_equality_and_count(vs_event_text, initial_count_vs + 3, events_ns_1) assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 3, events_ns_2) print("\nStep 5: restore backend service and check") svc_1 = read_service(kube_apis.v1, "backend1-svc", v_s_route_setup.route_m.namespace) svc_1.spec.ports[0].port = 80 replace_service(kube_apis.v1, "backend1-svc", v_s_route_setup.route_m.namespace, svc_1) wait_before_test(1) 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_m.paths[1]}", headers={"host": v_s_route_setup.vs_host}) assert resp_1.status_code == 200 assert resp_2.status_code == 200 events_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace) events_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace) assert_event_and_count(vsr_1_event_text, initial_count_vsr_1 + 4, events_ns_1) assert_event_with_full_equality_and_count(vs_event_text, initial_count_vs + 4, events_ns_1) assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 4, events_ns_2) print("\nStep 6: remove VSRoute and check") delete_v_s_route(kube_apis.custom_objects, v_s_route_setup.route_m.name, v_s_route_setup.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) 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_m.paths[1]}", headers={"host": v_s_route_setup.vs_host}) resp_3 = requests.get(f"{req_url}{v_s_route_setup.route_s.paths[0]}", headers={"host": v_s_route_setup.vs_host}) assert resp_1.status_code == 404 assert resp_2.status_code == 404 assert resp_3.status_code == 200 events_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace) events_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace) assert_locations_not_in_config(new_config, v_s_route_setup.route_m.paths) assert_event_and_count(vsr_1_event_text, initial_count_vsr_1 + 4, events_ns_1) assert_event_with_full_equality_and_count(vs_event_text, initial_count_vs + 4, events_ns_1) # a warning event because the VS references a non-existing VSR assert_event_with_full_equality_and_count(vs_warning_event_text, 1, events_ns_1) assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 5, events_ns_2) print("\nStep 7: restore VSRoute and check") create_v_s_route_from_yaml( kube_apis.custom_objects, f"{TEST_DATA}/virtual-server-route/route-multiple.yaml", v_s_route_setup.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) 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_m.paths[1]}", headers={"host": v_s_route_setup.vs_host}) resp_3 = requests.get(f"{req_url}{v_s_route_setup.route_s.paths[0]}", headers={"host": v_s_route_setup.vs_host}) assert_responses_and_server_name(resp_1, resp_2, resp_3) events_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace) events_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace) assert_locations_in_config(new_config, v_s_route_setup.route_m.paths) assert_event_and_count(vsr_1_event_text, 1, events_ns_1) assert_event_with_full_equality_and_count(vs_event_text, initial_count_vs + 5, events_ns_1) assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 6, events_ns_2) print("\nStep 8: remove one backend service and check") delete_service(kube_apis.v1, "backend1-svc", v_s_route_setup.route_m.namespace) wait_before_test(1) 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_m.paths[1]}", headers={"host": v_s_route_setup.vs_host}) resp_3 = requests.get(f"{req_url}{v_s_route_setup.route_s.paths[0]}", headers={"host": v_s_route_setup.vs_host}) assert resp_1.status_code == 502 assert resp_2.status_code == 200 assert resp_3.status_code == 200 events_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace) events_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace) assert_event_and_count(vsr_1_event_text, 2, events_ns_1) assert_event_with_full_equality_and_count(vs_event_text, initial_count_vs + 6, events_ns_1) assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 7, events_ns_2) print("\nStep 9: restore backend service and check") create_service_with_name(kube_apis.v1, v_s_route_setup.route_m.namespace, "backend1-svc") wait_before_test(1) 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_m.paths[1]}", headers={"host": v_s_route_setup.vs_host}) resp_3 = requests.get(f"{req_url}{v_s_route_setup.route_s.paths[0]}", headers={"host": v_s_route_setup.vs_host}) assert_responses_and_server_name(resp_1, resp_2, resp_3) events_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace) events_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace) assert_event_and_count(vsr_1_event_text, 3, events_ns_1) assert_event_with_full_equality_and_count(vs_event_text, initial_count_vs + 7, events_ns_1) assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 8, events_ns_2) print("\nStep 10: remove VS and check") delete_virtual_server(kube_apis.custom_objects, v_s_route_setup.vs_name, v_s_route_setup.namespace) wait_before_test(1) 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_m.paths[1]}", headers={"host": v_s_route_setup.vs_host}) resp_3 = requests.get(f"{req_url}{v_s_route_setup.route_s.paths[0]}", headers={"host": v_s_route_setup.vs_host}) assert resp_1.status_code == 404 assert resp_2.status_code == 404 assert resp_3.status_code == 404 list0_list_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace) list0_list_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace) assert_event_and_count(vsr_1_event_text, 3, list0_list_ns_1) assert_event_with_full_equality_and_count(vs_event_text, initial_count_vs + 7, list0_list_ns_1) assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 8, list0_list_ns_2) print("\nStep 11: restore VS and check") create_virtual_server_from_yaml( kube_apis.custom_objects, f"{TEST_DATA}/virtual-server-route/standard/virtual-server.yaml", v_s_route_setup.namespace) wait_before_test(1) 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_m.paths[1]}", headers={"host": v_s_route_setup.vs_host}) resp_3 = requests.get(f"{req_url}{v_s_route_setup.route_s.paths[0]}", headers={"host": v_s_route_setup.vs_host}) assert_responses_and_server_name(resp_1, resp_2, resp_3) list1_list_ns_1 = get_events(kube_apis.v1, v_s_route_setup.route_m.namespace) list1_list_ns_2 = get_events(kube_apis.v1, v_s_route_setup.route_s.namespace) assert_event_and_count(vsr_1_event_text, 4, list1_list_ns_1) assert_event_with_full_equality_and_count(vs_event_text, 1, list1_list_ns_1) assert_event_and_count(vsr_2_event_text, initial_count_vsr_2 + 9, list1_list_ns_2)
def v_s_route_setup(request, kube_apis, ingress_controller_endpoint) -> VirtualServerRouteSetup: """ Prepare Virtual Server Route Example. 1st namespace with VS and 1st addressed VSR and 2nd namespace with second addressed VSR. :param request: internal pytest fixture to parametrize this method: {example: virtual-server|virtual-server-tls|...} 'example' is a directory name in TEST_DATA :param kube_apis: client apis :param crd_ingress_controller: :param ingress_controller_endpoint: :return: VirtualServerRouteSetup """ vs_routes_ns = get_route_namespace_from_vs_yaml( f"{TEST_DATA}/{request.param['example']}/standard/virtual-server.yaml") ns_1 = create_namespace_with_name_from_yaml(kube_apis.v1, vs_routes_ns[0], f"{TEST_DATA}/common/ns.yaml") ns_2 = create_namespace_with_name_from_yaml(kube_apis.v1, vs_routes_ns[1], f"{TEST_DATA}/common/ns.yaml") print( "------------------------- Deploy Virtual Server -----------------------------------" ) vs_name = create_virtual_server_from_yaml( kube_apis.custom_objects, f"{TEST_DATA}/{request.param['example']}/standard/virtual-server.yaml", ns_1, ) vs_host = get_first_host_from_yaml( f"{TEST_DATA}/{request.param['example']}/standard/virtual-server.yaml") print( "------------------------- Deploy Virtual Server Routes -----------------------------------" ) vsr_m_name = create_v_s_route_from_yaml( kube_apis.custom_objects, f"{TEST_DATA}/{request.param['example']}/route-multiple.yaml", ns_1, ) vsr_m_paths = get_paths_from_vsr_yaml( f"{TEST_DATA}/{request.param['example']}/route-multiple.yaml") route_m = VirtualServerRoute(ns_1, vsr_m_name, vsr_m_paths) vsr_s_name = create_v_s_route_from_yaml( kube_apis.custom_objects, f"{TEST_DATA}/{request.param['example']}/route-single.yaml", ns_2) vsr_s_paths = get_paths_from_vsr_yaml( f"{TEST_DATA}/{request.param['example']}/route-single.yaml") route_s = VirtualServerRoute(ns_2, vsr_s_name, vsr_s_paths) def fin(): print("Clean up the Virtual Server Route:") delete_v_s_route(kube_apis.custom_objects, vsr_m_name, ns_1) delete_v_s_route(kube_apis.custom_objects, vsr_s_name, ns_2) print("Clean up Virtual Server:") delete_virtual_server(kube_apis.custom_objects, vs_name, ns_1) print("Delete test namespaces") delete_namespace(kube_apis.v1, ns_1) delete_namespace(kube_apis.v1, ns_2) request.addfinalizer(fin) return VirtualServerRouteSetup(ingress_controller_endpoint, ns_1, vs_host, vs_name, route_m, route_s)
def vsr_externalname_setup( request, kube_apis, ingress_controller_prerequisites, ingress_controller_endpoint) -> ReducedVirtualServerRouteSetup: """ Prepare an example app for Virtual Server Route. 1st namespace with externalName svc and VS+VSR. :param request: internal pytest fixture :param kube_apis: client apis :param ingress_controller_endpoint: :param ingress_controller_prerequisites: :return: """ vs_routes_ns = get_route_namespace_from_vs_yaml( f"{TEST_DATA}/{request.param['example']}/standard/virtual-server.yaml") ns_1 = create_namespace_with_name_from_yaml(kube_apis.v1, vs_routes_ns[0], f"{TEST_DATA}/common/ns.yaml") print( "------------------------- Deploy External-Backend -----------------------------------" ) external_ns = create_namespace_with_name_from_yaml( kube_apis.v1, "external-ns", f"{TEST_DATA}/common/ns.yaml") external_svc_name = create_service_with_name(kube_apis.v1, external_ns, "external-backend-svc") create_deployment_with_name(kube_apis.apps_v1_api, external_ns, "external-backend") print( "------------------------- Deploy Virtual Server -----------------------------------" ) vs_name = create_virtual_server_from_yaml( kube_apis.custom_objects, f"{TEST_DATA}/{request.param['example']}/standard/virtual-server.yaml", ns_1) vs_host = get_first_host_from_yaml( f"{TEST_DATA}/{request.param['example']}/standard/virtual-server.yaml") print( "------------------------- Deploy Virtual Server Route -----------------------------------" ) vsr_name = create_v_s_route_from_yaml( kube_apis.custom_objects, f"{TEST_DATA}/{request.param['example']}/route-single.yaml", ns_1) vsr_paths = get_paths_from_vsr_yaml( f"{TEST_DATA}/{request.param['example']}/route-single.yaml") route = VirtualServerRoute(ns_1, vsr_name, vsr_paths) print( "---------------------- Deploy ExternalName service and update ConfigMap ----------------------------" ) 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}/{request.param['example']}/nginx-config.yaml") external_svc_host = f"{external_svc_name}.{external_ns}.svc.cluster.local" svc_name = create_service_from_yaml( kube_apis.v1, ns_1, f"{TEST_DATA}/{request.param['example']}/externalname-svc.yaml") wait_before_test(2) req_url = f"http://{ingress_controller_endpoint.public_ip}:{ingress_controller_endpoint.port}" ensure_response_from_backend(f"{req_url}{route.paths[0]}", vs_host) def fin(): print("Delete test namespaces") delete_namespace(kube_apis.v1, external_ns) delete_namespace(kube_apis.v1, ns_1) request.addfinalizer(fin) return ReducedVirtualServerRouteSetup(ingress_controller_endpoint, ns_1, vs_host, vs_name, route, svc_name, external_svc_host)