Beispiel #1
0
 def fin():
     print("Clean up:")
     delete_ap_policy(kube_apis.custom_objects, pol_name, test_namespace)
     delete_ap_logconf(kube_apis.custom_objects, log_name, test_namespace)
     delete_common_app(kube_apis, "simple", test_namespace)
     src_sec_yaml = f"{TEST_DATA}/appprotect/appprotect-secret.yaml"
     delete_items_from_yaml(kube_apis, src_sec_yaml, test_namespace)
     write_to_json(f"reload-{get_test_file_name(request.node.fspath)}.json", reload_times)
Beispiel #2
0
 def fin():
     print("Clean up:")
     src_ing_yaml = f"{TEST_DATA}/appprotect/appprotect-ingress.yaml"
     delete_items_from_yaml(kube_apis, src_ing_yaml, test_namespace)
     delete_ap_policy(kube_apis.custom_objects, pol_name, test_namespace)
     delete_ap_logconf(kube_apis.custom_objects, log_name, test_namespace)
     delete_common_app(kube_apis, "simple", test_namespace)
     src_sec_yaml = f"{TEST_DATA}/appprotect/appprotect-secret.yaml"
     delete_items_from_yaml(kube_apis, src_sec_yaml, test_namespace)
 def fin():
     print("Clean up:")
     delete_items_from_yaml(kube_apis, src_syslog_yaml, test_namespace)
     delete_items_from_yaml(kube_apis, src_ing_yaml, test_namespace)
     delete_ap_policy(kube_apis.custom_objects, pol_name, test_namespace)
     delete_ap_logconf(kube_apis.custom_objects, log_name, test_namespace)
     delete_common_app(kube_apis, "grpc", test_namespace)
     delete_items_from_yaml(kube_apis, src_sec_yaml, test_namespace)
     replace_configmap_from_yaml(
         kube_apis.v1,
         ingress_controller_prerequisites.config_map['metadata']['name'],
         ingress_controller_prerequisites.namespace,
         f"{DEPLOYMENTS}/common/nginx-config.yaml")
def cleanup(kube_apis, ingress_controller_prerequisites, src_pol_name,
            test_namespace, vs_or_vsr, vs_name, vsr) -> None:
    vsr_namespace = test_namespace if vs_or_vsr == "vs" else vsr.namespace
    replace_configmap_from_yaml(
        kube_apis.v1,
        ingress_controller_prerequisites.config_map['metadata']['name'],
        ingress_controller_prerequisites.namespace,
        f"{DEPLOYMENTS}/common/nginx-config.yaml")
    delete_ap_logconf(kube_apis.custom_objects, log_name, test_namespace)
    delete_ap_policy(kube_apis.custom_objects, ap_pol_name, test_namespace)
    delete_policy(kube_apis.custom_objects, src_pol_name, vsr_namespace)
    delete_common_app(kube_apis, "grpc-vs", vsr_namespace)
    delete_items_from_yaml(kube_apis, src_syslog_yaml, test_namespace)
    if vs_or_vsr == "vs":
        delete_virtual_server(kube_apis.custom_objects, vs_name,
                              test_namespace)
        delete_items_from_yaml(kube_apis, src_vs_sec_yaml, test_namespace)
    elif vs_or_vsr == "vsr":
        print("Delete test namespaces")
        delete_namespace(kube_apis.v1, vsr.namespace)
 def fin():
     print("Clean up:")
     delete_ap_policy(kube_apis.custom_objects, ap_pol_name, test_namespace)
     delete_ap_usersig(kube_apis.custom_objects, usersig_name, test_namespace)
     delete_ap_logconf(kube_apis.custom_objects, log_name, test_namespace)
def backend_setup(request, kube_apis, ingress_controller_endpoint,
                  ingress_controller_prerequisites,
                  test_namespace) -> BackendSetup:
    """
    Deploy a simple application and AppProtect manifests.

    :param request: pytest fixture
    :param kube_apis: client apis
    :param ingress_controller_endpoint: public endpoint
    :param test_namespace:
    :return: BackendSetup
    """
    try:
        print(
            "------------------------- Replace ConfigMap with HTTP2 -------------------------"
        )
        replace_configmap_from_yaml(
            kube_apis.v1,
            ingress_controller_prerequisites.config_map['metadata']['name'],
            ingress_controller_prerequisites.namespace,
            f"{TEST_DATA}/appprotect/grpc/nginx-config.yaml")

        policy = request.param["policy"]
        print(
            "------------------------- Deploy backend application -------------------------"
        )
        create_example_app(kube_apis, "grpc", test_namespace)
        wait_until_all_pods_are_ready(kube_apis.v1, test_namespace)

        print(
            "------------------------- Deploy Secret -----------------------------"
        )
        src_sec_yaml = f"{TEST_DATA}/appprotect/appprotect-secret.yaml"
        create_items_from_yaml(kube_apis, src_sec_yaml, test_namespace)

        print(
            "------------------------- Deploy logconf -----------------------------"
        )
        src_log_yaml = f"{TEST_DATA}/appprotect/logconf.yaml"
        log_name = create_ap_logconf_from_yaml(kube_apis.custom_objects,
                                               src_log_yaml, test_namespace)

        print(
            f"------------------------- Deploy appolicy: {policy} ---------------------------"
        )
        src_pol_yaml = f"{TEST_DATA}/appprotect/grpc/{policy}.yaml"
        pol_name = create_ap_policy_from_yaml(kube_apis.custom_objects,
                                              src_pol_yaml, test_namespace)

        print(
            "------------------------- Deploy Syslog -----------------------------"
        )
        src_syslog_yaml = f"{TEST_DATA}/appprotect/syslog.yaml"
        create_items_from_yaml(kube_apis, src_syslog_yaml, test_namespace)
        syslog_dst = f"syslog-svc.{test_namespace}"
        print(syslog_dst)
        print(
            "------------------------- Deploy ingress -----------------------------"
        )
        src_ing_yaml = f"{TEST_DATA}/appprotect/grpc/ingress.yaml"
        create_ingress_with_ap_annotations(kube_apis, src_ing_yaml,
                                           test_namespace, policy, "True",
                                           "True", f"{syslog_dst}:514")
        ingress_host = get_first_ingress_host_from_yaml(src_ing_yaml)
        wait_before_test(40)
    except Exception as ex:
        print("Failed to complete setup, cleaning up..")
        delete_items_from_yaml(kube_apis, src_syslog_yaml, test_namespace)
        delete_items_from_yaml(kube_apis, src_ing_yaml, test_namespace)
        delete_ap_policy(kube_apis.custom_objects, pol_name, test_namespace)
        delete_ap_logconf(kube_apis.custom_objects, log_name, test_namespace)
        delete_common_app(kube_apis, "grpc", test_namespace)
        delete_items_from_yaml(kube_apis, src_sec_yaml, test_namespace)
        replace_configmap_from_yaml(
            kube_apis.v1,
            ingress_controller_prerequisites.config_map['metadata']['name'],
            ingress_controller_prerequisites.namespace,
            f"{DEPLOYMENTS}/common/nginx-config.yaml")
        pytest.fail(f"AP GRPC setup failed")

    def fin():
        print("Clean up:")
        delete_items_from_yaml(kube_apis, src_syslog_yaml, test_namespace)
        delete_items_from_yaml(kube_apis, src_ing_yaml, test_namespace)
        delete_ap_policy(kube_apis.custom_objects, pol_name, test_namespace)
        delete_ap_logconf(kube_apis.custom_objects, log_name, test_namespace)
        delete_common_app(kube_apis, "grpc", test_namespace)
        delete_items_from_yaml(kube_apis, src_sec_yaml, test_namespace)
        replace_configmap_from_yaml(
            kube_apis.v1,
            ingress_controller_prerequisites.config_map['metadata']['name'],
            ingress_controller_prerequisites.namespace,
            f"{DEPLOYMENTS}/common/nginx-config.yaml")

    request.addfinalizer(fin)

    return BackendSetup(ingress_host, ingress_controller_endpoint.public_ip,
                        ingress_controller_endpoint.port_ssl)