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
| <type 'str'>
| % python3 demo.py
| <class 'bytes'>

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
changes/13/14913/2
Michael Prokop 9 years ago
parent 541e5418ac
commit 429b98142d

@ -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

Loading…
Cancel
Save