From cdca648f15789815a73661b059e5c213ed539235 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Mon, 1 May 2017 20:31:25 +0530 Subject: [PATCH] Pep8 fixes for jenkins_* module (#24154) Signed-off-by: Abhijeet Kasurde --- .../modules/web_infrastructure/jenkins_job.py | 35 +++++++++++-------- .../web_infrastructure/jenkins_script.py | 24 ++++++------- test/sanity/pep8/legacy-files.txt | 2 -- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/lib/ansible/modules/web_infrastructure/jenkins_job.py b/lib/ansible/modules/web_infrastructure/jenkins_job.py index 00ee73d39b6..7b8f1760a4e 100644 --- a/lib/ansible/modules/web_infrastructure/jenkins_job.py +++ b/lib/ansible/modules/web_infrastructure/jenkins_job.py @@ -163,7 +163,9 @@ try: except ImportError: python_lxml_installed = False + class JenkinsJob: + def __init__(self, module): self.module = module @@ -265,7 +267,7 @@ class JenkinsJob: if self.enabled is None: return False - if ( (self.enabled is False and status != "disabled") or (self.enabled is True and status == "disabled") ): + if ((self.enabled is False and status != "disabled") or (self.enabled is True and status == "disabled")): return True return False @@ -328,31 +330,34 @@ class JenkinsJob: result['enabled'] = None return result + def test_dependencies(module): if not python_jenkins_installed: - module.fail_json(msg="python-jenkins required for this module. "\ - "see http://python-jenkins.readthedocs.io/en/latest/install.html") + module.fail_json(msg="python-jenkins required for this module. " + "see http://python-jenkins.readthedocs.io/en/latest/install.html") if not python_lxml_installed: - module.fail_json(msg="lxml required for this module. "\ - "see http://lxml.de/installation.html") + module.fail_json(msg="lxml required for this module. " + "see http://lxml.de/installation.html") + def job_config_to_string(xml_str): return ET.tostring(ET.fromstring(xml_str)) + def main(): module = AnsibleModule( - argument_spec = dict( - config = dict(required=False), - name = dict(required=True), - password = dict(required=False, no_log=True), - state = dict(required=False, choices=['present', 'absent'], default="present"), - enabled = dict(required=False, type='bool'), - token = dict(required=False, no_log=True), - url = dict(required=False, default="http://localhost:8080"), - user = dict(required=False) + argument_spec=dict( + config=dict(required=False), + name=dict(required=True), + password=dict(required=False, no_log=True), + state=dict(required=False, choices=['present', 'absent'], default="present"), + enabled=dict(required=False, type='bool'), + token=dict(required=False, no_log=True), + url=dict(required=False, default="http://localhost:8080"), + user=dict(required=False) ), - mutually_exclusive = [ + mutually_exclusive=[ ['password', 'token'], ['config', 'enabled'], ], diff --git a/lib/ansible/modules/web_infrastructure/jenkins_script.py b/lib/ansible/modules/web_infrastructure/jenkins_script.py index 3d5c31c9feb..b4f1cd1ef84 100644 --- a/lib/ansible/modules/web_infrastructure/jenkins_script.py +++ b/lib/ansible/modules/web_infrastructure/jenkins_script.py @@ -127,6 +127,7 @@ except ImportError: # python3 from urllib.parse import urlencode + def is_csrf_protection_enabled(module): resp, info = fetch_url(module, module.params['url'] + '/api/json', @@ -137,6 +138,7 @@ def is_csrf_protection_enabled(module): content = resp.read() return json.loads(content).get('useCrumbs', False) + def get_crumb(module): resp, info = fetch_url(module, module.params['url'] + '/crumbIssuer/api/json', @@ -147,20 +149,20 @@ def get_crumb(module): content = resp.read() return json.loads(content) + def main(): module = AnsibleModule( - argument_spec = dict( - script = dict(required=True, type="str"), - url = dict(required=False, type="str", default="http://localhost:8080"), - validate_certs = dict(required=False, type="bool", default=True), - user = dict(required=False, no_log=True, type="str",default=None), - password = dict(required=False, no_log=True, type="str",default=None), - args = dict(required=False, type="dict", default=None) + argument_spec=dict( + script=dict(required=True, type="str"), + url=dict(required=False, type="str", default="http://localhost:8080"), + validate_certs=dict(required=False, type="bool", default=True), + user=dict(required=False, no_log=True, type="str", default=None), + password=dict(required=False, no_log=True, type="str", default=None), + args=dict(required=False, type="dict", default=None) ) ) - if module.params['user'] is not None: if module.params['password'] is None: module.fail_json(msg="password required when user provided") @@ -168,7 +170,6 @@ def main(): module.params['url_password'] = module.params['password'] module.params['force_basic_auth'] = True - if module.params['args'] is not None: from string import Template script_contents = Template(module.params['script']).substitute(module.params['args']) @@ -183,7 +184,7 @@ def main(): resp, info = fetch_url(module, module.params['url'] + "/scriptText", data=urlencode({'script': script_contents}), - headers = headers, + headers=headers, method="POST") if info["status"] != 200: @@ -195,10 +196,9 @@ def main(): module.fail_json(msg="script failed with stacktrace:\n " + result) module.exit_json( - output = result, + output=result, ) - if __name__ == '__main__': main() diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 58ae7baefd7..7eb8eba290b 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -781,8 +781,6 @@ lib/ansible/modules/web_infrastructure/django_manage.py lib/ansible/modules/web_infrastructure/ejabberd_user.py lib/ansible/modules/web_infrastructure/htpasswd.py lib/ansible/modules/web_infrastructure/jboss.py -lib/ansible/modules/web_infrastructure/jenkins_job.py -lib/ansible/modules/web_infrastructure/jenkins_script.py lib/ansible/modules/web_infrastructure/jira.py lib/ansible/modules/web_infrastructure/letsencrypt.py lib/ansible/modules/windows/win_disk_image.py