mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix HAProxy draining (#1993)
* Fix HAProxy draining by manually entering the 'MAINT' state Inspired by rldleblanc: https://github.com/ansible/ansible/issues/37591#issuecomment-610130611 Signed-off-by: Norman Ziegner <norman.ziegner@ufz.de> * Add changelog fragment Signed-off-by: Norman Ziegner <norman.ziegner@ufz.de> * Fix drain function docstring Signed-off-by: Norman Ziegner <norman.ziegner@ufz.de> * Fix typos Signed-off-by: Norman Ziegner <norman.ziegner@ufz.de> * Update changelog fragment Signed-off-by: Norman Ziegner <norman.ziegner@ufz.de>
This commit is contained in:
parent
beb3b85a4f
commit
7145204594
2 changed files with 11 additions and 7 deletions
3
changelogs/fragments/1993-haproxy-fix-draining.yml
Normal file
3
changelogs/fragments/1993-haproxy-fix-draining.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
bugfixes:
|
||||
- haproxy - fix a bug preventing haproxy from properly entering ``DRAIN`` mode (https://github.com/ansible-collections/community.general/issues/1913).
|
|
@ -367,10 +367,9 @@ 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
|
||||
# When using track we get a status like this: MAINT (via pxname/svname) so we need to do substring matching
|
||||
if status in state[0]['status']:
|
||||
if not self._drain or (state[0]['scur'] == '0' and 'MAINT' in state):
|
||||
if not self._drain or state[0]['scur'] == '0':
|
||||
return True
|
||||
else:
|
||||
time.sleep(self.wait_interval)
|
||||
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))
|
||||
|
@ -409,15 +408,17 @@ class HAProxy(object):
|
|||
def drain(self, host, backend, status='DRAIN'):
|
||||
"""
|
||||
Drain action, sets the server to DRAIN mode.
|
||||
In this mode mode, the server will not accept any new connections
|
||||
In this mode, the server will not accept any new connections
|
||||
other than those that are accepted via persistence.
|
||||
"""
|
||||
haproxy_version = self.discover_version()
|
||||
|
||||
# check if haproxy version suppots DRAIN state (starting with 1.5)
|
||||
# check if haproxy version supports DRAIN state (starting with 1.5)
|
||||
if haproxy_version and (1, 5) <= haproxy_version:
|
||||
cmd = "set server $pxname/$svname state drain"
|
||||
self.execute_for_backends(cmd, backend, host, status)
|
||||
self.execute_for_backends(cmd, backend, host, "DRAIN")
|
||||
if status == "MAINT":
|
||||
self.disabled(host, backend, self.shutdown_sessions)
|
||||
|
||||
def act(self):
|
||||
"""
|
||||
|
@ -426,7 +427,7 @@ class HAProxy(object):
|
|||
# Get the state before the run
|
||||
self.command_results['state_before'] = self.get_state_for(self.backend, self.host)
|
||||
|
||||
# toggle enable/disbale server
|
||||
# toggle enable/disable server
|
||||
if self.state == 'enabled':
|
||||
self.enabled(self.host, self.backend, self.weight)
|
||||
elif self.state == 'disabled' and self._drain:
|
||||
|
|
Loading…
Reference in a new issue