def fin(): print("Clean up External-Name-Example:") replace_configmap(kube_apis.v1, config_map_name, ingress_controller_prerequisites.namespace, ingress_controller_prerequisites.config_map) delete_ingress(kube_apis.extensions_v1_beta1, ingress_name, test_namespace) delete_service(kube_apis.v1, svc_name, test_namespace)
def test_ap_ingress_batch_start( self, request, kube_apis, crd_ingress_controller_with_ap, ap_ingress_setup, ingress_controller_prerequisites, test_namespace, ): """ Pod startup time with AP Ingress """ print( "------------- Run test for AP policy: dataguard-alarm --------------" ) print( f"Request URL: {ap_ingress_setup.req_url} and Host: {ap_ingress_setup.ingress_host}" ) ensure_response_from_backend(ap_ingress_setup.req_url, ap_ingress_setup.ingress_host, check404=True) total_ing = int(request.config.getoption("--batch-resources")) manifest = f"{TEST_DATA}/appprotect/appprotect-ingress.yaml" for i in range(1, total_ing + 1): with open(manifest) as f: doc = yaml.safe_load(f) doc["metadata"]["name"] = f"appprotect-ingress-{i}" doc["spec"]["rules"][0]["host"] = f"appprotect-{i}.example.com" create_ingress(kube_apis.networking_v1, test_namespace, doc) print(f"Total resources deployed is {total_ing}") wait_before_test() ic_ns = ingress_controller_prerequisites.namespace scale_deployment(kube_apis.v1, kube_apis.apps_v1_api, "nginx-ingress", ic_ns, 0) while get_pods_amount(kube_apis.v1, ic_ns) is not 0: print(f"Number of replicas not 0, retrying...") wait_before_test() num = scale_deployment(kube_apis.v1, kube_apis.apps_v1_api, "nginx-ingress", ic_ns, 1) assert (get_total_ingresses(ap_ingress_setup.metrics_url, "nginx") == str(total_ing + 1) and get_last_reload_status( ap_ingress_setup.metrics_url, "nginx") == "1") for i in range(1, total_ing + 1): delete_ingress(kube_apis.networking_v1, f"appprotect-ingress-{i}", test_namespace) assert num is None
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)