def test_get_runtimedir(): import tempfile temp_dir = tempfile.gettempdir() NODE_SETTINGS['runas_user'] = False res = get_runtimedir() # print(res) assert res == '/run/fpnd' or res == temp_dir res = get_runtimedir(user_dirs=True) assert '/run/user/' in res or 'tmp/portage' in res or res == temp_dir NODE_SETTINGS['runas_user'] = True
def test_put_state_msg_save(): """ Same as test_put_state_msg but without cleaning """ state_path = Path(get_runtimedir(user_dirs=True)).joinpath('fpnd.state') msgs = [ 'STARTING', 'CONNECTED', 'CONFIG', 'ERROR', 'UPGRADE', 'WAITING', 'NONE' ] for msg in msgs: put_state_msg(msg, clean=False) status_queue = get_status(str(state_path)) assert len(list(status_queue)) == 1 data = status_queue.pop().strip() assert data == msg assert len(list(status_queue)) == 0 for msg in msgs: put_state_msg(msg, clean=False) status_queue = get_status(str(state_path), 7) assert len(list(status_queue)) == 7 data = status_queue.pop().strip() assert data == 'NONE' assert len(list(status_queue)) == 6 state_path.unlink()
def test_put_state_msg(): """ Use get_status() from freepn-gtk3-indicator (replicated above) """ state_path = Path(get_runtimedir(user_dirs=True)).joinpath('fpnd.state') msgs = [ 'STARTING', 'CONNECTED', 'CONFIG', 'ERROR', 'UPGRADE', 'WAITING', 'NONE' ] for msg in msgs: put_state_msg(msg) status_queue = get_status(str(state_path)) assert len(list(status_queue)) == 1 data = status_queue.pop().strip() assert data == msg assert len(list(status_queue)) == 0 for msg in msgs: put_state_msg(msg) status_queue = get_status(str(state_path), 7) assert len(list(status_queue)) == 1 data = status_queue.pop().strip() assert data == 'NONE' assert len(list(status_queue)) == 0 state_path.unlink()
from node_tools.msg_queues import wait_for_cfg_msg logger = logging.getLogger(__name__) # set log level and handler/formatter logger.setLevel(logging.DEBUG) logging.getLogger('node_tools.msg_queues').level = logging.DEBUG handler = logging.handlers.SysLogHandler(address='/dev/log', facility='daemon') formatter = logging.Formatter( '%(module)s: %(funcName)s+%(lineno)s: %(message)s') handler.setFormatter(formatter) logger.addHandler(handler) # pid_file = '/tmp/responder.pid' pid_file = os.path.join(get_runtimedir(), '{}.pid'.format('msg_responder')) # stdout = '/tmp/responder.log' # stderr = '/tmp/responder_err.log' cfg_q = dc.Deque(directory=get_cachedir('cfg_queue')) hold_q = dc.Deque(directory=get_cachedir('hold_queue')) off_q = dc.Deque(directory=get_cachedir('off_queue')) pub_q = dc.Deque(directory=get_cachedir('pub_queue')) wdg_q = dc.Deque(directory=get_cachedir('wedge_queue')) node_q = dc.Deque(directory=get_cachedir('node_queue')) reg_q = dc.Deque(directory=get_cachedir('reg_queue')) wait_q = dc.Deque(directory=get_cachedir('wait_queue')) tmp_q = dc.Deque(directory=get_cachedir('tmp_queue')) cln_q = dc.Deque(directory=get_cachedir('clean_queue'))
from node_tools.msg_queues import valid_cfg_msg logger = logging.getLogger(__name__) # set log level and handler/formatter logger.setLevel(logging.DEBUG) logging.getLogger('node_tools.msg_queues').level = logging.DEBUG handler = logging.handlers.SysLogHandler(address='/dev/log', facility='daemon') formatter = logging.Formatter( '%(module)s: %(funcName)s+%(lineno)s: %(message)s') handler.setFormatter(formatter) logger.addHandler(handler) # pid_file = '/tmp/subscriber.pid' pid_file = os.path.join(get_runtimedir(), '{}.pid'.format('msg_subscriber')) # std_out = '/tmp/subscriber.log' # std_err = '/tmp/subscriber_err.log' cfg_q = dc.Deque(directory=get_cachedir('cfg_queue')) node_q = dc.Deque(directory=get_cachedir('node_queue')) off_q = dc.Deque(directory=get_cachedir('off_queue')) pub_q = dc.Deque(directory=get_cachedir('pub_queue')) wdg_q = dc.Deque(directory=get_cachedir('wedge_queue')) def handle_msg(msg): if valid_announce_msg(msg): logger.debug('Got valid node ID: {}'.format(msg)) with node_q.transact(): node_q.append(msg)