Bkprt py3 haproxy (#37791)
* Fix python3 interpreter issue (#34811) (#35176)
* Fix python3 interpreter issue (#34811)
* Update ansible.module_utils._text (#34811)
* Convert to text later to account for multibyte characters
(cherry picked from commit 340064bfb9
)
* Add a changelog fragment for haproxy python3 fix
This commit is contained in:
parent
2dd02eb812
commit
f23c100419
2 changed files with 10 additions and 3 deletions
3
changelogs/fragments/py3-haproxy.yaml
Normal file
3
changelogs/fragments/py3-haproxy.yaml
Normal file
|
@ -0,0 +1,3 @@
|
|||
bugfixes:
|
||||
- Fix to send and receive bytes over a socket in the haproxy module which was
|
||||
causing tracebacks on Python3 https://github.com/ansible/ansible/pull/35176
|
|
@ -202,6 +202,7 @@ import time
|
|||
from string import Template
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils._text import to_bytes, to_text
|
||||
|
||||
|
||||
DEFAULT_SOCKET_LOCATION = "/var/run/haproxy.sock"
|
||||
|
@ -251,13 +252,16 @@ class HAProxy(object):
|
|||
"""
|
||||
self.client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
self.client.connect(self.socket)
|
||||
self.client.sendall('%s\n' % cmd)
|
||||
result = ''
|
||||
buf = ''
|
||||
self.client.sendall(to_bytes('%s\n' % cmd))
|
||||
|
||||
result = b''
|
||||
buf = b''
|
||||
buf = self.client.recv(RECV_SIZE)
|
||||
while buf:
|
||||
result += buf
|
||||
buf = self.client.recv(RECV_SIZE)
|
||||
result = to_text(result, errors='surrogate_or_strict')
|
||||
|
||||
if capture_output:
|
||||
self.capture_command_output(cmd, result.strip())
|
||||
self.client.close()
|
||||
|
|
Loading…
Reference in a new issue