当前位置: 首页>>代码示例>>Python>>正文


Python Action.get_by_name方法代码示例

本文整理汇总了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
开发者ID:ojacques,项目名称:st2,代码行数:34,代码来源:actionsregistrar.py

示例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)
开发者ID:bjoernbessert,项目名称:st2,代码行数:15,代码来源:test_actions_registrar.py

示例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)
开发者ID:LindsayHill,项目名称:st2,代码行数:16,代码来源:test_actions_registrar.py

示例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)
开发者ID:LindsayHill,项目名称:st2,代码行数:18,代码来源:test_actions_registrar.py

示例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)
开发者ID:bjoernbessert,项目名称:st2,代码行数:22,代码来源:test_actions.py


注:本文中的st2common.persistence.action.Action.get_by_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。