Пример #1
0
def test_get_services():
    dummy_consul_obj = DummyConsul()
    node = {
        "node_name": "node_name",
        "agent_consul_obj": dummy_consul_obj,
        "node_name": "node_name",
        "node_id": "node_id",
        "agent_addr": "agent_addr"
    }
    expected = threading_util.ThreadSafeDict()
    expected["service_id1{}".format("node_id")] = {
        "service_id": "service_id1",
        "service_address": "service_address1",
        "service_port": "service_port1",
        "service_ip": "service_ip1",
        "service_name": "service_name1",
        "agent_consul_obj": dummy_consul_obj,
        "node_id": "node_id",
        "agent_addr": "agent_addr"
    }
    expected["service_id2{}".format("node_id")] = {
        "service_id": "service_id2",
        "service_address": "service_address2",
        "service_port": "service_port2",
        "service_ip": "service_ip2",
        "service_name": "service_name2",
        "agent_consul_obj": dummy_consul_obj,
        "node_id": "node_id",
        "agent_addr": "agent_addr"
    }

    services_dict = threading_util.ThreadSafeDict()
    data_fetch.get_services(services_dict, node)
    assert services_dict == expected
Пример #2
0
def test_get_node_checks():
    dummy_consul_obj = DummyConsul()
    node_checks_dict = threading_util.ThreadSafeDict()
    node = {
        "node_name": "node_name",
        "agent_consul_obj": dummy_consul_obj,
        "node_name": "node_name",
        "node_id": "node_id",
        "agent_addr": "agent_addr"
    }
    expected = threading_util.ThreadSafeDict()
    expected["test_CheckID1node_id"] = {
        "node_id": "node_id",
        "node_name": "node_name",
        "agent_addr": "agent_addr",
        "CheckID": "test_CheckID1"
    }
    expected["test_CheckID2node_id"] = {
        "node_id": "node_id",
        "node_name": "node_name",
        "agent_addr": "agent_addr",
        "CheckID": "test_CheckID2"
    }
    data_fetch.get_node_checks(node_checks_dict, node)
    assert expected == node_checks_dict
Пример #3
0
def test_get_nodes():
    consul_utils.Consul.nodes = nodes
    nodes_dict = threading_util.ThreadSafeDict()
    agent = {
        "ip": "test_ip",
        "port": "test_port",
        "token": "test_token",
        "protocol": "test_protocol"
    }
    expected = threading_util.ThreadSafeDict()
    expected['test_node_id'] = {
        'agent_addr': ['test_ip:test_port'],
        'node_id': 'test_node_id',
        'agent_consul_obj': None
    }
    expected['test_node_id2'] = {
        'agent_addr': ['test_ip:test_port'],
        'node_id': 'test_node_id2',
        'agent_consul_obj': None
    }
    data_fetch.get_nodes(nodes_dict, agent)
    assert nodes_dict.keys() == expected.keys()
    for key in nodes_dict:
        assert nodes_dict[key].keys() == expected[key].keys()
        for each in expected[key]:
            if each != 'agent_consul_obj':
                assert nodes_dict[key][each] == expected[key][each]
Пример #4
0
def test_fetch_and_save_services():
    def dummy_get_services(service_dict, node):
        service_dict.update(
            reader('fetch_and_save_services/services_dict.json'))

    def dummy_get_service_info(service):
        service.update(reader('fetch_and_save_services/service_info.json'))

    get_services = data_fetch.get_services
    get_service_info = data_fetch.get_service_info
    data_fetch.get_services = dummy_get_services
    data_fetch.get_service_info = dummy_get_service_info

    datacenter = 'dc1'
    nodes_dict = reader('fetch_and_save_services/nodes_dict.json')
    services_dict = threading_util.ThreadSafeDict()
    consul_ip_list, services_key = data_fetch.fetch_and_save_services(
        datacenter, nodes_dict, services_dict)

    expected = reader('fetch_and_save_services/output.json')
    assert set(expected[0]) == consul_ip_list
    assert set(map(tuple, expected[1])) == services_key

    data_fetch.get_services = get_services
    data_fetch.get_service_info = get_service_info
Пример #5
0
def test_get_service_checks():
    dummy_consul_obj = DummyConsul()
    service_checks_dict = threading_util.ThreadSafeDict()
    service = {
        "service_name": "service_name",
        "agent_consul_obj": dummy_consul_obj,
        "service_id": "service_id",
        "agent_addr": "agent_addr"
    }
    expected = threading_util.ThreadSafeDict()
    expected["test_CheckID1service_id"] = {
        "service_id": "service_id",
        "agent_addr": "agent_addr",
        "CheckID": "test_CheckID1"
    }
    expected["test_CheckID2service_id"] = {
        "service_id": "service_id",
        "agent_addr": "agent_addr",
        "CheckID": "test_CheckID2"
    }
    data_fetch.get_service_checks(service_checks_dict, service)
    assert expected == service_checks_dict
Пример #6
0
def test_fetch_and_save_servicechecks():
    def dummy_get_service_checks(service_checks_dict, agent):
        service_checks_dict.update(
            reader('fetch_and_save_servicechecks/service_checks_dict.json'))

    get_service_checks = data_fetch.get_service_checks
    data_fetch.get_service_checks = dummy_get_service_checks

    services_dict = reader('fetch_and_save_servicechecks/services_dict.json')
    service_checks_dict = threading_util.ThreadSafeDict()
    service_checks_key = data_fetch.fetch_and_save_servicechecks(
        services_dict, service_checks_dict)

    expected = reader('fetch_and_save_servicechecks/output.json')
    assert set(map(tuple, expected)) == service_checks_key

    data_fetch.get_service_checks = get_service_checks
Пример #7
0
def test_fetch_and_save_nodechecks():
    def dummy_get_node_checks(node_checks_dict, agent):
        node_checks_dict.update(
            reader('fetch_and_save_nodechecks/node_checks_dict.json'))

    get_node_checks = data_fetch.get_node_checks
    data_fetch.get_node_checks = dummy_get_node_checks

    nodes_dict = reader('fetch_and_save_nodechecks/nodes_dict.json')
    node_checks_dict = threading_util.ThreadSafeDict()
    node_checks_key = data_fetch.fetch_and_save_nodechecks(
        nodes_dict, node_checks_dict)

    expected = reader('fetch_and_save_nodechecks/output.json')
    assert set(map(tuple, expected)) == node_checks_key

    data_fetch.get_node_checks = get_node_checks
Пример #8
0
def test_fetch_and_save_nodes():
    def dummy_get_nodes(nodes_dict, agent):
        nodes_dict.update(reader('fetch_and_save_nodes/nodes_dict.json'))

    get_nodes = data_fetch.get_nodes
    data_fetch.get_nodes = dummy_get_nodes

    datacenter = 'dc1'
    agents = ['dummy_agent']
    nodes_dict = threading_util.ThreadSafeDict()
    consul_ip_list, nodes_key = data_fetch.fetch_and_save_nodes(
        datacenter, agents, nodes_dict)

    expected = reader('fetch_and_save_nodes/output.json')
    assert set(expected[0]) == consul_ip_list
    assert set(expected[1]) == nodes_key

    data_fetch.get_nodes = get_nodes