Пример #1
0
 def test_responses_after_setup(self, kube_apis,
                                crd_ingress_controller_with_ed,
                                create_externaldns, virtual_server_setup):
     print("\nStep 1: Verify DNSEndpoint exists")
     dns_name = get_first_host_from_yaml(VS_YAML)
     retry = 0
     dep = is_dnsendpoint_present(kube_apis.custom_objects, dns_name,
                                  virtual_server_setup.namespace)
     while dep == False and retry <= 60:
         dep = is_dnsendpoint_present(kube_apis.custom_objects, dns_name,
                                      virtual_server_setup.namespace)
         retry += 1
         wait_before_test(1)
         print(f"DNSEndpoint not created, retrying... #{retry}")
     assert (dep is True)
     print("\nStep 2: Verify external-dns picked up the record")
     pod_ns = get_namespace_from_yaml(
         f"{TEST_DATA}/virtual-server-external-dns/external-dns.yaml")
     pod_name = kube_apis.v1.list_namespaced_pod(
         pod_ns).items[0].metadata.name
     log_contents = kube_apis.v1.read_namespaced_pod_log(pod_name, pod_ns)
     wanted_string = "CREATE: virtual-server.example.com 0 IN A"
     retry = 0
     while wanted_string not in log_contents and retry <= 60:
         log_contents = kube_apis.v1.read_namespaced_pod_log(
             pod_name, pod_ns)
         retry += 1
         wait_before_test(1)
         print(f"External DNS not updated, retrying... #{retry}")
     assert (wanted_string in log_contents)
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_vs_setup(kube_apis, test_namespace, policy_method) -> tuple:
    src_pol_name, vs_name = ap_generic_setup(kube_apis, test_namespace,
                                             test_namespace, policy_method,
                                             waf_spec_vs_src)
    vs_host = get_first_host_from_yaml(waf_spec_vs_src)
    vs_paths = get_paths_from_vs_yaml(waf_spec_vs_src)
    return (src_pol_name, vs_name, vs_host, vs_paths)
Пример #4
0
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 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)
Пример #6
0
def transport_server_tls_passthrough_setup(
        request, kube_apis, test_namespace,
        ingress_controller_endpoint) -> TransportServerTlsSetup:
    """
    Prepare Transport Server Example.

    :param request: internal pytest fixture to parametrize this method
    :param kube_apis: client apis
    :param test_namespace: namespace for test resources
    :param ingress_controller_endpoint: ip and port information
    :return TransportServerTlsSetup:
    """
    print(
        "------------------------- Deploy Transport Server with tls passthrough -----------------------------------"
    )
    # deploy secure_app
    secure_app_file = f"{TEST_DATA}/{request.param['example']}/standard/secure-app.yaml"
    create_items_from_yaml(kube_apis, secure_app_file, test_namespace)

    # deploy transport server
    transport_server_std_src = f"{TEST_DATA}/{request.param['example']}/standard/transport-server.yaml"
    ts_resource = create_ts_from_yaml(kube_apis.custom_objects,
                                      transport_server_std_src, test_namespace)
    ts_host = get_first_host_from_yaml(transport_server_std_src)
    wait_until_all_pods_are_ready(kube_apis.v1, test_namespace)

    def fin():
        print("Clean up TransportServer and app:")
        delete_ts(kube_apis.custom_objects, ts_resource, test_namespace)
        delete_items_from_yaml(kube_apis, secure_app_file, test_namespace)

    request.addfinalizer(fin)

    return TransportServerTlsSetup(
        ingress_controller_endpoint,
        ts_resource,
        ts_resource["metadata"]["name"],
        test_namespace,
        ts_host,
    )
Пример #7
0
def virtual_server_setup(request, kube_apis, ingress_controller_endpoint,
                         test_namespace) -> VirtualServerSetup:
    """
    Prepare Virtual Server Example.

    :param request: internal pytest fixture to parametrize this method:
        {example: virtual-server|virtual-server-tls|..., app_type: simple|split|...}
        'example' is a directory name in TEST_DATA,
        'app_type' is a directory name in TEST_DATA/common/app
    :param kube_apis: client apis
    :param crd_ingress_controller:
    :param ingress_controller_endpoint:
    :param test_namespace:
    :return: VirtualServerSetup
    """
    print(
        "------------------------- Deploy Virtual Server Example -----------------------------------"
    )
    vs_source = f"{TEST_DATA}/{request.param['example']}/standard/virtual-server.yaml"
    vs_name = create_virtual_server_from_yaml(kube_apis.custom_objects,
                                              vs_source, test_namespace)
    vs_host = get_first_host_from_yaml(vs_source)
    vs_paths = get_paths_from_vs_yaml(vs_source)
    if request.param["app_type"]:
        create_example_app(kube_apis, request.param["app_type"],
                           test_namespace)
        wait_until_all_pods_are_ready(kube_apis.v1, test_namespace)

    def fin():
        print("Clean up Virtual Server Example:")
        delete_virtual_server(kube_apis.custom_objects, vs_name,
                              test_namespace)
        if request.param["app_type"]:
            delete_common_app(kube_apis, request.param["app_type"],
                              test_namespace)

    request.addfinalizer(fin)

    return VirtualServerSetup(ingress_controller_endpoint, test_namespace,
                              vs_host, vs_name, vs_paths)
    def test_responses_after_virtual_server_update(self, kube_apis, crd_ingress_controller, virtual_server_setup):
        print("Step 2: update host and paths in the VS and check")
        patch_virtual_server_from_yaml(kube_apis.custom_objects, virtual_server_setup.vs_name,
                                       f"{TEST_DATA}/virtual-server/standard/virtual-server-updated.yaml",
                                       virtual_server_setup.namespace)
        new_paths = get_paths_from_vs_yaml(f"{TEST_DATA}/virtual-server/standard/virtual-server-updated.yaml")
        new_backend_1_url = f"http://{virtual_server_setup.public_endpoint.public_ip}" \
            f":{virtual_server_setup.public_endpoint.port}/{new_paths[0]}"
        new_backend_2_url = f"http://{virtual_server_setup.public_endpoint.public_ip}" \
            f":{virtual_server_setup.public_endpoint.port}/{new_paths[1]}"
        new_host = get_first_host_from_yaml(f"{TEST_DATA}/virtual-server/standard/virtual-server-updated.yaml")
        wait_before_test(1)
        resp = requests.get(virtual_server_setup.backend_1_url,
                            headers={"host": virtual_server_setup.vs_host})
        assert resp.status_code == 404
        resp = requests.get(virtual_server_setup.backend_2_url,
                            headers={"host": virtual_server_setup.vs_host})
        assert resp.status_code == 404
        resp = requests.get(new_backend_1_url, headers={"host": new_host})
        assert resp.status_code == 200
        resp = requests.get(new_backend_2_url, headers={"host": new_host})
        assert resp.status_code == 200

        print("Step 3: restore VS and check")
        patch_virtual_server_from_yaml(kube_apis.custom_objects, virtual_server_setup.vs_name,
                                       f"{TEST_DATA}/virtual-server/standard/virtual-server.yaml",
                                       virtual_server_setup.namespace)
        wait_before_test(1)
        resp = requests.get(new_backend_1_url, headers={"host": new_host})
        assert resp.status_code == 404
        resp = requests.get(new_backend_2_url, headers={"host": new_host})
        assert resp.status_code == 404
        resp = requests.get(virtual_server_setup.backend_1_url,
                            headers={"host": virtual_server_setup.vs_host})
        assert resp.status_code == 200
        resp = requests.get(virtual_server_setup.backend_2_url,
                            headers={"host": virtual_server_setup.vs_host})
        assert resp.status_code == 200
Пример #9
0
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)