def test_add_new(self): """Add a new plugin to the scheduler.""" CONF.set_override('enable', True, 'scheduler') self.assertIsNone(scheduler.SCHEDULER) scheduler.initialize_scheduler() mock_plugin = MockPlugin(dict()) mock_plugin_name = mock_plugin.get_name() mock_extensions = [ Extension(mock_plugin_name, None, None, mock_plugin) ] loader = StoryboardPluginLoader.make_test_instance( mock_extensions, namespace='storyboard.plugin.testing' ) test_list = list() loader.map(scheduler.add_plugins, test_list) self.assertTrue(test_list.index(mock_plugin_name) == 0) self.assertIsNotNone(scheduler.SCHEDULER.get_job(mock_plugin_name)) scheduler.shutdown_scheduler() self.assertIsNone(scheduler.SCHEDULER) CONF.clear_override('enable', 'scheduler')
def setup_app(pecan_config=None): if not pecan_config: pecan_config = get_pecan_config() # Setup logging cfg.set_defaults(_options.log_opts, default_log_levels=[ 'storyboard=INFO', 'storyboard.openstack.common.db=WARN', 'sqlalchemy=WARN' ]) log.setup(CONF, 'storyboard') hooks = [ session_hook.DBSessionHook(), user_id_hook.UserIdHook(), validation_hook.ValidationHook() ] # Setup search engine search_engine_name = CONF.search_engine search_engine_cls = search_engine_impls.ENGINE_IMPLS[search_engine_name] search_engine.set_engine(search_engine_cls()) # Load user preference plugins initialize_user_preferences() # Initialize scheduler initialize_scheduler() # Setup notifier if CONF.enable_notifications: hooks.append(NotificationHook()) app = pecan.make_app( pecan_config.app.root, debug=CONF.debug, hooks=hooks, force_canonical=getattr(pecan_config.app, 'force_canonical', True), guess_content_type_from_ext=False ) app = token_middleware.AuthTokenMiddleware(app) # Setup CORS if CONF.cors.allowed_origins: app = CORSMiddleware(app, allowed_origins=CONF.cors.allowed_origins, allowed_methods=['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], allowed_headers=['origin', 'authorization', 'accept', 'x-total', 'x-limit', 'x-marker', 'x-client', 'content-type'], max_age=CONF.cors.max_age) return app
def test_disabled_initialize(self): """Test that the initialize method does nothing when disabled.""" CONF.set_override('enable', False, 'scheduler') self.assertIsNone(scheduler.SCHEDULER) scheduler.initialize_scheduler() self.assertIsNone(scheduler.SCHEDULER) CONF.clear_override('enable', 'scheduler')
def setup_app(pecan_config=None): if not pecan_config: pecan_config = get_pecan_config() # Setup logging cfg.set_defaults(_options.log_opts, default_log_levels=[ 'storyboard=INFO', 'storyboard.openstack.common.db=WARN', 'sqlalchemy=WARN' ]) log.setup(CONF, 'storyboard') hooks = [ session_hook.DBSessionHook(), user_id_hook.UserIdHook(), validation_hook.ValidationHook() ] # Setup search engine search_engine_name = CONF.search_engine search_engine_cls = search_engine_impls.ENGINE_IMPLS[search_engine_name] search_engine.set_engine(search_engine_cls()) # Load user preference plugins initialize_user_preferences() # Initialize scheduler initialize_scheduler() # Setup notifier if CONF.enable_notifications: hooks.append(NotificationHook()) app = pecan.make_app(pecan_config.app.root, debug=CONF.debug, hooks=hooks, force_canonical=getattr(pecan_config.app, 'force_canonical', True), guess_content_type_from_ext=False) app = token_middleware.AuthTokenMiddleware(app) # Setup CORS if CONF.cors.allowed_origins: app = CORSMiddleware( app, allowed_origins=CONF.cors.allowed_origins, allowed_methods=['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], allowed_headers=[ 'origin', 'authorization', 'accept', 'x-total', 'x-limit', 'x-marker', 'x-client', 'content-type' ], max_age=CONF.cors.max_age) return app
def test_enabled_initialize(self): """Test that the initialize and shutdown methods work when enabled.""" CONF.set_override('enable', True, 'scheduler') self.assertIsNone(scheduler.SCHEDULER) scheduler.initialize_scheduler() self.assertIsNotNone(scheduler.SCHEDULER) scheduler.shutdown_scheduler() self.assertIsNone(scheduler.SCHEDULER) CONF.clear_override('enable', 'scheduler')
def test_add_plugins_reschedule(self): """Assert that the test_add_plugins will reschedule existing plugins. """ CONF.set_override('enable', True, 'scheduler') self.assertIsNone(scheduler.SCHEDULER) scheduler.initialize_scheduler() mock_plugin = MockPlugin(dict()) mock_plugin_name = mock_plugin.get_name() mock_extensions = [ Extension(mock_plugin_name, None, None, mock_plugin) ] loader = StoryboardPluginLoader.make_test_instance( mock_extensions, namespace='storyboard.plugin.testing' ) test_list = list() loader.map(scheduler.add_plugins, test_list) self.assertTrue(test_list.index(mock_plugin_name) == 0) first_run_job = scheduler.SCHEDULER.get_job(mock_plugin_name) first_run_trigger = first_run_job.trigger self.assertEqual(mock_plugin._trigger.run_date, first_run_trigger.run_date) # Update the plugin's interval and re-run new_date = datetime.datetime.now() + datetime.timedelta(days=2) mock_plugin._trigger = DateTrigger(run_date=new_date) test_list = list() loader.map(scheduler.add_plugins, test_list) # make sure the plugin is only loaded once. self.assertTrue(test_list.index(mock_plugin_name) == 0) self.assertEquals(len(test_list), 1) # Get the job. second_run_job = scheduler.SCHEDULER.get_job(mock_plugin_name) second_run_trigger = second_run_job.trigger self.assertNotEqual(second_run_trigger.run_date, first_run_trigger.run_date) scheduler.shutdown_scheduler() self.assertIsNone(scheduler.SCHEDULER) CONF.clear_override('enable', 'scheduler')
def test_intialize_with_manager(self): """Assert that the management plugin is loaded, and runs every minute. """ CONF.set_override('enable', True, 'scheduler') self.assertIsNone(scheduler.SCHEDULER) scheduler.initialize_scheduler() self.assertIsNotNone(scheduler.SCHEDULER) manager_job = scheduler.SCHEDULER \ .get_job(scheduler.SCHEDULE_MANAGER_ID) self.assertIsNotNone(manager_job) trigger = manager_job.trigger self.assertIsInstance(trigger, IntervalTrigger) self.assertEqual(60, trigger.interval_length) self.assertEqual(scheduler.SCHEDULE_MANAGER_ID, manager_job.id) scheduler.shutdown_scheduler() self.assertIsNone(scheduler.SCHEDULER) CONF.clear_override('enable', 'scheduler')