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


Python Action.query方法代码示例

本文整理汇总了Python中st2common.persistence.action.Action.query方法的典型用法代码示例。如果您正苦于以下问题:Python Action.query方法的具体用法?Python Action.query怎么用?Python Action.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在st2common.persistence.action.Action的用法示例。


在下文中一共展示了Action.query方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_run

# 需要导入模块: from st2common.persistence.action import Action [as 别名]
# 或者: from st2common.persistence.action.Action import query [as 别名]
    def test_run(self):
        pack = 'dummy_pack_1'
        # Verify all the resources are there

        pack_dbs = Pack.query(ref=pack)
        action_dbs = Action.query(pack=pack)
        alias_dbs = ActionAlias.query(pack=pack)
        rule_dbs = Rule.query(pack=pack)
        sensor_dbs = Sensor.query(pack=pack)
        trigger_type_dbs = TriggerType.query(pack=pack)
        policy_dbs = Policy.query(pack=pack)

        config_schema_dbs = ConfigSchema.query(pack=pack)
        config_dbs = Config.query(pack=pack)

        self.assertEqual(len(pack_dbs), 1)
        self.assertEqual(len(action_dbs), 1)
        self.assertEqual(len(alias_dbs), 2)
        self.assertEqual(len(rule_dbs), 1)
        self.assertEqual(len(sensor_dbs), 3)
        self.assertEqual(len(trigger_type_dbs), 4)
        self.assertEqual(len(policy_dbs), 2)

        self.assertEqual(len(config_schema_dbs), 1)
        self.assertEqual(len(config_dbs), 1)

        # Run action
        action = self.get_action_instance()
        action.run(packs=[pack])

        # Make sure all resources have been removed from the db
        pack_dbs = Pack.query(ref=pack)
        action_dbs = Action.query(pack=pack)
        alias_dbs = ActionAlias.query(pack=pack)
        rule_dbs = Rule.query(pack=pack)
        sensor_dbs = Sensor.query(pack=pack)
        trigger_type_dbs = TriggerType.query(pack=pack)
        policy_dbs = Policy.query(pack=pack)

        config_schema_dbs = ConfigSchema.query(pack=pack)
        config_dbs = Config.query(pack=pack)

        self.assertEqual(len(pack_dbs), 0)
        self.assertEqual(len(action_dbs), 0)
        self.assertEqual(len(alias_dbs), 0)
        self.assertEqual(len(rule_dbs), 0)
        self.assertEqual(len(sensor_dbs), 0)
        self.assertEqual(len(trigger_type_dbs), 0)
        self.assertEqual(len(policy_dbs), 0)

        self.assertEqual(len(config_schema_dbs), 0)
        self.assertEqual(len(config_dbs), 0)
开发者ID:lyandut,项目名称:st2,代码行数:54,代码来源:test_action_unload.py

示例2: _get_action_by_pack_and_name

# 需要导入模块: from st2common.persistence.action import Action [as 别名]
# 或者: from st2common.persistence.action.Action import query [as 别名]
def _get_action_by_pack_and_name(pack=None, name=None):
    """
        Get Action by name and pack.

        Query doesn't raise an exception.
    """
    return Action.query(name=name, pack=pack).first()
开发者ID:bjoernbessert,项目名称:st2,代码行数:9,代码来源:action_db.py

示例3: _transform_action

# 需要导入模块: from st2common.persistence.action import Action [as 别名]
# 或者: from st2common.persistence.action.Action import query [as 别名]
def _transform_action(spec, action_key, input_key):

    if action_key not in spec or spec.get(action_key) == 'st2.action':
        return

    if spec.get(action_key) == 'st2.callback':
        raise Exception('st2.callback is deprecated.')

    # Convert parameters that are inline (i.e. action: some_action var1={$.value1} var2={$.value2})
    # and split it to action name and input dict as illustrated below.
    #
    # action: some_action
    # input:
    #   var1: <% $.value1 %>
    #   var2: <% $.value2 %>
    #
    # This step to separate the action name and the input parameters is required
    # to wrap them with the st2.action proxy.
    #
    # action: st2.action
    # input:
    #   ref: some_action
    #   parameters:
    #     var1: <% $.value1 %>
    #     var2: <% $.value2 %>
    _eval_inline_params(spec, action_key, input_key)

    action_ref = spec.get(action_key)

    if action_ref and ResourceReference.is_resource_reference(action_ref):
        ref = ResourceReference.from_string_reference(ref=action_ref)
        actions = Action.query(name=ref.name, pack=ref.pack)
        action = actions.first() if actions else None
    else:
        action = None

    if action:
        spec[action_key] = 'st2.action'
        action_input = spec.get(input_key)
        spec[input_key] = {'ref': action_ref}
        if action_input:
            spec[input_key]['parameters'] = action_input
开发者ID:ruslantum,项目名称:st2,代码行数:44,代码来源:utils.py

示例4: test_packs_register_endpoint

# 需要导入模块: from st2common.persistence.action import Action [as 别名]
# 或者: from st2common.persistence.action.Action import query [as 别名]
    def test_packs_register_endpoint(self, mock_get_packs):
        # Register resources from all packs - make sure the count values are correctly added
        # together

        # Note: We only register a couple of packs and not all on disk to speed
        # things up. Registering all the packs takes a long time.
        fixtures_base_path = get_fixtures_base_path()
        packs_base_path = os.path.join(fixtures_base_path, 'packs')
        pack_names = [
            'dummy_pack_1',
            'dummy_pack_2',
            'dummy_pack_3',
            'dummy_pack_10',
        ]
        mock_return_value = {}
        for pack_name in pack_names:
            mock_return_value[pack_name] = os.path.join(packs_base_path, pack_name)

        mock_get_packs.return_value = mock_return_value

        resp = self.app.post_json('/v1/packs/register', {'fail_on_failure': False})

        self.assertEqual(resp.status_int, 200)
        self.assertTrue('runners' in resp.json)
        self.assertTrue('actions' in resp.json)
        self.assertTrue('triggers' in resp.json)
        self.assertTrue('sensors' in resp.json)
        self.assertTrue('rules' in resp.json)
        self.assertTrue('rule_types' in resp.json)
        self.assertTrue('aliases' in resp.json)
        self.assertTrue('policy_types' in resp.json)
        self.assertTrue('policies' in resp.json)
        self.assertTrue('configs' in resp.json)

        self.assertTrue(resp.json['actions'] >= 3)
        self.assertTrue(resp.json['configs'] >= 1)

        # Register resources from a specific pack
        resp = self.app.post_json('/v1/packs/register', {'packs': ['dummy_pack_1'],
                                                         'fail_on_failure': False})

        self.assertEqual(resp.status_int, 200)
        self.assertTrue(resp.json['actions'] >= 1)
        self.assertTrue(resp.json['sensors'] >= 1)
        self.assertTrue(resp.json['configs'] >= 1)

        # Verify metadata_file attribute is set
        action_dbs = Action.query(pack='dummy_pack_1')
        self.assertEqual(action_dbs[0].metadata_file, 'actions/my_action.yaml')

        # Register 'all' resource types should try include any possible content for the pack
        resp = self.app.post_json('/v1/packs/register', {'packs': ['dummy_pack_1'],
                                                         'fail_on_failure': False,
                                                         'types': ['all']})

        self.assertEqual(resp.status_int, 200)
        self.assertTrue('runners' in resp.json)
        self.assertTrue('actions' in resp.json)
        self.assertTrue('triggers' in resp.json)
        self.assertTrue('sensors' in resp.json)
        self.assertTrue('rules' in resp.json)
        self.assertTrue('rule_types' in resp.json)
        self.assertTrue('aliases' in resp.json)
        self.assertTrue('policy_types' in resp.json)
        self.assertTrue('policies' in resp.json)
        self.assertTrue('configs' in resp.json)

        # Registering single resource type should also cause dependent resources
        # to be registered
        # * actions -> runners
        # * rules -> rule types
        # * policies -> policy types
        resp = self.app.post_json('/v1/packs/register', {'packs': ['dummy_pack_1'],
                                                         'fail_on_failure': False,
                                                         'types': ['actions']})

        self.assertEqual(resp.status_int, 200)
        self.assertTrue(resp.json['runners'] >= 1)
        self.assertTrue(resp.json['actions'] >= 1)

        resp = self.app.post_json('/v1/packs/register', {'packs': ['dummy_pack_1'],
                                                         'fail_on_failure': False,
                                                         'types': ['rules']})

        self.assertEqual(resp.status_int, 200)
        self.assertTrue(resp.json['rule_types'] >= 1)
        self.assertTrue(resp.json['rules'] >= 1)

        resp = self.app.post_json('/v1/packs/register', {'packs': ['dummy_pack_2'],
                                                         'fail_on_failure': False,
                                                         'types': ['policies']})

        self.assertEqual(resp.status_int, 200)
        self.assertTrue(resp.json['policy_types'] >= 1)
        self.assertTrue(resp.json['policies'] >= 0)

        # Register specific type for all packs
        resp = self.app.post_json('/v1/packs/register', {'types': ['sensor'],
                                                         'fail_on_failure': False})

#.........这里部分代码省略.........
开发者ID:StackStorm,项目名称:st2,代码行数:103,代码来源:test_packs.py


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