コード例 #1
0
ファイル: test_copp.py プロジェクト: judyjoseph/sonic-mgmt
def _teardown_multi_asic_proxy(dut, creds, test_params, tbinfo):
    """
        Tears down multi asic proxy settings, returning it to its initial state.
    """
    if not dut.is_multi_asic:
        return

    logging.info("Removing iptables rules and disabling eth0 port forwarding")
    http_proxy, https_proxy = copp_utils._get_http_and_https_proxy_ip(creds)
    dut.command("sudo sysctl net.ipv4.conf.eth0.forwarding=0")
    # Delete IP Table rule for http and ptf nn_agent traffic.
    mgmt_ip = dut.host.options["inventory_manager"].get_host(
        dut.hostname).vars["ansible_host"]
    # Delete Rule to communicate to http/s proxy from namespace
    dut.command(
        "sudo iptables -t nat -D POSTROUTING -p tcp --dport 8080 -j SNAT --to-source {}"
        .format(mgmt_ip))
    dut.command(
        "sudo ip -n {} rule delete from all to {} pref 1 lookup default".
        format(test_params.nn_target_namespace, http_proxy))
    if http_proxy != https_proxy:
        dut.command(
            "sudo ip -n {} rule delete from all to {} pref 2 lookup default".
            format(test_params.nn_target_namespace, https_proxy))
    # Delete Rule to communicate to ptf nn agent client from namespace
    ns_ip = dut.shell("sudo ip -n {} -4 -o addr show eth0".format(
        test_params.nn_target_namespace) +
                      " | awk '{print $4}' | cut -d'/' -f1")["stdout"]
    dut.command(
        "sudo iptables -t nat -D PREROUTING -p tcp --dport 10900 -j DNAT --to-destination {}"
        .format(ns_ip))
    dut.command(
        "sudo ip -n {} rule delete from {} to {} pref 3 lookup default".format(
            test_params.nn_target_namespace, ns_ip, tbinfo["ptf_ip"]))
コード例 #2
0
ファイル: test_copp.py プロジェクト: judyjoseph/sonic-mgmt
def _setup_multi_asic_proxy(dut, creds, test_params, tbinfo):
    """
        Sets up the testbed to run the COPP tests on multi-asic platfroms via setting proxy.
    """
    if not dut.is_multi_asic:
        return

    logging.info("Adding iptables rules and enabling eth0 port forwarding")
    http_proxy, https_proxy = copp_utils._get_http_and_https_proxy_ip(creds)
    # Add IP Table rule for http and ptf nn_agent traffic.
    dut.command("sudo sysctl net.ipv4.conf.eth0.forwarding=1")
    mgmt_ip = dut.host.options["inventory_manager"].get_host(
        dut.hostname).vars["ansible_host"]
    # Add Rule to communicate to http/s proxy from namespace
    dut.command(
        "sudo iptables -t nat -A POSTROUTING -p tcp --dport 8080 -j SNAT --to-source {}"
        .format(mgmt_ip))
    dut.command(
        "sudo ip -n {} rule add from all to {} pref 1 lookup default".format(
            test_params.nn_target_namespace, http_proxy))
    if http_proxy != https_proxy:
        dut.command(
            "sudo ip -n {} rule add from all to {} pref 2 lookup default".
            format(test_params.nn_target_namespace, https_proxy))
    # Add Rule to communicate to ptf nn agent client from namespace
    ns_ip = dut.shell("sudo ip -n {} -4 -o addr show eth0".format(
        test_params.nn_target_namespace) +
                      " | awk '{print $4}' | cut -d'/' -f1")["stdout"]
    dut.command(
        "sudo iptables -t nat -A PREROUTING -p tcp --dport 10900 -j DNAT --to-destination {}"
        .format(ns_ip))
    dut.command(
        "sudo ip -n {} rule add from {} to {} pref 3 lookup default".format(
            test_params.nn_target_namespace, ns_ip, tbinfo["ptf_ip"]))