Skip to content

Commit

Permalink
Fix python3 interpreter issue (ansible#34811) (ansible#35176)
Browse files Browse the repository at this point in the history
* Fix python3 interpreter issue (ansible#34811)

* Update ansible.module_utils._text (ansible#34811)

* Convert to text later to account for multibyte characters
  • Loading branch information
ravibhure authored and abadger committed Mar 22, 2018
1 parent da3f7a8 commit 340064b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/ansible/modules/net_tools/haproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
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"
Expand Down Expand Up @@ -242,13 +243,16 @@ def execute(self, cmd, timeout=200, capture_output=True):
"""
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()
Expand Down

0 comments on commit 340064b

Please sign in to comment.