Esempio n. 1
0
def test_get_endpoint_ip():
    class Mock_bcf():
        def __init__(self):
            pass

    uss = Update_Switch_State()
    uss.first_time = False
    uss.sdnc = Mock_bcf()
    machines = [{
        'ip-address': '10.0.0.101',
        'mac': 'f8:b1:56:fe:f2:de',
        'segment': 'prod',
        'tenant': 'FLOORPLATE',
        'name': None
    }, {
        'ip-address': '10.0.0.99',
        'mac': '20:4c:9e:5f:e3:c3',
        'segment': 'to-core-router',
        'tenant': 'EXTERNAL',
        'name': None
    }]
    uss.find_new_machines(machines)
    retval = uss.endpoints.get_endpoint_ip(
        '3da53a95ae5d034ae37b539a24370260a36f8bb2')
    answer = '10.0.0.99'
    assert retval == answer

    retval = uss.endpoints.get_endpoint_ip('NOT-A-HASH')
    answer = None
    assert retval == answer
Esempio n. 2
0
def test_unmirror_endpoint():
    class Mock_bcf():
        def __init__(self):
            pass

        def unmirror_ip(self, my_ip):
            assert my_ip == '10.0.0.99'

    uss = Update_Switch_State()
    uss.first_time = False
    uss.sdnc = Mock_bcf()
    machines = [{
        'ip-address': '10.0.0.101',
        'mac': 'f8:b1:56:fe:f2:de',
        'segment': 'prod',
        'tenant': 'FLOORPLATE',
        'name': None
    }, {
        'ip-address': '10.0.0.99',
        'mac': '20:4c:9e:5f:e3:c3',
        'segment': 'to-core-router',
        'tenant': 'EXTERNAL',
        'name': None
    }]
    uss.find_new_machines(machines)

    assert uss.unmirror_endpoint('3da53a95ae5d034ae37b539a24370260a36f8bb2')
    assert not uss.unmirror_endpoint(
        '4da53a95ae5d034ae37b539a24370260a36f8bb2')
Esempio n. 3
0
def test_file_new_machines_later():
    uss = Update_Switch_State()
    uss.first_time = False
    machines = [{
        'ip-address': '10.0.0.101',
        'mac': 'f8:b1:56:fe:f2:de',
        'segment': 'prod',
        'tenant': 'FLOORPLATE',
        'active': 1,
        'port': 1,
        'name': None
    }, {
        'ip-address': '10.0.0.99',
        'mac': '20:4c:9e:5f:e3:c3',
        'segment': 'to-core-router',
        'tenant': 'EXTERNAL',
        'active': 1,
        'port': 1,
        'name': None
    }]
    answer = dict({
        'd502caea3609d553ab16a00c554f0602c1419f58': {
            'state': 'UNKNOWN',
            'next-state': 'NONE',
            'endpoint': {
                'ip-address': '10.0.0.101',
                'mac': 'f8:b1:56:fe:f2:de',
                'segment': 'prod',
                'tenant': 'FLOORPLATE',
                'active': 1,
                'port': 1,
                'name': None
            }
        },
        '3da53a95ae5d034ae37b539a24370260a36f8bb2': {
            'state': 'UNKNOWN',
            'next-state': 'NONE',
            'endpoint': {
                'ip-address': '10.0.0.99',
                'mac': '20:4c:9e:5f:e3:c3',
                'segment': 'to-core-router',
                'tenant': 'EXTERNAL',
                'active': 1,
                'port': 1,
                'name': None
            }
        }
    })
    uss.find_new_machines(machines)

    #assert str(answer) == str(dict(uss.endpoint_states))
    for key in answer:
        assert answer[key]['state'] == uss.endpoints.state[key].state
        assert answer[key]['next-state'] == uss.endpoints.state[key].next_state
        for key2 in answer[key]['endpoint']:
            assert answer[key]['endpoint'][key2] == uss.endpoints.state[
                key].endpoint_data[key2]
Esempio n. 4
0
def test_find_new_machines_first_time():
    uss = Update_Switch_State()
    uss.first_time = True
    machines = [{
        'ip-address': '10.0.0.101',
        'mac': 'f8:b1:56:fe:f2:de',
        'segment': 'prod',
        'tenant': 'FLOORPLATE',
        'active': 1,
        'port': 1,
        'name': None
    }, {
        'ip-address': '10.0.0.99',
        'mac': '20:4c:9e:5f:e3:c3',
        'segment': 'to-core-router',
        'tenant': 'EXTERNAL',
        'active': 1,
        'port': 1,
        'name': None
    }]
    uss.find_new_machines(machines)
    answer = dict({
        "d502caea3609d553ab16a00c554f0602c1419f58": {
            "state": "KNOWN",
            "next-state": "NONE",
            "endpoint": {
                "ip-address": "10.0.0.101",
                "mac": "f8:b1:56:fe:f2:de",
                "segment": "prod",
                "tenant": "FLOORPLATE",
                "active": 1,
                "port": 1,
                "name": None
            }
        },
        "3da53a95ae5d034ae37b539a24370260a36f8bb2": {
            "state": "KNOWN",
            "next-state": "NONE",
            "endpoint": {
                "ip-address": "10.0.0.99",
                "mac": "20:4c:9e:5f:e3:c3",
                "segment": "to-core-router",
                "tenant": "EXTERNAL",
                "active": 1,
                "port": 1,
                "name": None
            }
        }
    })
    #assert str(answer) == str(dict(uss.endpoint_states))
    for key in answer:
        assert answer[key]['state'] == uss.endpoints.state[key].state
        for next_key in answer[key]['endpoint']:
            assert answer[key]['endpoint'][next_key] == uss.endpoints.state[
                key].endpoint_data[next_key]
Esempio n. 5
0
def test_make_known_endpoint():
    class Mock_bcf():
        def __init__(self):
            pass

        def unmirror_ip(self, my_ip):
            assert my_ip == '10.0.0.99'

    uss = Update_Switch_State()
    uss.first_time = False
    uss.bcf = Mock_bcf()
    machines = [{
        'ip-address': '10.0.0.101',
        'mac': 'f8:b1:56:fe:f2:de',
        'segment': 'prod',
        'tenant': 'FLOORPLATE',
        'name': None
    }, {
        'ip-address': '10.0.0.99',
        'mac': '20:4c:9e:5f:e3:c3',
        'segment': 'to-core-router',
        'tenant': 'EXTERNAL',
        'name': None
    }]
    uss.find_new_machines(machines)

    uss.make_known_endpoint('3da53a95ae5d034ae37b539a24370260a36f8bb2')
    answer = dict({
        'd502caea3609d553ab16a00c554f0602c1419f58': {
            'state': 'UNKNOWN',
            'next-state': 'NONE',
            'endpoint': {
                'ip-address': '10.0.0.101',
                'mac': 'f8:b1:56:fe:f2:de',
                'segment': 'prod',
                'tenant': 'FLOORPLATE',
                'name': None
            }
        },
        '3da53a95ae5d034ae37b539a24370260a36f8bb2': {
            'state': 'KNOWN',
            'next-state': 'NONE',
            'endpoint': {
                'ip-address': '10.0.0.99',
                'mac': '20:4c:9e:5f:e3:c3',
                'segment': 'to-core-router',
                'tenant': 'EXTERNAL',
                'name': None
            }
        }
    })
    assert str(answer) == str(dict(uss.endpoint_states))