Ejemplo n.º 1
0
    def test_basic(self):

        ###############################
        # Create LoggerManager and test it
        api = InMemoryServerAPI()
        logger_manager = LoggerManager(api=api)

        ############################
        def run_commands(logger_manager):
            reader = NetworkReader(network=':8002')
            api = logger_manager.api
            time.sleep(1)

            runner = ServerAPICommandLine(api)

            runner.process_command('load_cruise %s' % self.cruise_filename)
            runner.process_command('set_mode NBP1700 port')
            for i in range(4):
                self.assertEqual(reader.read(),
                                 'TestLoggerManager ' + sample_data[i])
            logging.info('NetworkReader done')
            logger_manager.quit()

        cmd_thread = threading.Thread(target=run_commands,
                                      daemon=True,
                                      args=(logger_manager, ))
        cmd_thread.start()
        logger_manager.start()
        cmd_thread.join()
Ejemplo n.º 2
0
    def test_basic(self):

        ###############################
        # Create LoggerManager and test it
        api = InMemoryServerAPI()
        supervisor = SupervisorConnector(start_supervisor_in=self.tmpdirname +
                                         '/supervisor',
                                         max_tries=1,
                                         log_level=logging.WARNING)
        logger_manager = LoggerManager(api=api,
                                       supervisor=supervisor,
                                       logger_log_level=logging.WARNING)

        ############################
        def run_commands(logger_manager):
            api = logger_manager.api
            time.sleep(1)

            runner = ServerAPICommandLine(api)

            runner.process_command('load_configuration %s' %
                                   self.cruise_filename)
            runner.process_command('set_active_mode port')

            # Give it time to run
            time.sleep(2)

            reader = TextFileReader(self.output_filename)

            for i in range(4):
                result = reader.read()
                self.assertEqual(result, 'TestLoggerManager ' + sample_data[i])
            logging.info('TextFileReader done')
            logger_manager.quit()

        cmd_thread = threading.Thread(name='run_commands',
                                      target=run_commands,
                                      daemon=True,
                                      args=(logger_manager, ))
        cmd_thread.start()
        logger_manager.start()
        cmd_thread.join()
Ejemplo n.º 3
0
    stderr_writer = ComposedWriter(
      transforms=ToDASRecordTransform(field_name='stderr:logger_manager'),
      writers=[CachedDataWriter(data_server=args.data_server_websocket)])
    logging.getLogger().addHandler(StdErrLoggingHandler(stderr_writer,
                                                        parse_to_json=True))

  ############################
  # Instantiate API - a Are we using an in-memory store or Django
  # database as our backing store? Do our imports conditionally, so
  # they don't actually have to have Django if they're not using it.
  if args.database == 'django':
    from django_gui.django_server_api import DjangoServerAPI
    api = DjangoServerAPI()
  elif args.database == 'memory':
    from server.in_memory_server_api import InMemoryServerAPI
    api = InMemoryServerAPI()
  elif args.database == 'hapi':
    from hapi.hapi_server_api import HapiServerAPI
    api = HapiServerAPI()
  else:
    raise ValueError('Illegal arg for --database: "%s"' % args.database)

  # Now that API is defined, tack on one more logging handler: one
  # that passes messages to API.
  # TODO: decide if we even need this. Disabled for now
  #logging.getLogger().addHandler(WriteToAPILoggingHandler(api))

  ############################
  # Create our logger supervisor.
  supervisor = LoggerSupervisor(
    configs=None,
    def test_basic(self):

        api = InMemoryServerAPI()

        api.load_configuration(sample_1)

        self.assertEqual(api.get_modes(), ['off', 'port', 'underway'])
        self.assertEqual(api.get_active_mode(), 'off')
        self.assertDictEqual(
            api.get_logger_configs(), {
                'knud': {
                    'config': 'off'
                },
                'gyr1': {
                    'config': 'off'
                },
                'mwx1': {
                    'config': 'off'
                },
                's330': {
                    'config': 'off'
                }
            })

        with self.assertRaises(ValueError):
            api.set_active_mode('invalid mode')

        api.set_active_mode('underway')
        self.assertEqual(api.get_active_mode(), 'underway')
        self.assertDictEqual(
            api.get_logger_configs(), {
                'knud': {
                    'config': 'knud->net/file'
                },
                'gyr1': {
                    'config': 'gyr1->net/file'
                },
                'mwx1': {
                    'config': 'mwx1->net/file'
                },
                's330': {
                    'config': 's330->net/file'
                }
            })

        with self.assertRaises(ValueError):
            api.get_logger_configs('invalid_mode')
        self.assertEqual(
            api.get_logger_configs('port'), {
                'gyr1': {
                    'config': 'gyr1->net'
                },
                'knud': {
                    'config': 'off'
                },
                'mwx1': {
                    'config': 'mwx1->net'
                },
                's330': {
                    'config': 'off'
                }
            })
        self.assertDictEqual(
            api.get_loggers(), {
                'knud': {
                    'configs': ['off', 'knud->net', 'knud->net/file'],
                    'active': 'knud->net/file'
                },
                'gyr1': {
                    'configs': ['off', 'gyr1->net', 'gyr1->net/file'],
                    'active': 'gyr1->net/file'
                },
                'mwx1': {
                    'configs': ['off', 'mwx1->net', 'mwx1->net/file'],
                    'active': 'mwx1->net/file'
                },
                's330': {
                    'configs': ['off', 's330->net', 's330->net/file'],
                    'active': 's330->net/file'
                }
            })
        api.delete_configuration()
        with self.assertRaises(ValueError):
            api.get_logger_configs()
Ejemplo n.º 5
0
    def test_basic(self):

        api = InMemoryServerAPI()

        api.load_cruise(sample_1700)
        api.load_cruise(sample_1701)

        self.assertEqual(api.get_cruises(), ['NBP1700', 'NBP1701'])

        self.assertEqual(api.get_modes('NBP1700'), ['off', 'port', 'underway'])
        self.assertEqual(api.get_mode('NBP1700'), 'off')
        self.assertDictEqual(api.get_configs('NBP1700'), {
            'knud': {},
            'gyr1': {},
            'mwx1': {},
            's330': {}
        })

        with self.assertRaises(ValueError):
            api.set_mode('NBP1700', 'invalid mode')

        api.set_mode('NBP1700', 'underway')
        self.assertEqual(api.get_mode('NBP1700'), 'underway')
        self.assertDictEqual(
            api.get_configs('NBP1700'), {
                'knud': {'config knud->net/file'},
                'gyr1': {'config gyr1->net/file'},
                'mwx1': {'config mwx1->net/file'},
                's330': {'config s330->net/file'}
            })
        self.assertDictEqual(
            api.get_configs(), {
                'NBP1700:knud': {'config knud->net/file'},
                'NBP1700:gyr1': {'config gyr1->net/file'},
                'NBP1700:mwx1': {'config mwx1->net/file'},
                'NBP1700:s330': {'config s330->net/file'},
                'NBP1701:knud': {},
                'NBP1701:gyr1': {},
                'NBP1701:mwx1': {},
                'NBP1701:s330': {}
            })

        with self.assertRaises(ValueError):
            api.get_configs('NBP1701', 'invalid_mode')
        self.assertEqual(
            api.get_configs('NBP1701', 'port'), {
                'gyr1': {'config gyr1->net'},
                'knud': {},
                'mwx1': {'config mwx1->net'},
                's330': {}
            })

        self.assertDictEqual(
            api.get_loggers('NBP1700'), {
                'knud': {
                    'configs': ['off', 'knud->net', 'knud->net/file']
                },
                'gyr1': {
                    'configs': ['off', 'gyr1->net', 'gyr1->net/file']
                },
                'mwx1': {
                    'configs': ['off', 'mwx1->net', 'mwx1->net/file']
                },
                's330': {
                    'configs': ['off', 's330->net', 's330->net/file']
                }
            })
        api.delete_cruise('NBP1700')
        self.assertEqual(api.get_cruises(), ['NBP1701'])
        self.assertDictEqual(
            api.get_configs(), {
                'NBP1701:knud': {},
                'NBP1701:gyr1': {},
                'NBP1701:mwx1': {},
                'NBP1701:s330': {}
            })