コード例 #1
0
ファイル: radloggerpy.py プロジェクト: Dantali0n/radloggerpy
def main():
    configurator.setup_config_and_logging(sys.argv, CONF)

    # Display logo's
    LOG.info(ascii_logo.TEXT + ascii_logo.LOGO)

    # Display pid
    LOG.info(_('Starting RadLoggerPy service on PID %s') % os.getpid())

    # Perform first time initialization if required
    FirstTimeRun()

    # Create database session for main thread
    sess = database_manager.create_session()

    # launch device manager
    manager = DeviceManager()

    devices = SerialDeviceObject.find_enabled(sess)
    for device in devices:
        manager.launch_device(device)

    # TODO(Dantali0n): Improve state checking and error handling
    while True:
        manager.check_devices()
        time.sleep(30)

    # close all database sessions that are still left open
    database_manager.close_lingering_sessions()
コード例 #2
0
    def test_run_check_tasks_except_check(self, m_log):
        m_run = FirstTimeRun()

        check_task = FirstTimeRun.CheckTask(True, self.fake_task)
        m_run._check_tasks.append(check_task)

        m_run._run_check_tasks()

        m_log.error.assert_called_once()
コード例 #3
0
    def initialize_app(self, argv):
        # update configuration (sets CONF.version amongst others)
        parse_args(argv=())

        # Display logo
        self.LOG.info(ascii_logo.TEXT + ascii_logo.LOGO)

        # Perform first time initialization if required
        FirstTimeRun()

        # Display version
        self.LOG.info(_('Initializing radloggercli %s') % CONF.version)
コード例 #4
0
    def test_run_check_tasks(self):
        # Crate a mocked method
        m_method = mock.Mock()
        m_run = FirstTimeRun()

        # create CheckTask instance
        check_task = FirstTimeRun.CheckTask(self.fake_check_true, m_method)
        m_run._check_tasks.append(check_task)

        m_run._run_check_tasks()

        m_method.assert_called_once()
コード例 #5
0
    def test_run_tasks(self):
        # Crate a mocked method
        m_method = mock.Mock()
        m_run = FirstTimeRun()

        m_run.add_task(self.fake_task)
        # Force mocked method into the tasks list
        m_run._tasks.append(m_method)

        m_run._run_tasks()

        m_method.assert_called_once()
コード例 #6
0
    def test_constructor(self):
        m_method = mock.Mock()

        self.assertEqual(0, len(FirstTimeRun._tasks))
        self.assertEqual(0, len(FirstTimeRun._checks))

        FirstTimeRun.add_check(self.fake_check_true)
        FirstTimeRun.add_check(self.fake_check_false)
        FirstTimeRun.add_task(self.fake_task())
        FirstTimeRun._tasks.append(m_method)

        FirstTimeRun()

        m_method.assert_called_once()
コード例 #7
0
    def test_run_check_tasks_except_task(self, m_log):
        # Crate a mocked method
        m_method = mock.Mock()
        m_method.side_effect = Exception("Whoops")
        m_run = FirstTimeRun()

        check_task = FirstTimeRun.CheckTask(self.fake_check_true, m_method)
        # Force mocked method into the tasks list
        m_run._check_tasks.append(check_task)

        m_run._run_check_tasks()

        m_method.assert_called_once()
        m_log.error.assert_called_once()
コード例 #8
0
    def test_run_tasks_error(self, m_log):
        # Crate a mocked method
        m_method = mock.Mock()
        m_method.side_effect = Exception("Whoops")
        m_run = FirstTimeRun()

        m_run.add_task(self.fake_task)
        # Force mocked method into the tasks list
        m_run._tasks.append(m_method)

        m_run._run_tasks()

        m_method.assert_called_once()
        m_log.error.assert_called_once()
コード例 #9
0
    def test_run_checks_error(self, m_log):
        m_run = FirstTimeRun()
        m_run._checks.append(True)

        self.assertFalse(m_run._run_checks())
        m_log.error.assert_called_once()
コード例 #10
0
    def test_run_checks_all_true(self):
        m_run = FirstTimeRun()
        m_run.add_check(self.fake_check_true)
        m_run.add_check(self.fake_check_true)

        self.assertTrue(m_run._run_checks(all_to_init=True))
コード例 #11
0
    def test_run_checks_true(self):
        m_run = FirstTimeRun()
        m_run.add_check(self.fake_check_true)

        self.assertTrue(m_run._run_checks())
コード例 #12
0
    def test_run_checks_false(self):
        m_run = FirstTimeRun()
        m_run.add_check(self.fake_check_false)

        self.assertFalse(m_run._run_checks())