salt/0011-jobs.exit_success-allow-to-check-if-a-job-has-execut.patch

54 lines
1.4 KiB
Diff

From e0f15c5292869549b5c80997ccb3282961be8e49 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pablo=20Su=C3=A1rez=20Hern=C3=A1ndez?=
<psuarezhernandez@suse.com>
Date: Tue, 24 May 2016 09:21:43 +0100
Subject: [PATCH 11/11] jobs.exit_success allow to check if a job has executed
and exit successfully
jobs.exit_success() now works parsing the results of jobs.lookup_id()
---
salt/runners/jobs.py | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/salt/runners/jobs.py b/salt/runners/jobs.py
index 57d0324..e2b8737 100644
--- a/salt/runners/jobs.py
+++ b/salt/runners/jobs.py
@@ -488,6 +488,33 @@ def print_job(jid, ext_source=None, outputter=None):
return ret
+def exit_success(jid, ext_source=None):
+ '''
+ Check if a job has been executed and exit successfully
+
+ jid
+ The jid to look up.
+ ext_source
+ The external job cache to use. Default: `None`.
+
+ CLI Example:
+ .. code-block:: bash
+ salt-run jobs.exit_success 20160520145827701627
+ '''
+ ret = dict()
+
+ data = lookup_jid(
+ jid,
+ ext_source=ext_source
+ )
+
+ for minion in data:
+ if "retcode" in data[minion]:
+ ret[minion] = True if not data[minion]['retcode'] else False
+
+ return ret
+
+
def last_run(ext_source=None,
outputter=None,
metadata=None,
--
2.8.2