Beispiel #1
0
    def test_adhoc_mode(self):
        NODE_SETTINGS['mode'] = 'adhoc'
        self.assertIsNone(self.role)

        set_initial_role()
        validate_role()
        self.assertIsNone(NODE_SETTINGS['node_role'])
Beispiel #2
0
    def test_moon_role(self):
        self.assertIsNone(self.role)

        set_initial_role()
        validate_role()
        self.assertIsNone(NODE_SETTINGS['node_role'])

        NODE_SETTINGS['moon_list'].append(self.state['fpn_id'])

        validate_role()

        self.assertEqual(NODE_SETTINGS['node_role'], 'moon')
        self.assertEqual(NODE_SETTINGS['node_runner'], 'peerstate.py')
        self.assertEqual(self.state['fpn_role'], 'moon')
        NODE_SETTINGS['moon_list'].remove(self.state['fpn_id'])
Beispiel #3
0
    def test_ctlr_role(self):
        self.assertIsNone(self.role)

        set_initial_role()
        validate_role()
        self.assertIsNone(NODE_SETTINGS['node_role'])

        NODE_SETTINGS['ctlr_list'].append(self.state['fpn_id'])

        validate_role()

        self.assertEqual(NODE_SETTINGS['node_role'], 'controller')
        self.assertEqual(self.state['fpn_role'], 'controller')
        self.assertEqual(NODE_SETTINGS['node_runner'], 'netstate.py')
        NODE_SETTINGS['ctlr_list'].remove(self.state['fpn_id'])
Beispiel #4
0
def do_scheduling():
    set_initial_role()
    network_cruft_cleaner()
    schedule.run_all(1, 'base-tasks')
    validate_role()
    node_role = NODE_SETTINGS['node_role']
    mode = NODE_SETTINGS['mode']
    if node_role is None and mode == 'peer':
        NODE_SETTINGS['use_localhost'] = True

    if mode == 'peer':
        if node_role is None:
            check_time = 33
            baseCheckJob = schedule.every(check_time).seconds
            baseCheckJob.do(run_net_check).tag('base-tasks', 'route-status')

            try:
                data = wait_for_moon(timeout=45)
            except Exception as exc:
                logger.error('ENODATA exception {}'.format(exc))
                put_state_msg('ERROR')

            try:
                handle_moon_data(data)
                put_state_msg('STARTING')
            except MemberNodeError as exc:
                logger.error('ENODATA exception {}'.format(exc))
                put_state_msg('ERROR')

            str_level = logging.getLevelName(logger.getEffectiveLevel())
            logger.debug('Current log level is: {}'.format(str_level))
            startup_handlers()

        else:
            if node_role == 'controller':
                netobj_q = dc.Deque(directory=get_cachedir('netobj_queue'))
                gen_netobj_queue(netobj_q)
                cache = dc.Index(get_cachedir())
                for key_str in ['peer', 'moon', 'mstate']:
                    delete_cache_entry(cache, key_str)

            elif node_role == 'moon':
                cln_q = dc.Deque(directory=get_cachedir('clean_queue'))
                pub_q = dc.Deque(directory=get_cachedir('pub_queue'))
                schedule.every(37).seconds.do(run_cleanup_check, cln_q,
                                              pub_q).tag(
                                                  'chk-tasks', 'cleanup')
                schedule.every(15).minutes.do(check_daemon_status).tag(
                    'chk-tasks', 'responder')

            schedule.every(15).minutes.do(check_daemon_status,
                                          script='msg_subscriber.py').tag(
                                              'chk-tasks', 'subscriber')
            schedule.run_all(1, 'chk-tasks')

    elif mode == 'adhoc':
        logger.debug('Running in adhoc mode...')
        if NODE_SETTINGS['nwid']:
            logger.debug('ADHOC: found network {}'.format(
                NODE_SETTINGS['nwid']))
            do_startup(NODE_SETTINGS['nwid'])
        else:
            logger.error('No network ID found in NODE_SETTINGS!!')
            logger.error('Have you created a network yet?')

    logger.debug('MODE: startup mode is {} and role is {}'.format(
        mode, node_role))
    logger.info(
        'You are running fpnd/node_tools version {}'.format(fpnd_version))

    while True:
        schedule.run_pending()
        time.sleep(1)
Beispiel #5
0
def test_set_initial_role():
    set_initial_role()