Beispiel #1
0
def test_add_ipv4_addresses(base_state):
    # test ip addresses are from:
    # https://tools.ietf.org/html/rfc5737
    ipv4 = ["198.51.100.31/24"]
    ip4config = nli.add_addresses({}, ipv4)
    assert len(ip4config["address"]) == 1
    assert ip4config["address"][0]["ip"] == ipv4[0].split("/")[0]

    # add second IP address
    ipv4_old = ipv4
    ipv4 = ["192.0.2.8/24"]
    ip4config = nli.add_addresses(ip4config, ipv4)
    assert len(ip4config["address"]) == 2
    assert ip4config["address"][0]["ip"] == ipv4_old[0].split("/")[0]
    assert ip4config["address"][1]["ip"] == ipv4[0].split("/")[0]

    # Set only one address
    ip4config = nli.set_addresses(ip4config, ipv4)
    assert len(ip4config["address"]) == 1
    assert ip4config["address"][0]["ip"] == ipv4[0].split("/")[0]

    # Set only one (different) address
    ipv4 = ["203.0.113.5/24"]
    ip4config = nli.set_addresses(ip4config, ipv4)
    assert len(ip4config["address"]) == 1
    assert ip4config["address"][0]["ip"] == ipv4[0].split("/")[0]
Beispiel #2
0
def test_add_ipv4_address_twice(base_state):
    ipv4 = ["198.51.100.31/24"]
    ip4config = nli.add_addresses({}, ipv4)
    assert len(ip4config["address"]) == 1
    assert ip4config["address"][0]["ip"] == ipv4[0].split("/")[0]
    ip4config = nli.add_addresses({}, ipv4)
    assert len(ip4config["address"]) == 1
    assert ip4config["address"][0]["ip"] == ipv4[0].split("/")[0]
Beispiel #3
0
def test_set_remove_ipv4_address_not_existing(base_state):
    ipv4 = ["198.51.100.31/24"]
    ip4config = nli.add_addresses({}, ipv4)
    assert len(ip4config["address"]) == 1
    assert ip4config["address"][0]["ip"] == ipv4[0].split("/")[0]

    # add second IP address
    ipv4_old = ipv4
    ipv4 = ["192.0.2.8/24"]
    ip4config = nli.add_addresses(ip4config, ipv4)
    assert len(ip4config["address"]) == 2
    assert ip4config["address"][0]["ip"] == ipv4_old[0].split("/")[0]
    assert ip4config["address"][1]["ip"] == ipv4[0].split("/")[0]

    # remove non existing address
    ip4config = nli.remove_addresses(ip4config, ["203.0.113.7/24"])
    assert len(ip4config["address"]) == 2
    assert ip4config["address"][0]["ip"] == ipv4_old[0].split("/")[0]
    assert ip4config["address"][1]["ip"] == ipv4[0].split("/")[0]

    ip4config = nli.remove_addresses(ip4config, ipv4_old)
    assert len(ip4config["address"]) == 1
    assert ip4config["address"][0]["ip"] == ipv4[0].split("/")[0]
Beispiel #4
0
def test_add_and_remove_ipv4_address(base_state):
    ipv4 = ["198.51.100.31/24"]
    ip4config = nli.add_addresses({}, ipv4)
    assert len(ip4config["address"]) == 1
    assert ip4config["address"][0]["ip"] == ipv4[0].split("/")[0]

    ip4config = nli.remove_addresses(ip4config, ["203.0.113.7/24"])
    assert len(ip4config["address"]) == 1
    assert ip4config["address"][0]["ip"] == ipv4[0].split("/")[0]

    ip4config = nli.remove_addresses(ip4config, ipv4)
    assert len(ip4config["address"]) == 0

    ip4config_b = nli.remove_addresses(ip4config, ipv4)
    assert ip4config == ip4config_b
Beispiel #5
0
def test_add_two_ipv4_addressess_at_once(base_state):
    ipv4 = ["198.51.100.31/24", "192.0.2.8/24"]
    ip4config = nli.add_addresses({}, ipv4)
    assert len(ip4config["address"]) == 2
    assert ip4config["address"][0]["ip"] == ipv4[0].split("/")[0]
    assert ip4config["address"][1]["ip"] == ipv4[1].split("/")[0]