Module and states code refactor
Change-Id: Ia1c468d0b55603b6274ca0d275b2720602e5319e
diff --git a/_states/jenkins_job.py b/_states/jenkins_job.py
index 6f72d9d..dccac86 100644
--- a/_states/jenkins_job.py
+++ b/_states/jenkins_job.py
@@ -15,10 +15,10 @@
# Jenkins
try:
- import jenkins
- HAS_JENKINS = True
+ import jenkins
+ HAS_JENKINS = True
except ImportError:
- HAS_JENKINS = False
+ HAS_JENKINS = False
log = logging.getLogger(__name__)
@@ -27,7 +27,12 @@
'''
Only load if jenkins_common module exist.
'''
- if HAS_JENKINS and 'jenkins_common.call_groovy_script' not in __salt__:
+ if not HAS_JENKINS:
+ return (
+ False,
+ 'The jenkins_job state module cannot be loaded: '
+ 'python Jenkins API client could not be imported')
+ if 'jenkins_common.call_groovy_script' not in __salt__:
return (
False,
'The jenkins_job state module cannot be loaded: '
@@ -71,7 +76,6 @@
else:
raise e
-
if _job_exists:
buf = six.moves.StringIO(_current_job_config)
oldXMLstring = buf.read()
@@ -151,7 +155,7 @@
'changes': {},
'comment': "Cleanup not necessary"}
list_jobs_groovy = """\
- print(Jenkins.instance.items.collect{{it -> it.name}})
+ print(Jenkins.instance.items.collect{it -> it.name})
"""
deleted_jobs = []
if test:
@@ -159,7 +163,8 @@
ret['changes'][name] = status
ret['comment'] = 'Jobs %s' % status.lower()
else:
- call_result = __salt__['jenkins_common.call_groovy_script'](list_jobs_groovy,{})
+ call_result = __salt__['jenkins_common.call_groovy_script'](
+ list_jobs_groovy, {})
if call_result["code"] == 200:
existing_jobs = call_result["msg"]
if existing_jobs: