本文整理汇总了Python中handler.Handler.handle_retcodes方法的典型用法代码示例。如果您正苦于以下问题:Python Handler.handle_retcodes方法的具体用法?Python Handler.handle_retcodes怎么用?Python Handler.handle_retcodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类handler.Handler
的用法示例。
在下文中一共展示了Handler.handle_retcodes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SaltJob
# 需要导入模块: from handler import Handler [as 别名]
# 或者: from handler.Handler import handle_retcodes [as 别名]
#.........这里部分代码省略.........
current = self
while current.chain is not None:
current = current.chain
current.chain = next_
def is_finished(self):
"""
Computes the difference between the set of expected minions and the
set of minions that have returned so far. The job is finished when
there are no minions in the difference set.
@param return Boolean True for yes, Boolean false otherwise
"""
return self.minions.issubset(self.finished_minions)
def set_pub_data(self, pub_data):
"""
Handles the publish data returned from a call to run on an APIClient
object
@param pub_data - Dictionary containing affected minion ids and a jid
or an empty dict representing a publish failure
"""
# Check for bad publish, emit any output
self.handler.handle_publish(self, pub_data)
# Set jid and minions
self.jid = pub_data['jid']
self.minions = set(pub_data['minions'])
def add_minion_return(self, raw):
"""
Adds a minion return or an event to the tracked data.
The return/event must have the fields 'id' and 'return' to be
considered part of the job's response
@param raw - Dictionary representing event or minion return
"""
if raw is not None:
# Save the event
self.events[raw['id']] = raw
if 'return' in raw:
self.finished_minions.add(raw['id'])
self.ret[raw['id']] = raw['return']
def validate_func(self):
"""
Returns a validate function or none based upon the salt function
used. Example: state.sls in salt has some special output that needs
to be validated a little differently.
@return - A validating function or None
"""
salt_method = self.kwargs['fun']
validate_name = self.validate_funcs.get(salt_method)
if validate_name is not None:
return getattr(self, validate_name, None)
return None
def validate(self):
"""
Validates the job. Exceptions are raised by the handler.
Checks that the job finished
Checks that all events were success
Checks that all retcodes were acceptable
Calls any custom validation methods that are necessary.
"""
# Check that all minions have returned
if not self.is_finished():
self.handler.handle_unfinished(self)
# Checked that all events for the minion are success
if not all([e['success'] for e in self.events.itervalues()]):
self.handler.handle_unsuccessful(self)
# Check all retcodes
allcodes = set()
for e in self.events.itervalues():
allcodes.add(e.get('retcode', 1))
if len(allcodes.difference(self.goodcodes)) > 0:
self.handler.handle_retcodes(self)
# Do any custom validation base on the salt function
func = self.validate_func()
if func:
func()
def validate_state_sls(self):
"""
Validates this job against for the salt function 'state.sls'.
"""
for e in self.events.itervalues():
if not all([ret['result'] for ret in e['return'].itervalues()]):
self.handler.handle_failed_state_sls(self)
break