def get_runner(module_name, config=None): """ Load the module and return an instance of the runner. """ LOG.debug('Runner loading python module: %s', module_name) try: # TODO: Explore modifying this to support register_plugin module = register_runner(module_name) except Exception as e: msg = ('Failed to import runner module %s' % module_name) LOG.exception(msg) raise ActionRunnerCreateError('%s\n\n%s' % (msg, str(e))) LOG.debug('Instance of runner module: %s', module) if config: runner_kwargs = {'config': config} else: runner_kwargs = {} runner = module.get_runner(**runner_kwargs) LOG.debug('Instance of runner: %s', runner) return runner
def test_register_runner(self): runner = loader.register_runner(MOCK_RUNNER_NAME) self.assertIsNotNone(runner) self.assertEqual(MOCK_RUNNER_NAME, runner.__name__) self.assertIn(MOCK_RUNNER_NAME, loader.RUNNER_MODULES_CACHE) self.assertEqual(runner, loader.RUNNER_MODULES_CACHE[MOCK_RUNNER_NAME])
def get_runner(package_name, module_name, config=None): """ Load the module and return an instance of the runner. """ if not package_name: # Backward compatibility for Pre 2.7.0 where package name always equaled module name package_name = module_name LOG.debug('Runner loading Python module: %s.%s', package_name, module_name) try: # TODO: Explore modifying this to support register_plugin module = register_runner(package_name=package_name, module_name=module_name) except Exception as e: msg = ('Failed to import runner module %s.%s' % (package_name, module_name)) LOG.exception(msg) raise ActionRunnerCreateError('%s\n\n%s' % (msg, str(e))) LOG.debug('Instance of runner module: %s', module) if config: runner_kwargs = {'config': config} else: runner_kwargs = {} runner = module.get_runner(**runner_kwargs) LOG.debug('Instance of runner: %s', runner) return runner
def test_register_runner(self): runner = loader.register_runner(MOCK_RUNNER_NAME, MOCK_RUNNER_NAME) self.assertIsNotNone(runner) self.assertEqual(MOCK_RUNNER_NAME, runner.__name__) self.assertIn(MOCK_RUNNER_NAME, loader.RUNNER_MODULES_CACHE) self.assertEqual(runner, loader.RUNNER_MODULES_CACHE[MOCK_RUNNER_NAME][MOCK_RUNNER_NAME])
def test_register_runner(self): runner = loader.register_runner('mock_runner') self.assertIsNotNone(runner) self.assertEqual('mock_runner', runner.__name__) self.assertIn('mock_runner', loader.RUNNER_MODULES_CACHE) self.assertEqual(runner, loader.RUNNER_MODULES_CACHE['mock_runner'])
def test_register_runner_again(self): runner1 = loader.register_runner(MOCK_RUNNER_NAME) self.assertEqual(1, imp.load_source.call_count) self.assertIsNotNone(runner1) self.assertEqual(MOCK_RUNNER_NAME, runner1.__name__) self.assertIn(MOCK_RUNNER_NAME, loader.RUNNER_MODULES_CACHE) self.assertEqual(runner1, loader.RUNNER_MODULES_CACHE[MOCK_RUNNER_NAME]) runner2 = loader.register_runner(MOCK_RUNNER_NAME) self.assertEqual(1, imp.load_source.call_count) self.assertEqual(runner1, runner2) self.assertIsNotNone(runner2) self.assertEqual(MOCK_RUNNER_NAME, runner2.__name__) self.assertIn(MOCK_RUNNER_NAME, loader.RUNNER_MODULES_CACHE) self.assertEqual(runner2, loader.RUNNER_MODULES_CACHE[MOCK_RUNNER_NAME])
def test_register_runner_again(self): runner1 = loader.register_runner(MOCK_RUNNER_NAME, MOCK_RUNNER_NAME) self.assertEqual(1, imp.load_source.call_count) self.assertIsNotNone(runner1) self.assertEqual(MOCK_RUNNER_NAME, runner1.__name__) self.assertIn(MOCK_RUNNER_NAME, loader.RUNNER_MODULES_CACHE) self.assertEqual(runner1, loader.RUNNER_MODULES_CACHE[MOCK_RUNNER_NAME][MOCK_RUNNER_NAME]) runner2 = loader.register_runner(MOCK_RUNNER_NAME, MOCK_RUNNER_NAME) self.assertEqual(1, imp.load_source.call_count) self.assertEqual(runner1, runner2) self.assertIsNotNone(runner2) self.assertEqual(MOCK_RUNNER_NAME, runner2.__name__) self.assertIn(MOCK_RUNNER_NAME, loader.RUNNER_MODULES_CACHE) self.assertEqual(runner2, loader.RUNNER_MODULES_CACHE[MOCK_RUNNER_NAME][MOCK_RUNNER_NAME])
def test_register_runner_again(self): runner1 = loader.register_runner('mock_runner') self.assertEqual(1, imp.load_source.call_count) self.assertIsNotNone(runner1) self.assertEqual('mock_runner', runner1.__name__) self.assertIn('mock_runner', loader.RUNNER_MODULES_CACHE) self.assertEqual(runner1, loader.RUNNER_MODULES_CACHE['mock_runner']) runner2 = loader.register_runner('mock_runner') self.assertEqual(1, imp.load_source.call_count) self.assertEqual(runner1, runner2) self.assertIsNotNone(runner2) self.assertEqual('mock_runner', runner2.__name__) self.assertIn('mock_runner', loader.RUNNER_MODULES_CACHE) self.assertEqual(runner2, loader.RUNNER_MODULES_CACHE['mock_runner'])
def get_runner(module_name): """Load the module and return an instance of the runner.""" LOG.debug('Runner loading python module: %s', module_name) try: # TODO: Explore modifying this to support register_plugin module = register_runner(module_name) except Exception as e: LOG.exception('Failed to import module %s.', module_name) raise ActionRunnerCreateError(e) LOG.debug('Instance of runner module: %s', module) runner = module.get_runner() LOG.debug('Instance of runner: %s', runner) return runner