コード例 #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_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")

    # deleting non existant network should not raise errors but log outputs
    delete_vm_network(1, True, find_default_interface(), '8.8.8.8')
コード例 #3
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')
コード例 #4
0
def test_network_delete():
    delete_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 False