Ejemplo n.º 1
0
def test_valid_subnets_success():
    subnets = {
        "net1": "10.0.1.0/24",
        "net2": "10.0.2.0/24",
        "net3": "10.0.3.0/24",
        "net4": "10.0.4.0/24",
        "net5": "10.0.5.0/24"
    }

    net_validator.validate_subnets(subnets)
Ejemplo n.º 2
0
def test_valid_subnets_fail_hostbits():
    with pytest.raises(ValueError, match="10.0.2.0/14 has host bits set"):
        subnets = {
            "net1": "10.0.1.0/24",
            "net2": "10.0.2.0/14",
            "net3": "10.0.3.3/24",
            "net4": "10.0.4.0/24",
            "net5": "10.0.5.0"
        }

        net_validator.validate_subnets(subnets)
Ejemplo n.º 3
0
def test_valid_subnets_fail_empty():
    with pytest.raises(ipaddress.AddressValueError):
        subnets = {
            "net1": "10.0.1.0/24",
            "net2": "10.0.2.0/24",
            "net3": "",
            "net4": "10.0.4.0/24",
            "net5": "10.0.5.0/24"
        }

        net_validator.validate_subnets(subnets)
Ejemplo n.º 4
0
def test_valid_subnets_fail_no_netmask():
    with pytest.raises(ValueError, match="No prefix for subnet: 10.0.1.0"):
        subnets = {
            "net1": "10.0.1.0",
            "net2": "10.0.2.0/24",
            "net3": "10.0.3.0/24",
            "net4": "10.0.4.0/24",
            "net5": "10.0.5.0"
        }

        net_validator.validate_subnets(subnets)
Ejemplo n.º 5
0
def validate_subnets(orig_subnets: dict, sim_subnets: dict):
    net_validator.validate_subnets(orig_subnets, sim_subnets)

    # validate same number of networks
    if (len(orig_subnets) != len(sim_subnets)):
        raise KeyError("Network number mismatch")

    # validate same network names
    for o_net in orig_subnets.keys():
        if (o_net not in sim_subnets.keys()):
            raise KeyError("Network mismatch")
Ejemplo n.º 6
0
def test_valid_subnets_fail_netmask_empty():
    with pytest.raises(ipaddress.NetmaskValueError,
                       match="Invalid netmask: 10.0.5.0/"):
        subnets = {
            "net1": "10.0.1.0/24",
            "net2": "10.0.2.0/24",
            "net3": "10.0.3.0/24",
            "net4": "10.0.4.0/24",
            "net5": "10.0.5.0/"
        }

        net_validator.validate_subnets(subnets)
Ejemplo n.º 7
0
def test_valid_subnets_multiple():
    subnets1 = {
        "net1": "10.0.1.0/24",
        "net2": "10.0.2.0/24",
        "net3": "10.0.3.0/24",
        "net4": "10.0.4.0/24",
        "net5": "10.0.5.0/24"
    }

    subnets2 = {
        "net1": "10.1.1.0/24",
        "net2": "10.1.2.0/24",
        "net3": "10.1.3.0/24",
        "net4": "10.1.4.0/24",
        "net5": "10.1.5.0/24"
    }

    net_validator.validate_subnets(subnets1, subnets2)
Ejemplo n.º 8
0
def test_valid_subnets_multiple_fail_first():
    with pytest.raises(ValueError, match="10.0.3.3/24 has host bits set"):
        subnets1 = {
            "net1": "10.0.1.0/24",
            "net2": "10.0.2.0/24",
            "net3": "10.0.3.3/24",
            "net4": "10.0.4.0/24",
            "net5": "10.0.5.0"
        }

        subnets2 = {
            "net1": "10.1.1.0/24",
            "net2": "10.1.2.0/24",
            "net3": "10.1.3.0/24",
            "net4": "10.1.4.0/24",
            "net5": "10.1.5.0/24"
        }

        net_validator.validate_subnets(subnets1, subnets2)
Ejemplo n.º 9
0
def test_valid_subnets_multiple_fail_second():
    with pytest.raises(ipaddress.NetmaskValueError,
                       match="Invalid netmask: 10.0.3.0/"):
        subnets1 = {
            "net1": "10.0.1.0/24",
            "net2": "10.0.2.0/24",
            "net3": "10.0.3.0/24",
            "net4": "10.0.4.0/24",
            "net5": "10.0.5.0/24"
        }

        subnets2 = {
            "net1": "10.0.1.0/24",
            "net2": "10.0.2.0/24",
            "net3": "10.0.3.0/",
            "net4": "10.0.4.0/224",
            "net5": "10.0.5.0"
        }

        net_validator.validate_subnets(subnets1, subnets2)