def Setup():
    # execute.execute_unix_command("kubectl create -f /tmp/clusternetwork-test/templates/cnet_attach.yaml")
    network_attach_test = common_utils.get_helm_chart_content(
        "default/network-attach-test")
    compare_test_data(network_attach_test, network_attach_properties)
    replace_ifaces_in_fetched_chart_templates(
        "/tmp/network-attach-test/templates/*")
    danm_utils.create_resources_from_fetched_chart_templates(
        "/tmp/network-attach-test/templates")

    install_chart(danmnet_pods1)
    common_utils.test_kubernetes_object_quality(
        kube_object=danmnet_pods1,
        expected_result=danmnet_pods1['obj_count'],
        filter=r'(Running)\s*[0]',
        timeout=90)
    install_chart(danmnet_pods2)
    install_chart(danmnet_pods3)
    # install_chart(danmnet_pods4)
    install_chart(danmnet_pods5)
    install_chart(danmnet_pods6)
    install_chart(danmnet_pods7)
    install_chart(danmnet_pods8)
    install_chart(danmnet_pods9)
    install_chart(danmnet_pods10)
def Setup():
    cnet_test = common_utils.get_helm_chart_content(
        "default/clusternetwork-test")
    danm_utils.compare_test_data(cnet_test, clusternetworks_properties)

    cnet_test_error = common_utils.get_helm_chart_content(
        "default/clusternetwork-test-error")
    danm_utils.compare_test_data(cnet_test_error,
                                 clusternetworks_error_properties)

    tenantconfig_test = common_utils.get_helm_chart_content(
        "default/tenantconfig-test")
    danm_utils.compare_test_data(tenantconfig_test, tenantconfig_properties)

    tenantconfig_test_error = common_utils.get_helm_chart_content(
        "default/tenantconfig-test-error")
    danm_utils.compare_test_data(tenantconfig_test_error,
                                 tenantconfig_error_properties)

    tenantnetwork_test = common_utils.get_helm_chart_content(
        "default/tenantnetwork-test")
    danm_utils.compare_test_data(tenantnetwork_test, tenantnetwork_properties)

    tenantnetwork_test_error = common_utils.get_helm_chart_content(
        "default/tenantnetwork-test-error")
    danm_utils.compare_test_data(tenantnetwork_test_error,
                                 tenantnetwork_error_properties)
def Setup():
    tennet_attach_test = common_utils.get_helm_chart_content(
        "default/tenantnetwork-attach-test")
    danm_utils.compare_test_data(tennet_attach_test,
                                 tenantnetwork_attach_properties)

    replace_ifaces_in_fetched_chart_templates(
        "/tmp/tenantnetwork-attach-test/templates/*")
    replace_ifaces_in_fetched_chart_templates(
        "/tmp/tenantconfig-test/templates/*")
    # deploy a valid TenantConfig
    danm_utils.create_resources_from_fetched_chart_templates(
        "/tmp/tenantconfig-test/templates/tconf_05.yaml")
    # remove the default TenantConfig
    execute.execute_unix_command(
        "kubectl delete tenantconfig danm-tenant-config")
    # deploy all TenantNetwork-s
    danm_utils.create_resources_from_fetched_chart_templates(
        "/tmp/tenantnetwork-attach-test/templates")
    set_expected_host_if_in_constants(tenantnetwork_attach_properties)
def step13_check_invalid_net_attach_and_successful_damnep_ip_release_after_retries(
):
    tnet1_alloc_before = danm_utils.get_alloc_value(
        'tennet_attach_01', tenantnetwork_attach_properties, "tenantnetwork")
    tnet5_alloc_before = danm_utils.get_alloc_value(
        'tennet_attach_05', tenantnetwork_attach_properties, "tenantnetwork")
    tnet6_alloc_before = danm_utils.get_alloc_value(
        'tennet_attach_06', tenantnetwork_attach_properties, "tenantnetwork")
    common_utils.get_helm_chart_content("default/tenantnetwork-attach-pod11")
    common_utils.get_helm_chart_content("default/tenantnetwork-attach-pod13")

    execute.execute_unix_command(
        "sed -i 's/{{ .Values.registry_url }}/" + reg + "/g' " +
        "/tmp/tenantnetwork-attach-pod11/templates/tennet_pod_11.yaml")
    execute.execute_unix_command(
        "sed -i 's/{{ .Values.registry_url }}/" + reg + "/g' " +
        "/tmp/tenantnetwork-attach-pod13/templates/tennet_pod_13.yaml")

    for _ in range(0, 10):
        danm_utils.create_resources_from_fetched_chart_templates(
            "/tmp/tenantnetwork-attach-pod11/templates")
        danm_utils.create_resources_from_fetched_chart_templates(
            "/tmp/tenantnetwork-attach-pod13/templates")
        common_utils.test_kubernetes_object_quality(
            kube_object=tennet_pod11,
            expected_result=tennet_pod11['obj_count'],
            filter=r'(ContainerCreating)\s*[0]',
            timeout=40)
        common_utils.test_kubernetes_object_quality(
            kube_object=tennet_pod13,
            expected_result=tennet_pod13['obj_count'],
            filter=r'(ContainerCreating)\s*[0]',
            timeout=40)
        danm_utils.delete_resources_by_manifest_path(
            "/tmp/tenantnetwork-attach-pod11/templates")
        danm_utils.delete_resources_by_manifest_path(
            "/tmp/tenantnetwork-attach-pod13/templates")
        common_utils.check_kubernetes_object(
            kube_object=tennet_pod11,
            tester_function=common_utils.test_kubernetes_object_not_available,
            timeout=40)
        common_utils.check_kubernetes_object(
            kube_object=tennet_pod13,
            tester_function=common_utils.test_kubernetes_object_not_available,
            timeout=40)

    tnet1_alloc_after = danm_utils.get_alloc_value(
        'tennet_attach_01', tenantnetwork_attach_properties, 'tenantnetwork')
    tnet5_alloc_after = danm_utils.get_alloc_value(
        'tennet_attach_05', tenantnetwork_attach_properties, 'tenantnetwork')
    tnet6_alloc_after = danm_utils.get_alloc_value(
        'tennet_attach_06', tenantnetwork_attach_properties, 'tenantnetwork')
    if tnet1_alloc_before != tnet1_alloc_after:
        raise Exception(
            "allocation value in tennet_attach_01 is not as expected")
    if tnet5_alloc_before != tnet5_alloc_after:
        raise Exception(
            "allocation value in tennet_attach_05 is not as expected")
    if tnet6_alloc_before != tnet6_alloc_after:
        raise Exception(
            "allocation value in tennet_attach_06 is not as expected")
    danm_utils.check_dep_count('default', exp_count=0)
def step13():
    # danmnet_pods11, danmnet_pods13 has invalid networks attached hance the pod creation will fail,
    # checking if danmnet endpoints, ips are cleared after several unsuccessful pod creations
    alloc_before_cnet_pod5 = get_alloc_value('cnet_pod5',
                                             network_attach_properties,
                                             'clusternetwork')
    alloc_before_cnet_pod6 = get_alloc_value('cnet_pod6',
                                             network_attach_properties,
                                             'clusternetwork')
    common_utils.get_helm_chart_content('default/' +
                                        danmnet_pods11['obj_name'])
    execute.execute_unix_command("sed -i 's/{{ .Values.registry_url }}/" +
                                 reg + "/g' " + "/tmp/" +
                                 danmnet_pods11['obj_name'] + "/templates/" +
                                 danmnet_pods11['obj_name'] + ".yaml")
    common_utils.get_helm_chart_content('default/' +
                                        danmnet_pods13['obj_name'])
    execute.execute_unix_command("sed -i 's/{{ .Values.registry_url }}/" +
                                 reg + "/g' " + "/tmp/" +
                                 danmnet_pods13['obj_name'] + "/templates/" +
                                 danmnet_pods13['obj_name'] + ".yaml")
    command = "ls -rt /var/lib/cni/networks/cbr0/ | wc -l"
    ip_count_before = execute.execute_unix_command_as_root(command)
    command = "ls -rt /var/lib/cni/networks/cbr0/"
    cbr0_content1 = execute.execute_unix_command_as_root(command)

    for _ in range(0, 10):
        # danmnet_pods11 creation fails
        command = "kubectl create -f /tmp/" + danmnet_pods11[
            'obj_name'] + "/templates"
        execute.execute_unix_command_as_root(command)

        # danmnet_pods13 creation fails
        command = "kubectl create -f /tmp/" + danmnet_pods13[
            'obj_name'] + "/templates"
        execute.execute_unix_command_as_root(command)
        common_utils.test_kubernetes_object_quality(
            kube_object=danmnet_pods11,
            expected_result=danmnet_pods11['obj_count'],
            filter=r'(ContainerCreating)\s*[0]',
            timeout=40)
        common_utils.test_kubernetes_object_quality(
            kube_object=danmnet_pods13,
            expected_result=danmnet_pods13['obj_count'],
            filter=r'(ContainerCreating)\s*[0]',
            timeout=40)
        command = "kubectl delete -f /tmp/" + danmnet_pods11[
            'obj_name'] + "/templates"
        execute.execute_unix_command_as_root(command)
        command = "kubectl delete -f /tmp/" + danmnet_pods13[
            'obj_name'] + "/templates"
        execute.execute_unix_command_as_root(command)
        common_utils.check_kubernetes_object(
            kube_object=danmnet_pods11,
            tester_function=common_utils.test_kubernetes_object_not_available,
            timeout=40)
        common_utils.check_kubernetes_object(
            kube_object=danmnet_pods13,
            tester_function=common_utils.test_kubernetes_object_not_available,
            timeout=40)
    check_danm_count(ip_count_before, cbr0_content1, 0)
    logger.info("All flannel ips are cleared")
    alloc_after_cnet_pod5 = get_alloc_value('cnet_pod5',
                                            network_attach_properties,
                                            'clusternetwork')
    alloc_after_cnet_pod6 = get_alloc_value('cnet_pod6',
                                            network_attach_properties,
                                            'clusternetwork')
    if alloc_after_cnet_pod6 != alloc_before_cnet_pod6:
        raise Exception("allocation value in cnet-pod6 is not as expected")
    if alloc_after_cnet_pod5 != alloc_before_cnet_pod5:
        raise Exception("allocation value in cnet-pod5 is not as expected")
    check_dep_count('default', exp_count=0)