本文整理汇总了Python中st2common.persistence.action.Action.get_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Action.get_by_name方法的具体用法?Python Action.get_by_name怎么用?Python Action.get_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.persistence.action.Action
的用法示例。
在下文中一共展示了Action.get_by_name方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _register_action
# 需要导入模块: from st2common.persistence.action import Action [as 别名]
# 或者: from st2common.persistence.action.Action import get_by_name [as 别名]
def _register_action(self, pack, action):
with open(action, 'r') as fd:
try:
content = json.load(fd)
except ValueError:
LOG.exception('Failed loading action json from %s.', action)
raise
try:
model = Action.get_by_name(str(content['name']))
except ValueError:
model = ActionDB()
model.name = content['name']
model.description = content['description']
model.enabled = content['enabled']
model.pack = pack
model.entry_point = content['entry_point']
model.parameters = content.get('parameters', {})
runner_type = str(content['runner_type'])
valid_runner_type, runner_type_db = self._has_valid_runner_type(runner_type)
if valid_runner_type:
model.runner_type = {'name': runner_type_db.name}
else:
LOG.exception('Runner type %s doesn\'t exist.')
raise
try:
model = Action.add_or_update(model)
LOG.audit('Action created. Action %s from %s.', model, action)
except Exception:
LOG.exception('Failed to write action to db %s.', model.name)
raise
示例2: test_pack_name_missing
# 需要导入模块: from st2common.persistence.action import Action [as 别名]
# 或者: from st2common.persistence.action.Action import get_by_name [as 别名]
def test_pack_name_missing(self):
registrar = actions_registrar.ActionsRegistrar()
action_file = os.path.join(tests_base.get_fixtures_path(),
'wolfpack/actions/action_3_pack_missing.json')
registrar._register_action('dummy', action_file)
action_name = None
with open(action_file, 'r') as fd:
content = json.load(fd)
action_name = str(content['name'])
action_db = Action.get_by_name(action_name)
self.assertEqual(action_db.pack, 'dummy', 'Content pack must be ' +
'set to dummy')
Action.delete(action_db)
示例3: test_pack_name_missing
# 需要导入模块: from st2common.persistence.action import Action [as 别名]
# 或者: from st2common.persistence.action.Action import get_by_name [as 别名]
def test_pack_name_missing(self):
registrar = actions_registrar.ActionsRegistrar()
loader = fixtures_loader.FixturesLoader()
action_file = loader.get_fixture_file_path_abs(
'generic', 'actions', 'action_3_pack_missing.yaml')
registrar._register_action('dummy', action_file)
action_name = None
with open(action_file, 'r') as fd:
content = yaml.safe_load(fd)
action_name = str(content['name'])
action_db = Action.get_by_name(action_name)
self.assertEqual(action_db.pack, 'dummy', 'Content pack must be ' +
'set to dummy')
Action.delete(action_db)
示例4: test_action_update
# 需要导入模块: from st2common.persistence.action import Action [as 别名]
# 或者: from st2common.persistence.action.Action import get_by_name [as 别名]
def test_action_update(self):
registrar = actions_registrar.ActionsRegistrar()
loader = fixtures_loader.FixturesLoader()
action_file = loader.get_fixture_file_path_abs(
'generic', 'actions', 'action1.yaml')
registrar._register_action('wolfpack', action_file)
# try registering again. this should not throw errors.
registrar._register_action('wolfpack', action_file)
action_name = None
with open(action_file, 'r') as fd:
content = yaml.safe_load(fd)
action_name = str(content['name'])
action_db = Action.get_by_name(action_name)
self.assertEqual(action_db.pack, 'wolfpack', 'Content pack must be ' +
'set to wolfpack')
Action.delete(action_db)
示例5: test_post_duplicate
# 需要导入模块: from st2common.persistence.action import Action [as 别名]
# 或者: from st2common.persistence.action.Action import get_by_name [as 别名]
def test_post_duplicate(self):
action_ids = []
post_resp = self.__do_post(ACTION_1)
self.assertEqual(post_resp.status_int, 201)
action_in_db = Action.get_by_name(ACTION_1.get('name'))
self.assertTrue(action_in_db is not None, 'Action must be in db.')
action_ids.append(self.__get_action_id(post_resp))
post_resp = self.__do_post(ACTION_1, expect_errors=True)
# Verify name conflict
self.assertEqual(post_resp.status_int, 409)
post_resp = self.__do_post(ACTION_10)
action_ids.append(self.__get_action_id(post_resp))
# Verify action with same name but different pack is written.
self.assertEqual(post_resp.status_int, 201)
for i in action_ids:
self.__do_delete(i)