From 9d9e9a79e29bf92d1f22f18f47437d502415223e Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Tue, 2 May 2017 18:33:26 +0530 Subject: [PATCH] Pep8 fixes for apache2 module (#24185) Signed-off-by: Abhijeet Kasurde --- .../web_infrastructure/apache2_mod_proxy.py | 24 +++++++++++-------- .../web_infrastructure/apache2_module.py | 17 ++++++++----- test/sanity/pep8/legacy-files.txt | 2 -- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/lib/ansible/modules/web_infrastructure/apache2_mod_proxy.py b/lib/ansible/modules/web_infrastructure/apache2_mod_proxy.py index f45790de07..c021cc087a 100644 --- a/lib/ansible/modules/web_infrastructure/apache2_mod_proxy.py +++ b/lib/ansible/modules/web_infrastructure/apache2_mod_proxy.py @@ -219,6 +219,7 @@ EXPRESSION = r"(b=([\w\.\-]+)&w=(https?|ajp|wss?|ftp|[sf]cgi)://([\w\.\-]+):?(\d # Apache2 server version extraction regexp: APACHE_VERSION_EXPRESSION = r"Server Version: Apache/([\d.]+) \(([\w]+)\)" + def regexp_extraction(string, _regexp, groups=1): """ Returns the capture group (default=1) specified in the regexp, applied to the string """ regexp_search = re.search(string=str(string), pattern=str(_regexp)) @@ -227,6 +228,7 @@ def regexp_extraction(string, _regexp, groups=1): return str(regexp_search.group(groups)) return None + class BalancerMember(object): """ Apache 2.4 mod_proxy LB balancer member. attributes: @@ -276,10 +278,10 @@ class BalancerMember(object): def get_member_status(self): """ Returns a dictionary of a balancer member's status attributes.""" - status_mapping = {'disabled':'Dis', - 'drained':'Drn', - 'hot_standby':'Stby', - 'ignore_errors':'Ign'} + status_mapping = {'disabled': 'Dis', + 'drained': 'Drn', + 'hot_standby': 'Stby', + 'ignore_errors': 'Ign'} status = {} actual_status = str(self.attributes['Status']) for mode in status_mapping.keys(): @@ -291,10 +293,10 @@ class BalancerMember(object): def set_member_status(self, values): """ Sets a balancer member's status attributes amongst pre-mapped values.""" - values_mapping = {'disabled':'&w_status_D', - 'drained':'&w_status_N', - 'hot_standby':'&w_status_H', - 'ignore_errors':'&w_status_I'} + values_mapping = {'disabled': '&w_status_D', + 'drained': '&w_status_N', + 'hot_standby': '&w_status_H', + 'ignore_errors': '&w_status_I'} request_body = regexp_extraction(self.management_url, EXPRESSION, 1) for k in values_mapping.keys(): @@ -315,6 +317,7 @@ class BalancerMember(object): class Balancer(object): """ Apache httpd 2.4 mod_proxy balancer object""" + def __init__(self, host, suffix, module, members=None, tls=False): if tls: self.base_url = str(str('https://') + str(host)) @@ -359,6 +362,7 @@ class Balancer(object): members = property(get_balancer_members) + def main(): """ Initiates module.""" module = AnsibleModule( @@ -414,7 +418,7 @@ def main(): else: changed = False member_exists = False - member_status = {'disabled': False, 'drained': False, 'hot_standby': False, 'ignore_errors':False} + member_status = {'disabled': False, 'drained': False, 'hot_standby': False, 'ignore_errors': False} for mode in member_status.keys(): for state in states: if mode == state: @@ -447,7 +451,7 @@ def main(): module.exit_json( changed=changed, member=json_output - ) + ) else: module.fail_json(msg=str(module.params['member_host']) + ' is not a member of the balancer ' + str(module.params['balancer_vhost']) + '!') diff --git a/lib/ansible/modules/web_infrastructure/apache2_module.py b/lib/ansible/modules/web_infrastructure/apache2_module.py index 38d408d74b..f0a73566fe 100644 --- a/lib/ansible/modules/web_infrastructure/apache2_module.py +++ b/lib/ansible/modules/web_infrastructure/apache2_module.py @@ -1,5 +1,5 @@ #!/usr/bin/python -#coding: utf-8 -*- +# coding: utf-8 -*- # (c) 2013-2014, Christian Berendt # @@ -104,6 +104,7 @@ stderr: import re + def _run_threaded(module): control_binary = _get_ctl_binary(module) @@ -111,6 +112,7 @@ def _run_threaded(module): return bool(re.search(r'threaded:[ ]*yes', stdout)) + def _get_ctl_binary(module): for command in ['apache2ctl', 'apachectl']: ctl_binary = module.get_bin_path(command) @@ -122,6 +124,7 @@ def _get_ctl_binary(module): " At least one apache control binary is necessary." ) + def _module_is_enabled(module): control_binary = _get_ctl_binary(module) name = module.params['name'] @@ -146,6 +149,7 @@ def _module_is_enabled(module): searchstring = ' ' + create_apache_identifier(name) return searchstring in stdout + def create_apache_identifier(name): """ By convention if a module is loaded via name, it appears in apache2ctl -M as @@ -215,15 +219,16 @@ def _set_state(module, state): result=success_msg, warnings=module.warnings) + def main(): module = AnsibleModule( - argument_spec = dict( - name = dict(required=True), - force = dict(required=False, type='bool', default=False), - state = dict(default='present', choices=['absent', 'present']), + argument_spec=dict( + name=dict(required=True), + force=dict(required=False, type='bool', default=False), + state=dict(default='present', choices=['absent', 'present']), ignore_configcheck=dict(required=False, type='bool', default=False), ), - supports_check_mode = True, + supports_check_mode=True, ) module.warnings = [] diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 26ddf74761..e156e91d35 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -770,8 +770,6 @@ lib/ansible/modules/web_infrastructure/ansible_tower/tower_project.py lib/ansible/modules/web_infrastructure/ansible_tower/tower_role.py lib/ansible/modules/web_infrastructure/ansible_tower/tower_team.py lib/ansible/modules/web_infrastructure/ansible_tower/tower_user.py -lib/ansible/modules/web_infrastructure/apache2_mod_proxy.py -lib/ansible/modules/web_infrastructure/apache2_module.py lib/ansible/modules/web_infrastructure/deploy_helper.py lib/ansible/modules/web_infrastructure/django_manage.py lib/ansible/modules/web_infrastructure/ejabberd_user.py