示例#1
0
def test_invalid_cfg_msg():

    msg_list = [
                '{"node_id": "02beefdead"}',
                '{"node_id": "02beefdead", "net0_id": ["7ac4235ec5d3d938"]}',
                '{"node_id": "022beefdead", "networks": ["7ac4235ec5d3d938"]}',
                '{"node": "02beefdead", "networks": ["7ac4235ec5d3d938"]}',
                '{"node_id": "02beefhead", "networks": ["7ac4235ec5d3d938"]}'
               ]

    for msg in msg_list:
        with pytest.raises(AssertionError):
            valid_cfg_msg(msg)
示例#2
0
def handle_cfg(msg):
    import json

    if valid_cfg_msg(msg):
        logger.debug('Got valid cfg msg: {}'.format(msg))
        cfg_msg = json.loads(msg)
        mbr_id = cfg_msg['node_id']
        if mbr_id in pub_q:
            with cfg_q.transact():
                avoid_and_update(mbr_id, msg, cfg_q)
            logger.debug('Adding node cfg: {}'.format(msg))
        logger.info('{} msgs in cfg queue'.format(len(cfg_q)))
    else:
        logger.warning('Bad cfg msg is {}'.format(msg))
示例#3
0
def test_make_cfg_msg():
    # the char set used for trie keys is string.hexdigits
    import json
    from node_tools import ctlr_data as ct
    assert trie_is_empty(ct.id_trie) is True

    node_id = '02beefdead'
    needs = [False, True]
    net_list = ['7ac4235ec5d3d938']
    ct.id_trie[node_id] = (net_list, needs)
    cfg_msg = '{"node_id": "02beefdead", "networks": ["7ac4235ec5d3d938"]}'

    res = make_cfg_msg(ct.id_trie, node_id)
    assert type(res) is str
    assert json.loads(res) == json.loads(cfg_msg)
    assert valid_cfg_msg(res)
    ct.id_trie.clear()
    assert trie_is_empty(ct.id_trie) is True
示例#4
0
def test_valid_cfg_msg():
    res = valid_cfg_msg('{"node_id": "02beefdead", "networks": ["7ac4235ec5d3d938"]}')
    assert res is True