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


Python RuleEnforcer.get_action_execution_context方法代码示例

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


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

示例1: evaluate

# 需要导入模块: from st2reactor.rules.enforcer import RuleEnforcer [as 别名]
# 或者: from st2reactor.rules.enforcer.RuleEnforcer import get_action_execution_context [as 别名]
    def evaluate(self):
        """
        Evaluate trigger instance against the rule.

        :return: ``True`` if the rule matches, ``False`` otherwise.
        :rtype: ``boolean``
        """

        rule_db = self._get_rule_db()
        trigger_instance_db, trigger_db = self._get_trigger_instance_db()

        # The trigger check needs to be performed here as that is not performed
        # by RulesMatcher.
        if rule_db.trigger != trigger_db.ref:
            LOG.info('rule.trigger "%s" and trigger.ref "%s" do not match.',
                     rule_db.trigger, trigger_db.ref)
            return False

        # Check if rule matches criteria.
        matcher = RulesMatcher(trigger_instance=trigger_instance_db, trigger=trigger_db,
                               rules=[rule_db], extra_info=True)
        matching_rules = matcher.get_matching_rules()

        # Rule does not match so early exit.
        if len(matching_rules) < 1:
            return False

        # Check if rule can be enforced
        enforcer = RuleEnforcer(trigger_instance=trigger_instance_db, rule=rule_db)

        runner_type_db = mock.Mock()
        runner_type_db.runner_parameters = {}
        action_db = mock.Mock()
        action_db.parameters = {}
        params = rule_db.action.parameters  # pylint: disable=no-member

        context, additional_contexts = enforcer.get_action_execution_context(action_db=action_db,
                                                                             trace_context=None)

        # Note: We only return partially resolved parameters.
        # To be able to return all parameters we would need access to corresponding ActionDB,
        # RunnerTypeDB and ConfigDB object, but this would add a dependency on the database and the
        # tool is meant to be used standalone.
        try:
            params = enforcer.get_resolved_parameters(action_db=action_db,
                                                      runnertype_db=runner_type_db,
                                                      params=params,
                                                      context=context,
                                                      additional_contexts=additional_contexts)

            LOG.info('Action parameters resolved to:')
            for param in six.iteritems(params):
                LOG.info('\t%s: %s', param[0], param[1])
            return True
        except (UndefinedError, ValueError) as e:
            LOG.error('Failed to resolve parameters\n\tOriginal error : %s', six.text_type(e))
            return False
        except:
            LOG.exception('Failed to resolve parameters.')
            return False
开发者ID:nzlosh,项目名称:st2,代码行数:62,代码来源:tester.py

示例2: assertResolvedParamsMatchExpected

# 需要导入模块: from st2reactor.rules.enforcer import RuleEnforcer [as 别名]
# 或者: from st2reactor.rules.enforcer.RuleEnforcer import get_action_execution_context [as 别名]
    def assertResolvedParamsMatchExpected(self, rule, trigger_instance, params, expected_params):
        runner_type_db = mock.Mock()
        runner_type_db.runner_parameters = {}
        action_db = mock.Mock()
        action_db.parameters = {}

        enforcer = RuleEnforcer(trigger_instance, rule)
        context, additional_contexts = enforcer.get_action_execution_context(action_db=action_db)

        resolved_params = enforcer.get_resolved_parameters(action_db=action_db,
            runnertype_db=runner_type_db,
            params=params,
            context=context,
            additional_contexts=additional_contexts)
        self.assertEqual(resolved_params, expected_params)
开发者ID:StackStorm,项目名称:st2,代码行数:17,代码来源:test_enforce.py


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