Beispiel #1
0
def test_get_interface_mask(mocker, output, expected_mask):
    mocker.patch.object(LinuxDevice,
                        "__init__",
                        return_value=None,
                        autospec=True)
    mocker.patch.object(LinuxDevice,
                        "sendline",
                        return_value=None,
                        autospec=True)
    mocker.patch.object(LinuxDevice,
                        "check_output",
                        return_value=None,
                        autospec=True)
    mocker.patch.object(LinuxDevice,
                        "expect",
                        return_value=None,
                        autospec=True)
    regex = [
        r"(?<=netmask )" + ValidIpv4AddressRegex,
        r"(?<=Mask:)" + ValidIpv4AddressRegex,
    ]

    dev = LinuxDevice()
    dev.match = max([re.search(i, output) for i in regex], key=bool)
    print(dev.match)
    assert expected_mask == dev.get_interface_mask("erouter0")
Beispiel #2
0
def test_get_interface_ipaddr(mocker, output, expected_ip):
    mocker.patch.object(LinuxDevice,
                        "__init__",
                        return_value=None,
                        autospec=True)
    mocker.patch.object(LinuxDevice,
                        "sendline",
                        return_value=None,
                        autospec=True)
    mocker.patch.object(LinuxDevice,
                        "check_output",
                        return_value=None,
                        autospec=True)
    mocker.patch.object(LinuxDevice,
                        "expect",
                        return_value=None,
                        autospec=True)
    regex = [
        r"inet:?(?:\s*addr:)?\s*(\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3})\s*(Bcast|P-t-P|broadcast):",
        r"inet:?(?:\s*addr:)?\s*(" + ValidIpv4AddressRegex + ").*netmask (" +
        ValidIpv4AddressRegex + ")(.*destination " + ValidIpv4AddressRegex +
        ")?",
    ]

    dev = LinuxDevice()
    dev.match = max([re.search(i, output) for i in regex], key=bool)
    print(dev.match)
    assert expected_ip == dev.get_interface_ipaddr("erouter0")
Beispiel #3
0
def test_exception_get_interface_ip6addr(mocker, output, expected_ip):
    mocker.patch.object(LinuxDevice,
                        "check_output",
                        return_value=output,
                        autospec=True)
    mocker.patch.object(LinuxDevice,
                        "__init__",
                        return_value=None,
                        autospec=True)
    dev = LinuxDevice()
    with pytest.raises(Exception) or pytest.raises(
            ipaddress.AddressValueError):
        dev.get_interface_ip6addr("erouter0")
Beispiel #4
0
def test_exception_get_interface_ip6addr(mocker, output):
    mocker.patch.object(LinuxDevice,
                        "__init__",
                        return_value=None,
                        autospec=True)
    mocker.patch.object(LinuxDevice,
                        "expect",
                        return_value=None,
                        autospec=True)
    mocker.patch.object(LinuxDevice,
                        "sendline",
                        return_value=None,
                        autospec=True)

    dev = LinuxDevice()
    type(dev).before = mocker.PropertyMock(return_value=output)

    with pytest.raises(BftIfaceNoIpV6Addr):
        dev.get_interface_ip6addr("erouter0")
Beispiel #5
0
def test_get_interface_ip6addr(mocker, output, expected_ip):
    mocker.patch.object(LinuxDevice,
                        "__init__",
                        return_value=None,
                        autospec=True)
    mocker.patch.object(LinuxDevice,
                        "expect",
                        return_value=None,
                        autospec=True)
    mocker.patch.object(LinuxDevice,
                        "sendline",
                        return_value=None,
                        autospec=True)

    dev = LinuxDevice()
    # set mocker property
    type(dev).before = mocker.PropertyMock(return_value=output)

    assert expected_ip == dev.get_interface_ip6addr("erouter0")