本文整理汇总了Python中st2common.persistence.trigger.TriggerType.query方法的典型用法代码示例。如果您正苦于以下问题:Python TriggerType.query方法的具体用法?Python TriggerType.query怎么用?Python TriggerType.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.persistence.trigger.TriggerType
的用法示例。
在下文中一共展示了TriggerType.query方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_run
# 需要导入模块: from st2common.persistence.trigger import TriggerType [as 别名]
# 或者: from st2common.persistence.trigger.TriggerType 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)
示例2: _register_trigger_from_pack
# 需要导入模块: from st2common.persistence.trigger import TriggerType [as 别名]
# 或者: from st2common.persistence.trigger.TriggerType import query [as 别名]
def _register_trigger_from_pack(self, pack, trigger):
trigger_metadata_file_path = trigger
LOG.debug('Loading trigger from %s.', trigger_metadata_file_path)
content = self._meta_loader.load(file_path=trigger_metadata_file_path)
pack_field = content.get('pack', None)
if not pack_field:
content['pack'] = pack
pack_field = pack
if pack_field != pack:
raise Exception('Model is in pack "%s" but field "pack" is different: %s' %
(pack, pack_field))
trigger_api = TriggerTypeAPI(**content)
trigger_model = TriggerTypeAPI.to_model(trigger_api)
trigger_types = TriggerType.query(pack=trigger_model.pack, name=trigger_model.name)
if len(trigger_types) >= 1:
trigger_type = trigger_types[0]
LOG.debug('Found existing trigger id:%s with name:%s. Will update it.',
trigger_type.id, trigger_type.name)
trigger_model.id = trigger_type.id
try:
trigger_model = TriggerType.add_or_update(trigger_model)
except:
LOG.exception('Failed creating trigger model for %s', trigger)
return trigger_model