def setup_runner(cls): test_runner = { 'name': 'test-runner', 'description': 'A test runner.', 'enabled': True, 'runner_parameters': { 'runnerstr': { 'description': 'Foo str param.', 'type': 'string', 'default': 'defaultfoo' }, 'runnerint': { 'description': 'Foo int param.', 'type': 'number' }, 'runnerdummy': { 'description': 'Dummy param.', 'type': 'string', 'default': 'runnerdummy' }, 'runnerimmutable': { 'description': 'Immutable param.', 'type': 'string', 'default': 'runnerimmutable', 'immutable': True } }, 'runner_module': 'tests.test_runner' } runnertype_api = RunnerTypeAPI(**test_runner) RunnerContainerTest.runnertype_db = RunnerType.add_or_update( RunnerTypeAPI.to_model(runnertype_api)) test_failingrunner = { 'name': 'test-failingrunner', 'description': 'A failing test runner.', 'enabled': True, 'runner_parameters': { 'raise': { 'description': 'Foo str param.', 'type': 'boolean', 'default': True, 'immutable': True } }, 'runner_module': 'tests.test_runner' } runnertype_api = RunnerTypeAPI(**test_failingrunner) RunnerContainerTest.runnertype_db = RunnerType.add_or_update( RunnerTypeAPI.to_model(runnertype_api))
def setup_runner(cls): test_runner = { 'name': 'test-runner', 'description': 'A test runner.', 'enabled': True, 'runner_parameters': { 'runnerstr': { 'description': 'Foo str param.', 'type': 'string', 'default': 'defaultfoo' }, 'runnerint': { 'description': 'Foo int param.', 'type': 'number' }, 'runnerdummy': { 'description': 'Dummy param.', 'type': 'string', 'default': 'runnerdummy' } }, 'runner_module': 'tests.test_runner' } runnertype_api = RunnerTypeAPI(**test_runner) ActionDBUtilsTestCase.runnertype_db = RunnerType.add_or_update( RunnerTypeAPI.to_model(runnertype_api))
def register_runner_types(): LOG.info('Start : register default RunnerTypes.') for runnertype in RUNNER_TYPES: try: runnertype_db = get_runnertype_by_name(runnertype['name']) update = True except StackStormDBObjectNotFoundError: runnertype_db = None update = False runnertype_api = RunnerTypeAPI(**runnertype) runner_type_model = RunnerTypeAPI.to_model(runnertype_api) if runnertype_db: runner_type_model.id = runnertype_db.id try: runnertype_db = RunnerType.add_or_update(runner_type_model) if update: LOG.audit('RunnerType updated. RunnerType %s', runnertype_db) else: LOG.audit('RunnerType created. RunnerType %s', runnertype_db) except Exception: LOG.exception('Unable to register runner type %s.', runnertype['name']) LOG.info('End : register default RunnerTypes.')
def register_runner(runner_type, experimental): # For backward compatibility reasons, we also register runners under the old names runner_names = [runner_type['name']] + runner_type.get('aliases', []) for runner_name in runner_names: runner_type['name'] = runner_name runner_experimental = runner_type.get('experimental', False) if runner_experimental and not experimental: LOG.debug('Skipping experimental runner "%s"' % (runner_name)) continue # Remove additional, non db-model attributes non_db_attributes = ['experimental', 'aliases'] for attribute in non_db_attributes: if attribute in runner_type: del runner_type[attribute] try: runner_type_db = get_runnertype_by_name(runner_name) update = True except StackStormDBObjectNotFoundError: runner_type_db = None update = False # Note: We don't want to overwrite "enabled" attribute which is already in the database # (aka we don't want to re-enable runner which has been disabled by the user) if runner_type_db and runner_type_db['enabled'] != runner_type[ 'enabled']: runner_type['enabled'] = runner_type_db['enabled'] # If package is not provided, assume it's the same as module name for backward # compatibility reasons if not runner_type.get('runner_package', None): runner_type['runner_package'] = runner_type['runner_module'] runner_type_api = RunnerTypeAPI(**runner_type) runner_type_api.validate() runner_type_model = RunnerTypeAPI.to_model(runner_type_api) if runner_type_db: runner_type_model.id = runner_type_db.id try: runner_type_db = RunnerType.add_or_update(runner_type_model) extra = {'runner_type_db': runner_type_db} if update: LOG.audit('RunnerType updated. RunnerType %s', runner_type_db, extra=extra) else: LOG.audit('RunnerType created. RunnerType %s', runner_type_db, extra=extra) except Exception: LOG.exception('Unable to register runner type %s.', runner_type['name']) return 0 return 1
def setUpClass(cls): super(TestActionExecutionService, cls).setUpClass() cls.runner = RunnerTypeAPI(**RUNNER) cls.runnerdb = RunnerType.add_or_update(RunnerTypeAPI.to_model(cls.runner)) cls.action = ActionAPI(**ACTION) cls.actiondb = Action.add_or_update(ActionAPI.to_model(cls.action)) cls.container = RunnerContainer()
def register_runner_types(): LOG.debug('Start : register default RunnerTypes.') for runnertype in RUNNER_TYPES: try: runnertype_db = get_runnertype_by_name(runnertype['name']) update = True except StackStormDBObjectNotFoundError: runnertype_db = None update = False runnertype_api = RunnerTypeAPI(**runnertype) runnertype_api.validate() runner_type_model = RunnerTypeAPI.to_model(runnertype_api) if runnertype_db: runner_type_model.id = runnertype_db.id try: runnertype_db = RunnerType.add_or_update(runner_type_model) extra = {'runnertype_db': runnertype_db} if update: LOG.audit('RunnerType updated. RunnerType %s', runnertype_db, extra=extra) else: LOG.audit('RunnerType created. RunnerType %s', runnertype_db, extra=extra) except Exception: LOG.exception('Unable to register runner type %s.', runnertype['name']) LOG.debug('End : register default RunnerTypes.')
def setup_runner(cls): test_runner = { "name": "test-runner", "description": "A test runner.", "enabled": True, "runner_parameters": { "runnerstr": { "description": "Foo str param.", "type": "string", "default": "defaultfoo", }, "runnerint": { "description": "Foo int param.", "type": "number" }, "runnerdummy": { "description": "Dummy param.", "type": "string", "default": "runnerdummy", }, }, "runner_module": "tests.test_runner", } runnertype_api = RunnerTypeAPI(**test_runner) ActionDBUtilsTestCase.runnertype_db = RunnerType.add_or_update( RunnerTypeAPI.to_model(runnertype_api))
def setUpClass(cls): super(TestActionExecutionService, cls).setUpClass() cls.runner = RunnerTypeAPI(**RUNNER) cls.runnerdb = RunnerType.add_or_update( RunnerTypeAPI.to_model(cls.runner)) cls.actions = { ACTION['name']: ActionAPI(**ACTION), ACTION_OVR_PARAM['name']: ActionAPI(**ACTION_OVR_PARAM), ACTION_OVR_PARAM_MUTABLE['name']: ActionAPI(**ACTION_OVR_PARAM_MUTABLE), ACTION_OVR_PARAM_IMMUTABLE['name']: ActionAPI(**ACTION_OVR_PARAM_IMMUTABLE), ACTION_OVR_PARAM_BAD_ATTR['name']: ActionAPI(**ACTION_OVR_PARAM_BAD_ATTR), ACTION_OVR_PARAM_BAD_ATTR_NOOP['name']: ActionAPI(**ACTION_OVR_PARAM_BAD_ATTR_NOOP) } cls.actiondbs = { name: Action.add_or_update(ActionAPI.to_model(action)) for name, action in six.iteritems(cls.actions) } cls.container = RunnerContainer()
def _setup_runner_models(cls): test_runner = { 'name': 'test-runner', 'description': 'A test runner.', 'enabled': True, 'runner_parameters': { 'runnerstr': { 'description': 'Foo str param.', 'type': 'string', 'default': 'defaultfoo' }, 'runnerint': { 'description': 'Foo int param.', 'type': 'number' }, 'runnerdummy': { 'description': 'Dummy param.', 'type': 'string', 'default': 'runnerdummy' }, 'runnerimmutable': { 'description': 'Immutable param.', 'type': 'string', 'default': 'runnerimmutable', 'immutable': True } }, 'runner_module': 'tests.test_runner' } runnertype_api = RunnerTypeAPI(**test_runner) ParamsUtilsTest.runnertype_db = RunnerTypeAPI.to_model(runnertype_api)
def setUpClass(cls): super(TestActionExecutionService, cls).setUpClass() cls.runner = RunnerTypeAPI(**RUNNER) cls.runnerdb = RunnerType.add_or_update( RunnerTypeAPI.to_model(cls.runner)) cls.action = ActionAPI(**ACTION) cls.actiondb = Action.add_or_update(ActionAPI.to_model(cls.action)) cls.container = RunnerContainer()
def setUpClass(cls): super(ActionParamsUtilsTest, cls).setUpClass() cls.runnertype = RunnerTypeAPI( **FIXTURES['runners']['testrunner1.yaml']) cls.runnertype_db = RunnerType.add_or_update( RunnerTypeAPI.to_model(cls.runnertype)) cls.action = ActionAPI(**FIXTURES['actions']['action1.yaml']) cls.action_db = Action.add_or_update(ActionAPI.to_model(cls.action))
def setUpClass(cls): super(TestActionAPIValidator, cls).setUpClass() runner_api_dict = fixture.ARTIFACTS['runners']['run-local'] runner_api = RunnerTypeAPI(**runner_api_dict) runner_model = RunnerTypeAPI.to_model(runner_api) RunnerType.add_or_update(runner_model)
def setUpClass(cls): super(TestStreamController, cls).setUpClass() instance = RunnerTypeAPI(**RUNNER_TYPE_1) RunnerType.add_or_update(RunnerTypeAPI.to_model(instance)) instance = ActionAPI(**ACTION_1) Action.add_or_update(ActionAPI.to_model(instance))
def register_runner_types(experimental=False): """ :param experimental: True to also register experimental runners. :type experimental: ``bool`` """ LOG.debug('Start : register default RunnerTypes.') for runner_type in RUNNER_TYPES: runner_type = copy.deepcopy(runner_type) # For backward compatibility reasons, we also register runners under the old names runner_names = [runner_type['name']] + runner_type.get('aliases', []) for runner_name in runner_names: runner_type['name'] = runner_name runner_experimental = runner_type.get('experimental', False) if runner_experimental and not experimental: LOG.debug('Skipping experimental runner "%s"' % (runner_name)) continue # Remove additional, non db-model attributes non_db_attributes = ['experimental', 'aliases'] for attribute in non_db_attributes: if attribute in runner_type: del runner_type[attribute] try: runner_type_db = get_runnertype_by_name(runner_name) update = True except StackStormDBObjectNotFoundError: runner_type_db = None update = False # Note: We don't want to overwrite "enabled" attribute which is already in the database # (aka we don't want to re-enable runner which has been disabled by the user) if runner_type_db and runner_type_db['enabled'] != runner_type['enabled']: runner_type['enabled'] = runner_type_db['enabled'] runner_type_api = RunnerTypeAPI(**runner_type) runner_type_api.validate() runner_type_model = RunnerTypeAPI.to_model(runner_type_api) if runner_type_db: runner_type_model.id = runner_type_db.id try: runner_type_db = RunnerType.add_or_update(runner_type_model) extra = {'runner_type_db': runner_type_db} if update: LOG.audit('RunnerType updated. RunnerType %s', runner_type_db, extra=extra) else: LOG.audit('RunnerType created. RunnerType %s', runner_type_db, extra=extra) except Exception: LOG.exception('Unable to register runner type %s.', runner_type['name']) LOG.debug('End : register default RunnerTypes.')
def register_runner_types(experimental=False): """ :param experimental: True to also register experimental runners. :type experimental: ``bool`` """ LOG.debug('Start : register default RunnerTypes.') for runner_type in RUNNER_TYPES: runner_type = copy.deepcopy(runner_type) # For backward compatibility reasons, we also register runners under the old names runner_names = [runner_type['name']] + runner_type.get('aliases', []) for runner_name in runner_names: runner_type['name'] = runner_name runner_experimental = runner_type.get('experimental', False) if runner_experimental and not experimental: LOG.debug('Skipping experimental runner "%s"' % (runner_name)) continue # Remove additional, non db-model attributes non_db_attributes = ['experimental', 'aliases'] for attribute in non_db_attributes: if attribute in runner_type: del runner_type[attribute] try: runner_type_db = get_runnertype_by_name(runner_name) update = True except StackStormDBObjectNotFoundError: runner_type_db = None update = False runner_type_api = RunnerTypeAPI(**runner_type) runner_type_api.validate() runner_type_model = RunnerTypeAPI.to_model(runner_type_api) if runner_type_db: runner_type_model.id = runner_type_db.id try: runner_type_db = RunnerType.add_or_update(runner_type_model) extra = {'runner_type_db': runner_type_db} if update: LOG.audit('RunnerType updated. RunnerType %s', runner_type_db, extra=extra) else: LOG.audit('RunnerType created. RunnerType %s', runner_type_db, extra=extra) except Exception: LOG.exception('Unable to register runner type %s.', runner_type['name']) LOG.debug('End : register default RunnerTypes.')
def setUpClass(cls): super(DSLTransformTestCase, cls).setUpClass() for _, fixture in six.iteritems(FIXTURES['runners']): instance = RunnerTypeAPI(**fixture) RunnerType.add_or_update(RunnerTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['actions']): instance = ActionAPI(**fixture) Action.add_or_update(ActionAPI.to_model(instance))
def setUpClass(cls): super(MistralValidationControllerTest, cls).setUpClass() for _, fixture in six.iteritems(FIXTURES['runners']): instance = RunnerTypeAPI(**fixture) RunnerType.add_or_update(RunnerTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['actions']): instance = ActionAPI(**fixture) Action.add_or_update(ActionAPI.to_model(instance))
def setUpClass(cls): super(SchedulerTest, cls).setUpClass() for _, fixture in six.iteritems(FIXTURES['runners']): instance = RunnerTypeAPI(**fixture) RunnerType.add_or_update(RunnerTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['actions']): instance = ActionAPI(**fixture) Action.add_or_update(ActionAPI.to_model(instance))
def setUpClass(cls): super(DSLTransformTestCase, cls).setUpClass() runners_registrar.register_runner_types() for _, fixture in six.iteritems(FIXTURES['runners']): instance = RunnerTypeAPI(**fixture) RunnerType.add_or_update(RunnerTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['actions']): instance = ActionAPI(**fixture) Action.add_or_update(ActionAPI.to_model(instance))
def register_runner(runner_type, experimental): # For backward compatibility reasons, we also register runners under the old names runner_names = [runner_type['name']] + runner_type.get('aliases', []) for runner_name in runner_names: runner_type['name'] = runner_name runner_experimental = runner_type.get('experimental', False) if runner_experimental and not experimental: LOG.debug('Skipping experimental runner "%s"' % (runner_name)) continue # Remove additional, non db-model attributes non_db_attributes = ['experimental', 'aliases'] for attribute in non_db_attributes: if attribute in runner_type: del runner_type[attribute] try: runner_type_db = get_runnertype_by_name(runner_name) update = True except StackStormDBObjectNotFoundError: runner_type_db = None update = False # Note: We don't want to overwrite "enabled" attribute which is already in the database # (aka we don't want to re-enable runner which has been disabled by the user) if runner_type_db and runner_type_db['enabled'] != runner_type['enabled']: runner_type['enabled'] = runner_type_db['enabled'] # If package is not provided, assume it's the same as module name for backward # compatibility reasons if not runner_type.get('runner_package', None): runner_type['runner_package'] = runner_type['runner_module'] runner_type_api = RunnerTypeAPI(**runner_type) runner_type_api.validate() runner_type_model = RunnerTypeAPI.to_model(runner_type_api) if runner_type_db: runner_type_model.id = runner_type_db.id try: runner_type_db = RunnerType.add_or_update(runner_type_model) extra = {'runner_type_db': runner_type_db} if update: LOG.audit('RunnerType updated. RunnerType %s', runner_type_db, extra=extra) else: LOG.audit('RunnerType created. RunnerType %s', runner_type_db, extra=extra) except Exception: LOG.exception('Unable to register runner type %s.', runner_type['name']) return 0 return 1
def setUpClass(cls): super(MistralValidationTest, cls).setUpClass() for _, fixture in six.iteritems(FIXTURES["runners"]): instance = RunnerTypeAPI(**fixture) RunnerType.add_or_update(RunnerTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES["actions"]): instance = ActionAPI(**fixture) Action.add_or_update(ActionAPI.to_model(instance)) cls.validator = wf_validation_utils.get_validator()
def setUpClass(cls): super(MistralValidationTest, cls).setUpClass() for _, fixture in six.iteritems(FIXTURES['runners']): instance = RunnerTypeAPI(**fixture) RunnerType.add_or_update(RunnerTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['actions']): instance = ActionAPI(**fixture) Action.add_or_update(ActionAPI.to_model(instance)) cls.validator = wf_validation_utils.get_validator()
def register_runner_types(experimental=False): """ :param experimental: True to also register experimental runners. :type experimental: ``bool`` """ LOG.debug("Start : register default RunnerTypes.") for runner_type in RUNNER_TYPES: runner_type = copy.deepcopy(runner_type) # For backward compatibility reasons, we also register runners under the old names runner_names = [runner_type["name"]] + runner_type.get("aliases", []) for runner_name in runner_names: runner_type["name"] = runner_name runner_experimental = runner_type.get("experimental", False) if runner_experimental and not experimental: LOG.debug('Skipping experimental runner "%s"' % (runner_name)) continue # Remove additional, non db-model attributes non_db_attributes = ["experimental", "aliases"] for attribute in non_db_attributes: if attribute in runner_type: del runner_type[attribute] try: runner_type_db = get_runnertype_by_name(runner_name) update = True except StackStormDBObjectNotFoundError: runner_type_db = None update = False runner_type_api = RunnerTypeAPI(**runner_type) runner_type_api.validate() runner_type_model = RunnerTypeAPI.to_model(runner_type_api) if runner_type_db: runner_type_model.id = runner_type_db.id try: runner_type_db = RunnerType.add_or_update(runner_type_model) extra = {"runner_type_db": runner_type_db} if update: LOG.audit("RunnerType updated. RunnerType %s", runner_type_db, extra=extra) else: LOG.audit("RunnerType created. RunnerType %s", runner_type_db, extra=extra) except Exception: LOG.exception("Unable to register runner type %s.", runner_type["name"]) LOG.debug("End : register default RunnerTypes.")
def setUpClass(cls): super(TestActionExecutionService, cls).setUpClass() cls.runner = RunnerTypeAPI(**RUNNER) cls.runnerdb = RunnerType.add_or_update(RunnerTypeAPI.to_model(cls.runner)) runner_api = RunnerTypeAPI(**RUNNER_ACTION_CHAIN) RunnerType.add_or_update(RunnerTypeAPI.to_model(runner_api)) cls.actions = { ACTION['name']: ActionAPI(**ACTION), ACTION_WORKFLOW['name']: ActionAPI(**ACTION_WORKFLOW), ACTION_OVR_PARAM['name']: ActionAPI(**ACTION_OVR_PARAM), ACTION_OVR_PARAM_MUTABLE['name']: ActionAPI(**ACTION_OVR_PARAM_MUTABLE), ACTION_OVR_PARAM_IMMUTABLE['name']: ActionAPI(**ACTION_OVR_PARAM_IMMUTABLE), ACTION_OVR_PARAM_BAD_ATTR['name']: ActionAPI(**ACTION_OVR_PARAM_BAD_ATTR), ACTION_OVR_PARAM_BAD_ATTR_NOOP['name']: ActionAPI(**ACTION_OVR_PARAM_BAD_ATTR_NOOP) } cls.actiondbs = {name: Action.add_or_update(ActionAPI.to_model(action)) for name, action in six.iteritems(cls.actions)} cls.container = RunnerContainer()
def setUpClass(cls): super(ActionParamsUtilsTest, cls).setUpClass() cls.runnertype_dbs = {} cls.action_dbs = {} for _, fixture in six.iteritems(FIXTURES['runners']): instance = RunnerTypeAPI(**fixture) runnertype_db = RunnerType.add_or_update(RunnerTypeAPI.to_model(instance)) cls.runnertype_dbs[runnertype_db.name] = runnertype_db for _, fixture in six.iteritems(FIXTURES['actions']): instance = ActionAPI(**fixture) action_db = Action.add_or_update(ActionAPI.to_model(instance)) cls.action_dbs[action_db.name] = action_db
def setUpClass(cls): super(ActionParamsUtilsTest, cls).setUpClass() cls.runnertype_dbs = {} cls.action_dbs = {} for _, fixture in six.iteritems(FIXTURES['runners']): instance = RunnerTypeAPI(**fixture) runnertype_db = RunnerType.add_or_update( RunnerTypeAPI.to_model(instance)) cls.runnertype_dbs[runnertype_db.name] = runnertype_db for _, fixture in six.iteritems(FIXTURES['actions']): instance = ActionAPI(**fixture) action_db = Action.add_or_update(ActionAPI.to_model(instance)) cls.action_dbs[action_db.name] = action_db
def setUpClass(cls): super(PolicyTest, cls).setUpClass() for _, fixture in six.iteritems(FIXTURES['runners']): instance = RunnerTypeAPI(**fixture) RunnerType.add_or_update(RunnerTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['actions']): instance = ActionAPI(**fixture) Action.add_or_update(ActionAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['policytypes']): instance = PolicyTypeAPI(**fixture) PolicyType.add_or_update(PolicyTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['policies']): instance = PolicyAPI(**fixture) Policy.add_or_update(PolicyAPI.to_model(instance))
def setUpClass(cls): EventletTestCase.setUpClass() DbTestCase.setUpClass() for _, fixture in six.iteritems(FIXTURES['runners']): instance = RunnerTypeAPI(**fixture) RunnerType.add_or_update(RunnerTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['actions']): instance = ActionAPI(**fixture) Action.add_or_update(ActionAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['policytypes']): instance = PolicyTypeAPI(**fixture) PolicyType.add_or_update(PolicyTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES['policies']): instance = PolicyAPI(**fixture) Policy.add_or_update(PolicyAPI.to_model(instance))
def setUp(self): EventletTestCase.setUpClass() DbTestCase.setUpClass() for _, fixture in six.iteritems(FIXTURES["runners"]): instance = RunnerTypeAPI(**fixture) RunnerType.add_or_update(RunnerTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES["actions"]): instance = ActionAPI(**fixture) Action.add_or_update(ActionAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES["policytypes"]): instance = PolicyTypeAPI(**fixture) PolicyType.add_or_update(PolicyTypeAPI.to_model(instance)) for _, fixture in six.iteritems(FIXTURES["policies"]): instance = PolicyAPI(**fixture) Policy.add_or_update(PolicyAPI.to_model(instance))
def register_runner_types(): try: default_remote_dir = cfg.CONF.ssh_runner.remote_dir except: default_remote_dir = '/tmp' RUNNER_TYPES = [ { 'name': 'run-local', 'description': 'A runner to execute local actions as a fixed user.', 'enabled': True, 'runner_parameters': { 'hosts': { 'description': 'Fixed to localhost as this action is run locally.', 'type': 'string', 'default': 'localhost', 'immutable': True }, 'cmd': { 'description': 'Arbitrary Linux command to be executed on the ' 'host.', 'type': 'string' }, 'parallel': { 'description': 'Default to parallel execution.', 'type': 'boolean', 'default': True, 'immutable': True }, 'sudo': { 'description': 'The command will be executed with sudo.', 'type': 'boolean', 'default': False }, 'dir': { 'description': 'The working directory where the command will be ' 'executed on the host.', 'type': 'string', 'default': default_remote_dir }, 'kwarg_op': { 'description': 'Operator to use in front of keyword args i.e. "--" or "-".', 'type': 'string', 'default': '--' } }, 'runner_module': 'st2actions.runners.fabricrunner' }, { 'name': 'run-local-script', 'description': 'A runner to execute local actions as a fixed user.', 'enabled': True, 'runner_parameters': { 'hosts': { 'description': 'Fixed to localhost as this action is run locally.', 'type': 'string', 'default': 'localhost', 'immutable': True }, 'parallel': { 'description': 'Default to parallel execution.', 'type': 'boolean', 'default': True, 'immutable': True }, 'sudo': { 'description': 'The command will be executed with sudo.', 'type': 'boolean', 'default': False }, 'dir': { 'description': 'The working directory where the command will be ' 'executed on the host.', 'type': 'string', 'default': default_remote_dir }, 'kwarg_op': { 'description': 'Operator to use in front of keyword args i.e. "--" or "-".', 'type': 'string', 'default': '--' } }, 'runner_module': 'st2actions.runners.fabricrunner' }, { 'name': 'run-remote', 'description': 'A remote execution runner that executes actions ' 'as a fixed system user.', 'enabled': True, 'runner_parameters': { 'hosts': { 'description': 'A comma delimited string of a list of hosts ' 'where the remote command will be executed.', 'type': 'string', 'required': True }, 'cmd': { 'description': 'Arbitrary Linux command to be executed on the ' 'remote host(s).', 'type': 'string' }, 'parallel': { 'description': 'Default to parallel execution.', 'type': 'boolean', 'default': True, 'immutable': True }, 'sudo': { 'description': 'The remote command will be executed with sudo.', 'type': 'boolean' }, 'dir': { 'description': 'The working directory where the command will be ' 'executed on the remote host.', 'type': 'string', 'default': default_remote_dir }, 'kwarg_op': { 'description': 'Operator to use in front of keyword args i.e. "--" or "-".', 'type': 'string', 'default': '--' } }, 'runner_module': 'st2actions.runners.fabricrunner' }, { 'name': 'run-remote-script', 'description': 'A remote execution runner that executes actions ' 'as a fixed system user.', 'enabled': True, 'runner_parameters': { 'hosts': { 'description': 'A comma delimited string of a list of hosts ' 'where the remote command will be executed.', 'type': 'string', 'required': True }, 'parallel': { 'description': 'Default to parallel execution.', 'type': 'boolean', 'default': True, 'immutable': True }, 'sudo': { 'description': 'The remote command will be executed with sudo.', 'type': 'boolean' }, 'dir': { 'description': 'The working directory where the command will be ' 'executed on the remote host.', 'type': 'string', 'default': default_remote_dir }, 'kwarg_op': { 'description': 'Operator to use in front of keyword args i.e. "--" or "-".', 'type': 'string', 'default': '--' } }, 'runner_module': 'st2actions.runners.fabricrunner' }, { 'name': 'http-runner', 'description': 'A HTTP client for running HTTP actions.', 'enabled': True, 'runner_parameters': { 'url': { 'description': 'URL to the HTTP endpoint.', 'type': 'string', 'required': True }, 'headers': { 'description': 'HTTP headers for the request.', 'type': 'string' }, 'cookies': { 'description': 'TODO: Description for cookies.', 'type': 'string' }, 'proxy': { 'description': 'TODO: Description for proxy.', 'type': 'string' }, 'redirects': { 'description': 'TODO: Description for redirects.', 'type': 'string' }, }, 'runner_module': 'st2actions.runners.httprunner' }, { 'name': 'mistral-v1', 'description': 'A runner for executing mistral v1 workflow.', 'enabled': True, 'runner_parameters': { 'workbook': { 'description': 'The name of the workbook.', 'type': 'string', 'required': True }, 'task': { 'description': 'The startup task in the workbook to execute.', 'type': 'string', 'required': True }, 'context': { 'description': 'Context for the startup task.', 'type': 'object', 'default': {} } }, 'runner_module': 'st2actions.runners.mistral.v1' }, { 'name': 'mistral-v2', 'description': 'A runner for executing mistral v2 workflow.', 'enabled': True, 'runner_parameters': { 'workflow': { 'description': 'The name of the workflow.', 'type': 'string', 'required': True }, 'context': { 'description': 'Context for the startup task.', 'type': 'object', 'default': {} } }, 'runner_module': 'st2actions.runners.mistral.v2' }, { 'name': 'action-chain', 'description': 'A runner for launching linear action chains.', 'enabled': True, 'runner_parameters': {}, 'runner_module': 'st2actions.runners.actionchainrunner' }, { 'name': 'run-python', 'description': 'A runner for launching python actions.', 'enabled': True, 'runner_parameters': {}, 'runner_module': 'st2actions.runners.pythonrunner' } ] LOG.info('Start : register default RunnerTypes.') for runnertype in RUNNER_TYPES: try: runnertype_db = get_runnertype_by_name(runnertype['name']) if runnertype_db: LOG.info('RunnerType name=%s exists.', runnertype['name']) continue except StackStormDBObjectNotFoundError: pass runnertype_api = RunnerTypeAPI(**runnertype) try: runnertype_db = RunnerType.add_or_update(RunnerTypeAPI.to_model(runnertype_api)) LOG.audit('RunnerType created. RunnerType %s', runnertype_db) except Exception: LOG.exception('Unable to register runner type %s.', runnertype['name']) LOG.info('End : register default RunnerTypes.')
def base(event, context, passthrough=False): # Set up logging logger = logging.getLogger() # Read DEBUG value from the environment variable debug = os.environ.get('ST2_DEBUG', False) if str(debug).lower() in ['true', '1']: debug = True if debug: logger.setLevel(logging.DEBUG) else: logger.setLevel(logging.INFO) if isinstance(event, basestring): try: event = json.loads(event) except ValueError as e: LOG.error("ERROR: Can not parse `event`: '{}'\n{}".format( str(event), str(e))) raise e LOG.info("Received event: " + json.dumps(event, indent=2)) # Special case for Lambda function being called over HTTP via API gateway # See # https://serverless.com/framework/docs/providers/aws/events/apigateway # #example-lambda-proxy-event-default # for details is_event_body_string = (isinstance(event.get('body'), basestring) is True) content_type = event.get('headers', {}).get('content-type', '').lower() if is_event_body_string: if content_type == 'application/json': try: event['body'] = json.loads(event['body']) except Exception as e: LOG.warn('`event` has `body` which is not JSON: %s', str(e.message)) elif content_type == 'application/x-www-form-urlencoded': try: event['body'] = dict( parse_qsl(['body'], keep_blank_values=True)) except Exception as e: LOG.warn('`event` has `body` which is not `%s`: %s', content_type, str(e.message)) else: LOG.warn('Unsupported event content type: %s' % (content_type)) action_name = os.environ['ST2_ACTION'] try: action_db = ACTIONS[action_name] except KeyError: raise ValueError('No action named "%s" has been installed.' % (action_name)) manager = DriverManager(namespace='st2common.runners.runner', invoke_on_load=False, name=action_db.runner_type['name']) runnertype_db = RunnerTypeAPI.to_model( RunnerTypeAPI(**manager.driver.get_metadata()[0])) if passthrough: runner = PassthroughRunner() else: runner = manager.driver.get_runner() runner._sandbox = False runner.runner_type_db = runnertype_db runner.action = action_db runner.action_name = action_db.name # runner.liveaction = liveaction_db # runner.liveaction_id = str(liveaction_db.id) # runner.execution = ActionExecution.get(liveaction__id=runner.liveaction_id) # runner.execution_id = str(runner.execution.id) runner.entry_point = content_utils.get_entry_point_abs_path( pack=action_db.pack, entry_point=action_db.entry_point) runner.context = {} # getattr(liveaction_db, 'context', dict()) # runner.callback = getattr(liveaction_db, 'callback', dict()) runner.libs_dir_path = content_utils.get_action_libs_abs_path( pack=action_db.pack, entry_point=action_db.entry_point) # For re-run, get the ActionExecutionDB in which the re-run is based on. # rerun_ref_id = runner.context.get('re-run', {}).get('ref') # runner.rerun_ex_ref = ActionExecution.get(id=rerun_ref_id) if rerun_ref_id else None config_schema = CONFIG_SCHEMAS.get(action_db.pack, None) config_values = os.environ.get('ST2_CONFIG', None) if config_schema and config_values: runner._config = validate_config_against_schema( config_schema=config_schema, config_object=json.loads(config_values), config_path=None, pack_name=action_db.pack) param_values = os.environ.get('ST2_PARAMETERS', None) try: if param_values: live_params = param_utils.render_live_params( runner_parameters=runnertype_db.runner_parameters, action_parameters=action_db.parameters, params=json.loads(param_values), action_context={}, additional_contexts={'input': event}) else: live_params = event if debug and 'log_level' not in live_params: # Set log_level runner parameter live_params['log_level'] = 'DEBUG' runner_params, action_params = param_utils.render_final_params( runner_parameters=runnertype_db.runner_parameters, action_parameters=action_db.parameters, params=live_params, action_context={}) except ParamException as e: raise actionrunner.ActionRunnerException(str(e)) runner.runner_parameters = runner_params LOG.debug('Performing pre-run for runner: %s', runner.runner_id) runner.pre_run() (status, output, context) = runner.run(action_params) output_values = os.environ.get('ST2_OUTPUT', None) if output_values: try: result = param_utils.render_live_params( runner_parameters=runnertype_db.runner_parameters, action_parameters=action_db.parameters, params=json.loads(output_values), action_context={}, additional_contexts={ 'input': event, 'output': output }) except ParamException as e: raise actionrunner.ActionRunnerException(str(e)) else: result = output # Log the logs generated by the action. We do that so the actual action logs # (action stderr) end up in CloudWatch output = output or {} if output.get('stdout', None): LOG.info('Action stdout: %s' % (output['stdout'])) if output.get('stderr', None): LOG.info('Action stderr and logs: %s' % (output['stderr'])) return { 'event': event, 'live_params': live_params, 'output': output, 'result': result }
def main(): # Read DEBUG value from the environment variable debug = os.environ.get('ST2_DEBUG', False) if str(debug).lower() in ['true', '1']: debug = True if debug: LOG.setLevel(logging.DEBUG) else: LOG.setLevel(logging.INFO) # Read input = os.environ.get('ST2_INPUT', {}) if isinstance(input, six.string_types): try: input = json.loads(input) except ValueError as e: LOG.error("ERROR: Can not parse `input`: '{}'\n{}".format(str(input), str(e))) raise e LOG.debug("Received input: " + json.dumps(input, indent=2)) # Read action name from environment variable action_name = os.environ['ST2_ACTION'] try: action_db = ACTIONS[action_name] except KeyError: raise ValueError('No action named "%s" has been installed.' % (action_name)) # Initialize runner manager = DriverManager(namespace='st2common.runners.runner', invoke_on_load=False, name=action_db.runner_type['name']) runnertype_db = RunnerTypeAPI.to_model(RunnerTypeAPI(**manager.driver.get_metadata())) runner = manager.driver.get_runner() runner._sandbox = False runner.runner_type_db = runnertype_db runner.action = action_db runner.action_name = action_db.name runner.entry_point = content_utils.get_entry_point_abs_path(pack=action_db.pack, entry_point=action_db.entry_point) runner.context = {} runner.libs_dir_path = content_utils.get_action_libs_abs_path(pack=action_db.pack, entry_point=action_db.entry_point) config_schema = CONFIG_SCHEMAS.get(action_db.pack, None) config_values = os.environ.get('ST2_CONFIG', None) if config_schema and config_values: runner._config = validate_config_against_schema(config_schema=config_schema, config_object=json.loads(config_values), config_path=None, pack_name=action_db.pack) param_values = os.environ.get('ST2_PARAMETERS', None) try: if param_values: live_params = param_utils.render_live_params( runner_parameters=runnertype_db.runner_parameters, action_parameters=action_db.parameters, params=json.loads(param_values), action_context={}, additional_contexts={ 'input': input }) else: live_params = input if debug and 'log_level' not in live_params: # Set log_level runner parameter live_params['log_level'] = 'DEBUG' runner_params, action_params = param_utils.render_final_params( runner_parameters=runnertype_db.runner_parameters, action_parameters=action_db.parameters, params=live_params, action_context={}) except ParamException as e: raise actionrunner.ActionRunnerException(str(e)) runner.runner_parameters = runner_params LOG.debug('Performing pre-run for runner: %s', runner.runner_id) runner.pre_run() (status, output, context) = runner.run(action_params) try: output['result'] = json.loads(output['result']) except Exception: pass output_values = os.environ.get('ST2_OUTPUT', None) if output_values: try: result = param_utils.render_live_params( runner_parameters={}, action_parameters={}, params=json.loads(output_values), action_context={}, additional_contexts={ 'input': input, 'output': output }) except ParamException as e: raise actionrunner.ActionRunnerException(str(e)) else: result = output output = output or {} if output.get('stdout', None): LOG.info('Action stdout: %s' % (output['stdout'])) if output.get('stderr', None): LOG.info('Action stderr and logs: %s' % (output['stderr'])) print(json.dumps(result))
def register_runner_types(): try: default_remote_dir = cfg.CONF.ssh_runner.remote_dir except: default_remote_dir = '/tmp' RUNNER_TYPES = [{ 'name': 'run-local', 'description': 'A runner to execute local actions as a fixed user.', 'enabled': True, 'runner_parameters': { 'hosts': { 'description': 'Fixed to localhost as this action is run locally.', 'type': 'string', 'default': 'localhost', 'immutable': True }, 'cmd': { 'description': 'Arbitrary Linux command to be executed on the ' 'host.', 'type': 'string' }, 'parallel': { 'description': 'Default to parallel execution.', 'type': 'boolean', 'default': True, 'immutable': True }, 'sudo': { 'description': 'The command will be executed with sudo.', 'type': 'boolean', 'default': False }, 'dir': { 'description': 'The working directory where the command will be ' 'executed on the host.', 'type': 'string', 'default': default_remote_dir }, 'kwarg_op': { 'description': 'Operator to use in front of keyword args i.e. "--" or "-".', 'type': 'string', 'default': '--' } }, 'runner_module': 'st2actions.runners.fabricrunner' }, { 'name': 'run-local-script', 'description': 'A runner to execute local actions as a fixed user.', 'enabled': True, 'runner_parameters': { 'hosts': { 'description': 'Fixed to localhost as this action is run locally.', 'type': 'string', 'default': 'localhost', 'immutable': True }, 'parallel': { 'description': 'Default to parallel execution.', 'type': 'boolean', 'default': True, 'immutable': True }, 'sudo': { 'description': 'The command will be executed with sudo.', 'type': 'boolean', 'default': False }, 'dir': { 'description': 'The working directory where the command will be ' 'executed on the host.', 'type': 'string', 'default': default_remote_dir }, 'kwarg_op': { 'description': 'Operator to use in front of keyword args i.e. "--" or "-".', 'type': 'string', 'default': '--' } }, 'runner_module': 'st2actions.runners.fabricrunner' }, { 'name': 'run-remote', 'description': 'A remote execution runner that executes actions ' 'as a fixed system user.', 'enabled': True, 'runner_parameters': { 'hosts': { 'description': 'A comma delimited string of a list of hosts ' 'where the remote command will be executed.', 'type': 'string', 'required': True }, 'cmd': { 'description': 'Arbitrary Linux command to be executed on the ' 'remote host(s).', 'type': 'string' }, 'parallel': { 'description': 'Default to parallel execution.', 'type': 'boolean', 'default': True, 'immutable': True }, 'sudo': { 'description': 'The remote command will be executed with sudo.', 'type': 'boolean' }, 'dir': { 'description': 'The working directory where the command will be ' 'executed on the remote host.', 'type': 'string', 'default': default_remote_dir }, 'kwarg_op': { 'description': 'Operator to use in front of keyword args i.e. "--" or "-".', 'type': 'string', 'default': '--' } }, 'runner_module': 'st2actions.runners.fabricrunner' }, { 'name': 'run-remote-script', 'description': 'A remote execution runner that executes actions ' 'as a fixed system user.', 'enabled': True, 'runner_parameters': { 'hosts': { 'description': 'A comma delimited string of a list of hosts ' 'where the remote command will be executed.', 'type': 'string', 'required': True }, 'parallel': { 'description': 'Default to parallel execution.', 'type': 'boolean', 'default': True, 'immutable': True }, 'sudo': { 'description': 'The remote command will be executed with sudo.', 'type': 'boolean' }, 'dir': { 'description': 'The working directory where the command will be ' 'executed on the remote host.', 'type': 'string', 'default': default_remote_dir }, 'kwarg_op': { 'description': 'Operator to use in front of keyword args i.e. "--" or "-".', 'type': 'string', 'default': '--' } }, 'runner_module': 'st2actions.runners.fabricrunner' }, { 'name': 'http-runner', 'description': 'A HTTP client for running HTTP actions.', 'enabled': True, 'runner_parameters': { 'url': { 'description': 'URL to the HTTP endpoint.', 'type': 'string', 'required': True }, 'headers': { 'description': 'HTTP headers for the request.', 'type': 'string' }, 'cookies': { 'description': 'TODO: Description for cookies.', 'type': 'string' }, 'proxy': { 'description': 'TODO: Description for proxy.', 'type': 'string' }, 'redirects': { 'description': 'TODO: Description for redirects.', 'type': 'string' }, }, 'runner_module': 'st2actions.runners.httprunner' }, { 'name': 'mistral-v1', 'description': 'A runner for executing mistral v1 workflow.', 'enabled': True, 'runner_parameters': { 'workbook': { 'description': 'The name of the workbook.', 'type': 'string', 'required': True }, 'task': { 'description': 'The startup task in the workbook to execute.', 'type': 'string', 'required': True }, 'context': { 'description': 'Context for the startup task.', 'type': 'object', 'default': {} } }, 'runner_module': 'st2actions.runners.mistral.v1' }, { 'name': 'mistral-v2', 'description': 'A runner for executing mistral v2 workflow.', 'enabled': True, 'runner_parameters': { 'workflow': { 'description': 'The name of the workflow.', 'type': 'string', 'required': True }, 'context': { 'description': 'Context for the startup task.', 'type': 'object', 'default': {} } }, 'runner_module': 'st2actions.runners.mistral.v2' }, { 'name': 'action-chain', 'description': 'A runner for launching linear action chains.', 'enabled': True, 'runner_parameters': {}, 'runner_module': 'st2actions.runners.actionchainrunner' }, { 'name': 'run-python', 'description': 'A runner for launching python actions.', 'enabled': True, 'runner_parameters': {}, 'runner_module': 'st2actions.runners.pythonrunner' }] LOG.info('Start : register default RunnerTypes.') for runnertype in RUNNER_TYPES: try: runnertype_db = get_runnertype_by_name(runnertype['name']) if runnertype_db: LOG.info('RunnerType name=%s exists.', runnertype['name']) continue except StackStormDBObjectNotFoundError: pass runnertype_api = RunnerTypeAPI(**runnertype) try: runnertype_db = RunnerType.add_or_update( RunnerTypeAPI.to_model(runnertype_api)) LOG.audit('RunnerType created. RunnerType %s', runnertype_db) except Exception: LOG.exception('Unable to register runner type %s.', runnertype['name']) LOG.info('End : register default RunnerTypes.')
def setUpClass(cls): super(ActionParamsUtilsTest, cls).setUpClass() cls.runnertype = RunnerTypeAPI(**FIXTURES['runners']['testrunner1.yaml']) cls.runnertype_db = RunnerType.add_or_update(RunnerTypeAPI.to_model(cls.runnertype)) cls.action = ActionAPI(**FIXTURES['actions']['action1.yaml']) cls.action_db = Action.add_or_update(ActionAPI.to_model(cls.action))