Пример #1
0
def test_node_state_check():
    from node_tools import state_data as stest

    state = AttrDict.from_nested_dict(stest.fpnState)
    assert state.cfg_ref is None
    res = node_state_check()
    assert res is None
    state.update(cfg_ref='7f5c6fc9-28d9-45d6-b210-1a08b958e219')
    res = node_state_check()
    state.update(cfg_ref=None)
Пример #2
0
def echo_client(fpn_id, addr, send_cfg=False):
    import json
    from node_tools import state_data as st
    from node_tools.msg_queues import make_version_msg
    from node_tools.node_funcs import do_shutdown
    from node_tools.node_funcs import node_state_check
    from node_tools.node_funcs import run_ztcli_cmd

    if NODE_SETTINGS['use_localhost'] or not addr:
        addr = '127.0.0.1'

    cfg = st.cfg_msgs
    compatible = True
    node_data = st.fpnState
    reply_list = []
    reciept = False

    try:
        if send_cfg:
            reply_list = send_req_msg(addr, 'node_cfg', fpn_id)
            logger.debug('CFG: send_cfg reply is {}'.format(reply_list))
            if 'result' not in reply_list[0]:
                logger.warning('CFG: malformed reply {}'.format(reply_list))
            else:
                node_data['cfg_ref'] = reply_list[0]['ref']
                cfg = json.loads(reply_list[0]['result'])
                logger.debug('CFG: state has payload {}'.format(cfg))
                for net in cfg['networks']:
                    res = run_ztcli_cmd(action='join', extra=net)
                    logger.debug('run_ztcli_cmd join result: {}'.format(res))
        else:
            ver_msg = make_version_msg(fpn_id)
            reply_list = send_req_msg(addr, 'echo', ver_msg)
            logger.debug('ECHO: ver_msg reply is {}'.format(reply_list))
            if 'result' not in reply_list[0]:
                logger.warning('ECHO: malformed reply {}'.format(reply_list))
            else:
                node_data['msg_ref'] = reply_list[0]['ref']
                msg = json.loads(reply_list[0]['result'])
                logger.debug('ECHO: got msg reply {}'.format(msg))
                if 'UPGRADE' in msg['version']:
                    put_state_msg('UPGRADE')
                    compatible = False
        reciept = True
        logger.debug('Send result is {}'.format(reply_list))
        if not compatible:
            logger.error(
                'Shutting down due to incompatible version: {}'.format(
                    ver_msg))
            do_shutdown()
        if not send_cfg and not node_data['cfg_ref']:
            res = node_state_check(deorbit=True)
            logger.debug('node_state_check returned {}'.format(res))
    except Exception as exc:
        # success wrapper needs a warning to catch
        logger.warning('Send error is {}'.format(exc))
        raise exc

    return reply_list, reciept
Пример #3
0
def echo_client(fpn_id, addr, send_cfg=False):
    import json
    from node_tools import state_data as st
    from node_tools.node_funcs import node_state_check
    from node_tools.node_funcs import run_ztcli_cmd

    if NODE_SETTINGS['use_localhost'] or not addr:
        addr = '127.0.0.1'

    cfg = st.cfg_msgs
    node_data = st.fpnState
    reply_list = []
    reciept = False

    try:
        if send_cfg:
            reply_list = send_req_msg(addr, 'node_cfg', fpn_id)
            logger.debug('CFG: send_cfg reply is {}'.format(reply_list))
            if 'result' not in reply_list[0]:
                logger.warning('CFG: malformed reply {}'.format(reply_list))
            else:
                node_data['cfg_ref'] = reply_list[0]['ref']
                cfg = json.loads(reply_list[0]['result'])
                logger.debug('CFG: state has payload {}'.format(cfg))
                for net in cfg['networks']:
                    res = run_ztcli_cmd(action='join', extra=net)
                    logger.debug('run_ztcli_cmd join result: {}'.format(res))
        else:
            reply_list = send_req_msg(addr, 'echo', fpn_id)
            node_data['msg_ref'] = reply_list[0]['ref']
        reciept = True
        logger.debug('Send result is {}'.format(reply_list))
        if not send_cfg and not node_data['cfg_ref']:
            res = node_state_check(deorbit=True)
            logger.debug('node_state_check returned {}'.format(res))
    except Exception as exc:
        # success wrapper needs a warning to catch
        logger.warning('Send error is {}'.format(exc))
        raise exc

    return reply_list, reciept