Skip to content

Commit

Permalink
[ansible/library/exabgp]: Output handling for PY3 (sonic-net#14423)
Browse files Browse the repository at this point in the history
Tests running in PTF Py3 only image fail with error -

E           {"changed": false, "failed": true, "msg": "Error: (<class 'AttributeError'>, AttributeError(\"'str' object has no attribute 'decode'\"), <traceback object at 0x7f60a07fe2c0>)"}

How did you do it?
Fixed to code to treat output as UTF-8 native string in Py3.

How did you verify/test it?
By running failed tests manually on a testbed.
  • Loading branch information
opcoder0 authored Sep 11, 2024
1 parent 3cc528c commit 38f202c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ansible/library/exabgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ def exec_command(module, cmd, ignore_error=False, msg="executing command"):

def get_exabgp_status(module, name):
output = exec_command(module, cmd="supervisorctl status exabgp-%s" % name)
m = re.search(r'^([\w|-]*)\s+(\w*).*$', output.decode("utf-8"))
m = None
if six.PY2:
m = re.search(r'^([\w|-]*)\s+(\w*).*$', output.decode("utf-8"))
else:
# For PY3 module.run_command encoding is "utf-8" by default
m = re.search(r'^([\w|-]*)\s+(\w*).*$', output)
return m.group(2)


Expand Down

0 comments on commit 38f202c

Please sign in to comment.