本文整理汇总了Python中st2common.persistence.trace.Trace.query方法的典型用法代码示例。如果您正苦于以下问题:Python Trace.query方法的具体用法?Python Trace.query怎么用?Python Trace.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.persistence.trace.Trace
的用法示例。
在下文中一共展示了Trace.query方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update
# 需要导入模块: from st2common.persistence.trace import Trace [as 别名]
# 或者: from st2common.persistence.trace.Trace import query [as 别名]
def test_update(self):
saved = TraceDBTest._create_save_trace(
trace_tag='test_trace',
action_executions=[],
rules=[],
trigger_instances=[])
retrieved = Trace.query(trace_tag=saved.trace_tag)
self.assertEquals(len(retrieved), 1, 'Should have 1 trace.')
self.assertEquals(retrieved[0].id, saved.id, 'Incorrect trace retrieved.')
no_action_executions = 4
no_rules = 4
no_trigger_instances = 5
saved = TraceDBTest._create_save_trace(
trace_tag='test_trace',
id_=retrieved[0].id,
action_executions=[str(bson.ObjectId()) for _ in range(no_action_executions)],
rules=[str(bson.ObjectId()) for _ in range(no_rules)],
trigger_instances=[str(bson.ObjectId()) for _ in range(no_trigger_instances)])
retrieved = Trace.query(trace_tag=saved.trace_tag)
self.assertEquals(len(retrieved), 1, 'Should have 1 trace.')
self.assertEquals(retrieved[0].id, saved.id, 'Incorrect trace retrieved.')
# validate update
self.assertEquals(len(retrieved[0].action_executions), no_action_executions,
'Failed to update action_executions.')
self.assertEquals(len(retrieved[0].rules), no_rules, 'Failed to update rules.')
self.assertEquals(len(retrieved[0].trigger_instances), no_trigger_instances,
'Failed to update trigger_instances.')
示例2: test_trace_tag_resuse
# 需要导入模块: from st2common.persistence.trace import Trace [as 别名]
# 或者: from st2common.persistence.trace.Trace import query [as 别名]
def test_trace_tag_resuse(self):
self.traceable_liveaction['context']['trace_context'] = {'trace_tag': 'blank space'}
action_services.request(self.traceable_liveaction)
# Let's use same trace tag again and we should see two trace objects in db.
action_services.request(self.traceable_liveaction)
traces = Trace.query(**{'trace_tag': 'blank space'})
self.assertEqual(len(traces), 2)
示例3: test_query
# 需要导入模块: from st2common.persistence.trace import Trace [as 别名]
# 或者: from st2common.persistence.trace.Trace import query [as 别名]
def test_query(self):
saved = TraceDBTest._create_save_trace(
trace_tag='test_trace',
action_executions=[str(bson.ObjectId()) for _ in range(4)],
rules=[str(bson.ObjectId()) for _ in range(4)],
trigger_instances=[str(bson.ObjectId()) for _ in range(5)])
retrieved = Trace.query(trace_tag=saved.trace_tag)
self.assertEquals(len(retrieved), 1, 'Should have 1 trace.')
self.assertEquals(retrieved[0].id, saved.id, 'Incorrect trace retrieved.')
# Add another trace with same trace_tag and confirm that we support.
# This is most likley an anti-pattern for the trace_tag but it is an unknown.
saved = TraceDBTest._create_save_trace(
trace_tag='test_trace',
action_executions=[str(bson.ObjectId()) for _ in range(2)],
rules=[str(bson.ObjectId()) for _ in range(4)],
trigger_instances=[str(bson.ObjectId()) for _ in range(3)])
retrieved = Trace.query(trace_tag=saved.trace_tag)
self.assertEquals(len(retrieved), 2, 'Should have 2 traces.')
示例4: _get_single_trace_by_component
# 需要导入模块: from st2common.persistence.trace import Trace [as 别名]
# 或者: from st2common.persistence.trace.Trace import query [as 别名]
def _get_single_trace_by_component(**component_filter):
"""
Tries to return a single Trace mathing component_filter. Raises an exception
when a filter matches multiple.
"""
traces = Trace.query(**component_filter)
if len(traces) == 0:
return None
elif len(traces) > 1:
raise UniqueTraceNotFoundException(
'More than 1 trace matching %s found.' % component_filter)
return traces[0]
示例5: get_trace
# 需要导入模块: from st2common.persistence.trace import Trace [as 别名]
# 或者: from st2common.persistence.trace.Trace import query [as 别名]
def get_trace(trace_context, ignore_trace_tag=False):
"""
:param trace_context: context object using which a trace can be found.
:type trace_context: ``dict`` or ``TraceContext``
:param ignore_trace_tag: Even if a trace_tag is provided will be ignored.
:type ignore_trace_tag: ``str``
:rtype: ``TraceDB``
"""
trace_context = _get_valid_trace_context(trace_context)
if not trace_context.id_ and not trace_context.trace_tag:
raise ValueError('Atleast one of id_ or trace_tag should be specified.')
if trace_context.id_:
try:
return Trace.get_by_id(trace_context.id_)
except (ValidationError, ValueError):
LOG.warning('Database lookup for Trace with id="%s" failed.',
trace_context.id_, exc_info=True)
raise StackStormDBObjectNotFoundError(
'Unable to find Trace with id="%s"' % trace_context.id_)
if ignore_trace_tag:
return None
traces = Trace.query(trace_tag=trace_context.trace_tag)
# Assume this method only handles 1 trace.
if len(traces) > 1:
raise UniqueTraceNotFoundException(
'More than 1 Trace matching %s found.' % trace_context.trace_tag)
return traces[0]
示例6: get_trace_db_by_rule
# 需要导入模块: from st2common.persistence.trace import Trace [as 别名]
# 或者: from st2common.persistence.trace.Trace import query [as 别名]
def get_trace_db_by_rule(rule=None, rule_id=None):
if rule:
rule_id = str(rule.id)
# by rule could return multiple traces
return Trace.query(rules__object_id=rule_id)