本文整理汇总了Python中st2common.models.api.action.RunnerTypeAPI类的典型用法代码示例。如果您正苦于以下问题:Python RunnerTypeAPI类的具体用法?Python RunnerTypeAPI怎么用?Python RunnerTypeAPI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RunnerTypeAPI类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: register_runner_types
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.')
示例2: register_runner_types
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.')
示例3: register_runner
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
示例4: register_runner_types
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.")
示例5: setup_runner
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))
示例6: setup_runner
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))
示例7: put
def put(self, runner_type_api, name_or_id, requester_user):
# Note: We only allow "enabled" attribute of the runner to be changed
runner_type_db = self._get_by_name_or_id(name_or_id=name_or_id)
permission_type = PermissionType.RUNNER_MODIFY
rbac_utils.assert_user_has_resource_db_permission(user_db=requester_user,
resource_db=runner_type_db,
permission_type=permission_type)
old_runner_type_db = runner_type_db
LOG.debug('PUT /runnertypes/ lookup with id=%s found object: %s', name_or_id,
runner_type_db)
try:
if runner_type_api.id and runner_type_api.id != name_or_id:
LOG.warning('Discarding mismatched id=%s found in payload and using uri_id=%s.',
runner_type_api.id, name_or_id)
runner_type_db.enabled = runner_type_api.enabled
runner_type_db = RunnerType.add_or_update(runner_type_db)
except (ValidationError, ValueError) as e:
LOG.exception('Validation failed for runner type data=%s', runner_type_api)
abort(http_client.BAD_REQUEST, six.text_type(e))
return
extra = {'old_runner_type_db': old_runner_type_db, 'new_runner_type_db': runner_type_db}
LOG.audit('Runner Type updated. RunnerType.id=%s.' % (runner_type_db.id), extra=extra)
runner_type_api = RunnerTypeAPI.from_model(runner_type_db)
return runner_type_api
示例8: _setup_runner_models
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)
示例9: test_basic_execution
def test_basic_execution(self):
liveaction = LiveActionDB(action='executions.local', parameters={'cmd': 'uname -a'})
liveaction, _ = action_service.request(liveaction)
liveaction = self._wait_on_status(liveaction, action_constants.LIVEACTION_STATUS_FAILED)
execution = self._get_action_execution(
liveaction__id=str(liveaction.id),
raise_exception=True
)
self.assertDictEqual(execution.trigger, {})
self.assertDictEqual(execution.trigger_type, {})
self.assertDictEqual(execution.trigger_instance, {})
self.assertDictEqual(execution.rule, {})
action = action_utils.get_action_by_ref('executions.local')
self.assertDictEqual(execution.action, vars(ActionAPI.from_model(action)))
runner = RunnerType.get_by_name(action.runner_type['name'])
self.assertDictEqual(execution.runner, vars(RunnerTypeAPI.from_model(runner)))
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(execution.start_timestamp, liveaction.start_timestamp)
self.assertEqual(execution.end_timestamp, liveaction.end_timestamp)
self.assertEqual(execution.result, liveaction.result)
self.assertEqual(execution.status, liveaction.status)
self.assertEqual(execution.context, liveaction.context)
self.assertEqual(execution.liveaction['callback'], liveaction.callback)
self.assertEqual(execution.liveaction['action'], liveaction.action)
示例10: test_chained_executions
def test_chained_executions(self):
liveaction = LiveActionDB(action='core.chain')
liveaction, _ = action_service.request(liveaction)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_FAILED)
execution = self._get_action_execution(liveaction__id=str(liveaction.id),
raise_exception=True)
action = action_utils.get_action_by_ref('core.chain')
self.assertDictEqual(execution.action, vars(ActionAPI.from_model(action)))
runner = RunnerType.get_by_name(action.runner_type['name'])
self.assertDictEqual(execution.runner, vars(RunnerTypeAPI.from_model(runner)))
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(execution.start_timestamp, liveaction.start_timestamp)
self.assertEqual(execution.end_timestamp, liveaction.end_timestamp)
self.assertEqual(execution.result, liveaction.result)
self.assertEqual(execution.status, liveaction.status)
self.assertEqual(execution.context, liveaction.context)
self.assertEqual(execution.liveaction['callback'], liveaction.callback)
self.assertEqual(execution.liveaction['action'], liveaction.action)
self.assertGreater(len(execution.children), 0)
for child in execution.children:
record = ActionExecution.get(id=child, raise_exception=True)
self.assertEqual(record.parent, str(execution.id))
self.assertEqual(record.action['name'], 'local')
self.assertEqual(record.runner['name'], 'run-local')
示例11: test_execution_creation_action_triggered_by_rule
def test_execution_creation_action_triggered_by_rule(self):
# Wait for the action execution to complete and then confirm outcome.
trigger_type = self.MODELS['triggertypes']['triggertype2.yaml']
trigger = self.MODELS['triggers']['trigger2.yaml']
trigger_instance = self.MODELS['triggerinstances']['trigger_instance_1.yaml']
test_liveaction = self.FIXTURES['liveactions']['liveaction3.yaml']
rule = self.MODELS['rules']['rule3.yaml']
# Setup LiveAction to point to right rule and trigger_instance.
# XXX: We need support for dynamic fixtures.
test_liveaction['context']['rule']['id'] = str(rule.id)
test_liveaction['context']['trigger_instance']['id'] = str(trigger_instance.id)
test_liveaction_api = LiveActionAPI(**test_liveaction)
test_liveaction = LiveAction.add_or_update(LiveActionAPI.to_model(test_liveaction_api))
liveaction = LiveAction.get(context__trigger_instance__id=str(trigger_instance.id))
self.assertIsNotNone(liveaction)
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_REQUESTED)
executions_util.create_execution_object(liveaction)
execution = self._get_action_execution(liveaction__id=str(liveaction.id),
raise_exception=True)
self.assertDictEqual(execution.trigger, vars(TriggerAPI.from_model(trigger)))
self.assertDictEqual(execution.trigger_type, vars(TriggerTypeAPI.from_model(trigger_type)))
self.assertDictEqual(execution.trigger_instance,
vars(TriggerInstanceAPI.from_model(trigger_instance)))
self.assertDictEqual(execution.rule, vars(RuleAPI.from_model(rule)))
action = action_utils.get_action_by_ref(liveaction.action)
self.assertDictEqual(execution.action, vars(ActionAPI.from_model(action)))
runner = RunnerType.get_by_name(action.runner_type['name'])
self.assertDictEqual(execution.runner, vars(RunnerTypeAPI.from_model(runner)))
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEquals(execution.liveaction['id'], str(liveaction.id))
示例12: test_chained_executions
def test_chained_executions(self):
with mock.patch("st2common.runners.register_runner", mock.MagicMock(return_value=action_chain_runner)):
liveaction = LiveActionDB(action="executions.chain")
liveaction, _ = action_service.request(liveaction)
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(liveaction.status, action_constants.LIVEACTION_STATUS_FAILED)
execution = self._get_action_execution(liveaction__id=str(liveaction.id), raise_exception=True)
action = action_utils.get_action_by_ref("executions.chain")
self.assertDictEqual(execution.action, vars(ActionAPI.from_model(action)))
runner = RunnerType.get_by_name(action.runner_type["name"])
self.assertDictEqual(execution.runner, vars(RunnerTypeAPI.from_model(runner)))
liveaction = LiveAction.get_by_id(str(liveaction.id))
self.assertEqual(execution.start_timestamp, liveaction.start_timestamp)
self.assertEqual(execution.end_timestamp, liveaction.end_timestamp)
self.assertEqual(execution.result, liveaction.result)
self.assertEqual(execution.status, liveaction.status)
self.assertEqual(execution.context, liveaction.context)
self.assertEqual(execution.liveaction["callback"], liveaction.callback)
self.assertEqual(execution.liveaction["action"], liveaction.action)
self.assertGreater(len(execution.children), 0)
for child in execution.children:
record = ActionExecution.get(id=child, raise_exception=True)
self.assertEqual(record.parent, str(execution.id))
self.assertEqual(record.action["name"], "local")
self.assertEqual(record.runner["name"], "run-local")
示例13: setUpClass
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()
示例14: setUpClass
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)
示例15: setUpClass
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))