From 43764177430fabb11d2ee02ea88cc2594f5cc515 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 5 Oct 2018 09:55:42 +0200 Subject: [PATCH] fix drain mode 'bool' (#30833) (#46478) --- lib/ansible/modules/net_tools/haproxy.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/net_tools/haproxy.py b/lib/ansible/modules/net_tools/haproxy.py index 1c2897a20bf..f0423630497 100644 --- a/lib/ansible/modules/net_tools/haproxy.py +++ b/lib/ansible/modules/net_tools/haproxy.py @@ -233,7 +233,7 @@ class HAProxy(object): self.wait = self.module.params['wait'] self.wait_retries = self.module.params['wait_retries'] self.wait_interval = self.module.params['wait_interval'] - self.drain = self.module.params['drain'] + self._drain = self.module.params['drain'] self.command_results = {} def execute(self, cmd, timeout=200, capture_output=True): @@ -310,7 +310,8 @@ class HAProxy(object): # Fail when backends were not found state = self.get_state_for(backend, svname) if (self.fail_on_not_found) and state is None: - self.module.fail_json(msg="The specified backend '%s/%s' was not found!" % (backend, svname)) + self.module.fail_json( + msg="The specified backend '%s/%s' was not found!" % (backend, svname)) if state is not None: self.execute(Template(cmd).substitute(pxname=backend, svname=svname)) @@ -327,7 +328,8 @@ class HAProxy(object): state = tuple( map( lambda d: {'status': d['status'], 'weight': d['weight'], 'scur': d['scur']}, - filter(lambda d: (pxname is None or d['pxname'] == pxname) and d['svname'] == svname, r) + filter(lambda d: (pxname is None or d['pxname'] + == pxname) and d['svname'] == svname, r) ) ) return state or None @@ -344,12 +346,13 @@ class HAProxy(object): # We can assume there will only be 1 element in state because both svname and pxname are always set when we get here if state[0]['status'] == status: - if not self.drain or (state[0]['scur'] == '0' and state == 'MAINT'): + if not self._drain or (state[0]['scur'] == '0' and state == 'MAINT'): return True else: time.sleep(self.wait_interval) - self.module.fail_json(msg="server %s/%s not status '%s' after %d retries. Aborting." % (pxname, svname, status, self.wait_retries)) + self.module.fail_json(msg="server %s/%s not status '%s' after %d retries. Aborting." % + (pxname, svname, status, self.wait_retries)) def enabled(self, host, backend, weight): """ @@ -397,7 +400,7 @@ class HAProxy(object): # toggle enable/disbale server if self.state == 'enabled': self.enabled(self.host, self.backend, self.weight) - elif self.state == 'disabled' and self.drain: + elif self.state == 'disabled' and self._drain: self.drain(self.host, self.backend, status='MAINT') elif self.state == 'disabled': self.disabled(self.host, self.backend, self.shutdown_sessions)