From 429b98142d31362dcfdc53a8b0f4711c680bb45e Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Tue, 15 Aug 2017 11:30:03 +0200 Subject: [PATCH] TT#20266 Fix Python3 issue with identifying next release version After switching repoapi to Python3 we noticed that workfront issues received a wrong target release set by repoapi: | Updated Target Release to b'mr5.5.1' The underlying issue is that meta-release-helper's output is considered a bytes object, while we need a string object. Demonstration of what's going on, using just the relevant (though minimized) repoapi code: | % cat demo.py | import subprocess | | def executeAndReturnOutput(command, env=None): | proc = subprocess.Popen(command, stdout=subprocess.PIPE, | stderr=subprocess.PIPE, env=env) | stdoutdata, stderrdata = proc.communicate() | return proc.returncode, stdoutdata, stderrdata | | def get_next_release(branch): | command = [ | "/usr/bin/meta-release-helper", | "--next-release", | branch | ] | res = executeAndReturnOutput(command) | if res[0] != 0: | return None | val = res[1].rstrip() | if len(val) > 0: | return val | else: | return None | | release = get_next_release("master") | print(type(release)) | | % python2 demo.py | | % python3 demo.py | NOTE regarding tests: inside our tests (test_utils.py) the call to meta-release-helper gets mocked/patched, so it's set to a string object already (which differs from what we get in actual usage/production). That's why this issue was hidden so far. NOTE for later debugging: if repoapi source gets changed don't forget to restart uwsgi service (`systemctl restart uwsgi.service`) and find its logging output in file `/var/log/uwsgi/app/repoapi.log` (which is NOT same es `journalctl -u uwsgi.service`!). Change-Id: I0f797ed3f7ae49c963c2f3c07fd601221e1dcd6c --- repoapi/utils.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/repoapi/utils.py b/repoapi/utils.py index 6487467..3384646 100644 --- a/repoapi/utils.py +++ b/repoapi/utils.py @@ -153,7 +153,14 @@ def get_next_release(branch): return None val = res[1].rstrip() if len(val) > 0: - return val + # py2 vs py3: convert to string iff it's a bytes object, + # otherwise it should be a string object already (as with + # py2 as well as the mocking/patching as being done in test_utils.py) + if type(val) is bytes: + return val.decode("utf-8") + else: + return val + else: return None