示例#1
0
def iptables_test():
    if not tool_exists('iptables'):
        pytest.skip("iptables does not exist")

    rule = "INPUT -i draktest0 -d 239.255.255.0/24 -j DROP"

    assert not iptable_rule_exists(rule)

    add_iptable_rule(rule)
    assert iptable_rule_exists(rule) is True

    # adding second time also
    add_iptable_rule(rule)

    # it should not be added second time
    assert count_num_rules(rule) == 1

    # if somehow added due to unknown issues

    # this call is adding the rule again to test if del_iptable_rule does delete multiple similar rules or not
    subprocess.check_output(f"iptables -A {rule}", shell=True)

    # the clear should delete all the same rules
    del_iptable_rule(rule)
    assert not iptable_rule_exists(rule)
示例#2
0
def network_setup_test():
    if not tool_exists('brctl'):
        pytest.skip("brctl does not exist")

    setup_vm_network(1, True, find_default_interface(), '8.8.8.8')
    assert iptable_rule_exists(
        "INPUT -i drak1 -p udp --dport 67:68 --sport 67:68 -j ACCEPT") is True

    # setting up network again should not run
    setup_vm_network(1, True, find_default_interface(), '8.8.8.8')
示例#3
0
def dnsmasq_start_test():
    if not tool_exists('dnsmasq'):
        pytest.skip("dnsmasq does not exist")

    # stale dnsmasq will create issues with the stopping test
    dnsmasq_pids = Path('/var/run/').glob("dnsmasq-vm*.pid")
    for pid in dnsmasq_pids:
        subprocess.run(['pkill', '-F', str(pid)])

    start_dnsmasq(1, '8.8.8.8', True)
    cmd = subprocess.run(['pgrep', '-F', '/var/run/dnsmasq-vm1.pid'])
    assert cmd.returncode == 0

    # starting already stopped dnsmasq
    # what should be the expected behavior?
    start_dnsmasq(1, '8.8.8.8', True)
def dnsmasq_start_test():
    if not tool_exists("dnsmasq"):
        pytest.skip("dnsmasq does not exist")

    # stale dnsmasq will create issues with the stopping test
    dnsmasq_pids = Path("/var/run/").glob("dnsmasq-vm*.pid")
    for pid in dnsmasq_pids:
        subprocess.run(["pkill", "-F", str(pid)])

    start_dnsmasq(10, "8.8.8.8", True)

    # wait up to 10 seconds for the pidfile to appear
    for _ in range(10):
        cmd = subprocess.run(["pgrep", "-F", "/var/run/dnsmasq-vm10.pid"])
        # we can break, pidfile appeared
        if cmd.returncode == 0:
            break
        time.sleep(1.0)

    assert cmd.returncode == 0

    # starting already stopped dnsmasq
    # what should be the expected behavior?
    start_dnsmasq(10, "8.8.8.8", True)
示例#5
0
def tcpdump_collector_test():
    if not tool_exists('tcpdump'):
        pytest.skip("tcpdump does not exist")

    pytest.skip("No specific tests required at this stage")
示例#6
0

@depends_on(dnsmasq_start_test)
def dnsmasq_stop_test():
    stop_dnsmasq(1)
    assert subprocess.run(['pgrep', '-F',
                           '/var/run/dnsmasq-vm1.pid']).returncode == 1

    # stopping already stopped dnsmasq
    stop_dnsmasq(1)

    # stopping a non started dnsmasq
    stop_dnsmasq(5)


@pytest.mark.skipif(not tool_exists('tcpdump'),
                    reason="tcpdump does not exist")
@depends_on(network_setup_test)
def tcpdump_collector_test():
    if not tool_exists('tcpdump'):
        pytest.skip("tcpdump does not exist")

    pytest.skip("No specific tests required at this stage")


@depends_on(network_setup_test)
def network_delete_test():
    delete_vm_network(1, True, find_default_interface(), '8.8.8.8')
    assert not iptable_rule_exists(
        "INPUT -i drak1 -p udp --dport 67:68 --sport 67:68 -j ACCEPT")
    start_dnsmasq(10, "8.8.8.8", True)


@depends_on(dnsmasq_start_test)
def dnsmasq_stop_test():
    stop_dnsmasq(10)
    assert subprocess.run(["pgrep", "-F", "/var/run/dnsmasq-vm10.pid"]).returncode == 1

    # stopping already stopped dnsmasq
    stop_dnsmasq(10)

    # stopping a non started dnsmasq
    stop_dnsmasq(5)


@pytest.mark.skipif(not tool_exists("tcpdump"), reason="tcpdump does not exist")
@depends_on(network_setup_test)
def tcpdump_collector_test():
    if not tool_exists("tcpdump"):
        pytest.skip("tcpdump does not exist")

    pytest.skip("No specific tests required at this stage")


@depends_on(network_setup_test)
def network_delete_test():
    delete_vm_network(10, True, find_default_interface(), "8.8.8.8")
    assert not iptable_rule_exists(
        "INPUT -i drak10 -p udp --dport 67:68 --sport 67:68 -j ACCEPT"
    )
示例#8
0

@depends_on(dnsmasq_start_test)
def dnsmasq_stop_test():
    stop_dnsmasq(10)
    assert subprocess.run(["pgrep", "-F",
                           "/var/run/dnsmasq-vm10.pid"]).returncode == 1

    # stopping already stopped dnsmasq
    stop_dnsmasq(10)

    # stopping a non started dnsmasq
    stop_dnsmasq(5)


@pytest.mark.skipif(not tool_exists("tcpdump"),
                    reason="tcpdump does not exist")
@depends_on(network_setup_test)
def tcpdump_collector_test():
    if not tool_exists("tcpdump"):
        pytest.skip("tcpdump does not exist")

    pytest.skip("No specific tests required at this stage")


@depends_on(network_setup_test)
def network_delete_test():
    delete_vm_network(10, True, find_default_interface(), "8.8.8.8")
    assert not iptable_rule_exists(
        "INPUT -i drak10 -p udp --dport 67:68 --sport 67:68 -j ACCEPT")