diff options
| author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-05-20 11:17:05 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-06-02 08:24:00 +0100 |
| commit | a7309d5790f5dac46e84d3c14959943eb2496fda (patch) | |
| tree | 48e1fcb886b8ef2974bade09694356f3230fb8a8 /meta/lib/oeqa | |
| parent | 297438e965053b2eb56cc8ef3e59465642f10a24 (diff) | |
| download | poky-a7309d5790f5dac46e84d3c14959943eb2496fda.tar.gz | |
classes/lib: Update to use python3 command pipeline decoding
In python3, strings are unicode by default. We need to encode/decode
from command pipelines and other places where we interface with the
real world using the correct locales. This patch updates various
call sites to use the correct encoding/decodings.
(From OE-Core rev: bb4685af1bffe17b3aa92a6d21398f38a44ea874)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa')
| -rw-r--r-- | meta/lib/oeqa/oetest.py | 4 | ||||
| -rw-r--r-- | meta/lib/oeqa/runtime/parselogs.py | 4 | ||||
| -rw-r--r-- | meta/lib/oeqa/runtime/ping.py | 2 | ||||
| -rw-r--r-- | meta/lib/oeqa/utils/commands.py | 2 | ||||
| -rw-r--r-- | meta/lib/oeqa/utils/qemurunner.py | 26 | ||||
| -rw-r--r-- | meta/lib/oeqa/utils/qemutinyrunner.py | 4 | ||||
| -rw-r--r-- | meta/lib/oeqa/utils/sshcontrol.py | 1 |
7 files changed, 25 insertions, 18 deletions
diff --git a/meta/lib/oeqa/oetest.py b/meta/lib/oeqa/oetest.py index a50f9d8187..4211ffc379 100644 --- a/meta/lib/oeqa/oetest.py +++ b/meta/lib/oeqa/oetest.py | |||
| @@ -132,7 +132,7 @@ class oeSDKTest(oeTest): | |||
| 132 | return False | 132 | return False |
| 133 | 133 | ||
| 134 | def _run(self, cmd): | 134 | def _run(self, cmd): |
| 135 | return subprocess.check_output(". %s > /dev/null; %s;" % (self.tc.sdkenv, cmd), shell=True) | 135 | return subprocess.check_output(". %s > /dev/null; %s;" % (self.tc.sdkenv, cmd), shell=True).decode("utf-8") |
| 136 | 136 | ||
| 137 | class oeSDKExtTest(oeSDKTest): | 137 | class oeSDKExtTest(oeSDKTest): |
| 138 | def _run(self, cmd): | 138 | def _run(self, cmd): |
| @@ -144,7 +144,7 @@ class oeSDKExtTest(oeSDKTest): | |||
| 144 | env['PATH'] = avoid_paths_in_environ(paths_to_avoid) | 144 | env['PATH'] = avoid_paths_in_environ(paths_to_avoid) |
| 145 | 145 | ||
| 146 | return subprocess.check_output(". %s > /dev/null;"\ | 146 | return subprocess.check_output(". %s > /dev/null;"\ |
| 147 | " %s;" % (self.tc.sdkenv, cmd), shell=True, env=env) | 147 | " %s;" % (self.tc.sdkenv, cmd), shell=True, env=env).decode("utf-8") |
| 148 | 148 | ||
| 149 | def getmodule(pos=2): | 149 | def getmodule(pos=2): |
| 150 | # stack returns a list of tuples containg frame information | 150 | # stack returns a list of tuples containg frame information |
diff --git a/meta/lib/oeqa/runtime/parselogs.py b/meta/lib/oeqa/runtime/parselogs.py index a93660131d..242cd8cdd5 100644 --- a/meta/lib/oeqa/runtime/parselogs.py +++ b/meta/lib/oeqa/runtime/parselogs.py | |||
| @@ -238,7 +238,7 @@ class ParseLogsTest(oeRuntimeTest): | |||
| 238 | result = None | 238 | result = None |
| 239 | thegrep = self.build_grepcmd(errors, ignore_errors, log) | 239 | thegrep = self.build_grepcmd(errors, ignore_errors, log) |
| 240 | try: | 240 | try: |
| 241 | result = subprocess.check_output(thegrep, shell=True) | 241 | result = subprocess.check_output(thegrep, shell=True).decode("utf-8") |
| 242 | except: | 242 | except: |
| 243 | pass | 243 | pass |
| 244 | if (result is not None): | 244 | if (result is not None): |
| @@ -246,7 +246,7 @@ class ParseLogsTest(oeRuntimeTest): | |||
| 246 | rez = result.splitlines() | 246 | rez = result.splitlines() |
| 247 | for xrez in rez: | 247 | for xrez in rez: |
| 248 | try: | 248 | try: |
| 249 | grep_output = subprocess.check_output(['grep', '-F', xrez, '-B', str(lines_before), '-A', str(lines_after), log]) | 249 | grep_output = subprocess.check_output(['grep', '-F', xrez, '-B', str(lines_before), '-A', str(lines_after), log]).decode("utf-8") |
| 250 | except: | 250 | except: |
| 251 | pass | 251 | pass |
| 252 | results[log.replace('target_logs/','')][xrez]=grep_output | 252 | results[log.replace('target_logs/','')][xrez]=grep_output |
diff --git a/meta/lib/oeqa/runtime/ping.py b/meta/lib/oeqa/runtime/ping.py index 80c460161b..0f27447926 100644 --- a/meta/lib/oeqa/runtime/ping.py +++ b/meta/lib/oeqa/runtime/ping.py | |||
| @@ -14,7 +14,7 @@ class PingTest(oeRuntimeTest): | |||
| 14 | endtime = time.time() + 60 | 14 | endtime = time.time() + 60 |
| 15 | while count < 5 and time.time() < endtime: | 15 | while count < 5 and time.time() < endtime: |
| 16 | proc = subprocess.Popen("ping -c 1 %s" % self.target.ip, shell=True, stdout=subprocess.PIPE) | 16 | proc = subprocess.Popen("ping -c 1 %s" % self.target.ip, shell=True, stdout=subprocess.PIPE) |
| 17 | output += proc.communicate()[0] | 17 | output += proc.communicate()[0].decode("utf-8") |
| 18 | if proc.poll() == 0: | 18 | if proc.poll() == 0: |
| 19 | count += 1 | 19 | count += 1 |
| 20 | else: | 20 | else: |
diff --git a/meta/lib/oeqa/utils/commands.py b/meta/lib/oeqa/utils/commands.py index 48f6441290..9a7c1d1375 100644 --- a/meta/lib/oeqa/utils/commands.py +++ b/meta/lib/oeqa/utils/commands.py | |||
| @@ -78,7 +78,7 @@ class Command(object): | |||
| 78 | self.process.kill() | 78 | self.process.kill() |
| 79 | self.thread.join() | 79 | self.thread.join() |
| 80 | 80 | ||
| 81 | self.output = self.output.rstrip() | 81 | self.output = self.output.decode("utf-8").rstrip() |
| 82 | self.status = self.process.poll() | 82 | self.status = self.process.poll() |
| 83 | 83 | ||
| 84 | self.log.debug("Command '%s' returned %d as exit code." % (self.cmd, self.status)) | 84 | self.log.debug("Command '%s' returned %d as exit code." % (self.cmd, self.status)) |
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py index 695402fead..f51de99458 100644 --- a/meta/lib/oeqa/utils/qemurunner.py +++ b/meta/lib/oeqa/utils/qemurunner.py | |||
| @@ -71,7 +71,8 @@ class QemuRunner: | |||
| 71 | if self.logfile: | 71 | if self.logfile: |
| 72 | # It is needed to sanitize the data received from qemu | 72 | # It is needed to sanitize the data received from qemu |
| 73 | # because is possible to have control characters | 73 | # because is possible to have control characters |
| 74 | msg = re_control_char.sub('', unicode(msg, 'utf-8')) | 74 | msg = msg.decode("utf-8") |
| 75 | msg = re_control_char.sub('', msg) | ||
| 75 | with codecs.open(self.logfile, "a", encoding="utf-8") as f: | 76 | with codecs.open(self.logfile, "a", encoding="utf-8") as f: |
| 76 | f.write("%s" % msg) | 77 | f.write("%s" % msg) |
| 77 | 78 | ||
| @@ -79,7 +80,7 @@ class QemuRunner: | |||
| 79 | import fcntl | 80 | import fcntl |
| 80 | fl = fcntl.fcntl(o, fcntl.F_GETFL) | 81 | fl = fcntl.fcntl(o, fcntl.F_GETFL) |
| 81 | fcntl.fcntl(o, fcntl.F_SETFL, fl | os.O_NONBLOCK) | 82 | fcntl.fcntl(o, fcntl.F_SETFL, fl | os.O_NONBLOCK) |
| 82 | return os.read(o.fileno(), 1000000) | 83 | return os.read(o.fileno(), 1000000).decode("utf-8") |
| 83 | 84 | ||
| 84 | 85 | ||
| 85 | def handleSIGCHLD(self, signum, frame): | 86 | def handleSIGCHLD(self, signum, frame): |
| @@ -229,14 +230,19 @@ class QemuRunner: | |||
| 229 | socklist.remove(self.server_socket) | 230 | socklist.remove(self.server_socket) |
| 230 | logger.info("Connection from %s:%s" % addr) | 231 | logger.info("Connection from %s:%s" % addr) |
| 231 | else: | 232 | else: |
| 232 | data = sock.recv(1024) | 233 | data = data + sock.recv(1024) |
| 233 | if data: | 234 | if data: |
| 234 | bootlog += data | 235 | try: |
| 235 | if re.search(".* login:", bootlog): | 236 | data = data.decode("utf-8") |
| 236 | self.server_socket = qemusock | 237 | bootlog += data |
| 237 | stopread = True | 238 | data = b'' |
| 238 | reachedlogin = True | 239 | if re.search(".* login:", bootlog): |
| 239 | logger.info("Reached login banner") | 240 | self.server_socket = qemusock |
| 241 | stopread = True | ||
| 242 | reachedlogin = True | ||
| 243 | logger.info("Reached login banner") | ||
| 244 | except UnicodeDecodeError: | ||
| 245 | continue | ||
| 240 | else: | 246 | else: |
| 241 | socklist.remove(sock) | 247 | socklist.remove(sock) |
| 242 | sock.close() | 248 | sock.close() |
| @@ -325,7 +331,7 @@ class QemuRunner: | |||
| 325 | # Walk the process tree from the process specified looking for a qemu-system. Return its [pid'cmd] | 331 | # Walk the process tree from the process specified looking for a qemu-system. Return its [pid'cmd] |
| 326 | # | 332 | # |
| 327 | ps = subprocess.Popen(['ps', 'axww', '-o', 'pid,ppid,command'], stdout=subprocess.PIPE).communicate()[0] | 333 | ps = subprocess.Popen(['ps', 'axww', '-o', 'pid,ppid,command'], stdout=subprocess.PIPE).communicate()[0] |
| 328 | processes = ps.split('\n') | 334 | processes = ps.decode("utf-8").split('\n') |
| 329 | nfields = len(processes[0].split()) - 1 | 335 | nfields = len(processes[0].split()) - 1 |
| 330 | pids = {} | 336 | pids = {} |
| 331 | commands = {} | 337 | commands = {} |
diff --git a/meta/lib/oeqa/utils/qemutinyrunner.py b/meta/lib/oeqa/utils/qemutinyrunner.py index d6ce09645c..054ab0ec5d 100644 --- a/meta/lib/oeqa/utils/qemutinyrunner.py +++ b/meta/lib/oeqa/utils/qemutinyrunner.py | |||
| @@ -102,7 +102,7 @@ class QemuTinyRunner(QemuRunner): | |||
| 102 | bb.note("Qemu pid didn't appeared in %s seconds" % self.runqemutime) | 102 | bb.note("Qemu pid didn't appeared in %s seconds" % self.runqemutime) |
| 103 | output = self.runqemu.stdout | 103 | output = self.runqemu.stdout |
| 104 | self.stop() | 104 | self.stop() |
| 105 | bb.note("Output from runqemu:\n%s" % output.read()) | 105 | bb.note("Output from runqemu:\n%s" % output.read().decode("utf-8")) |
| 106 | return False | 106 | return False |
| 107 | 107 | ||
| 108 | return self.is_alive() | 108 | return self.is_alive() |
| @@ -131,7 +131,7 @@ class QemuTinyRunner(QemuRunner): | |||
| 131 | # Walk the process tree from the process specified looking for a qemu-system. Return its [pid'cmd] | 131 | # Walk the process tree from the process specified looking for a qemu-system. Return its [pid'cmd] |
| 132 | # | 132 | # |
| 133 | ps = subprocess.Popen(['ps', 'axww', '-o', 'pid,ppid,command'], stdout=subprocess.PIPE).communicate()[0] | 133 | ps = subprocess.Popen(['ps', 'axww', '-o', 'pid,ppid,command'], stdout=subprocess.PIPE).communicate()[0] |
| 134 | processes = ps.split('\n') | 134 | processes = ps.decode("utf-8").split('\n') |
| 135 | nfields = len(processes[0].split()) - 1 | 135 | nfields = len(processes[0].split()) - 1 |
| 136 | pids = {} | 136 | pids = {} |
| 137 | commands = {} | 137 | commands = {} |
diff --git a/meta/lib/oeqa/utils/sshcontrol.py b/meta/lib/oeqa/utils/sshcontrol.py index ff88d37bd9..f5d46e03cc 100644 --- a/meta/lib/oeqa/utils/sshcontrol.py +++ b/meta/lib/oeqa/utils/sshcontrol.py | |||
| @@ -58,6 +58,7 @@ class SSHProcess(object): | |||
| 58 | self.process.stdout.close() | 58 | self.process.stdout.close() |
| 59 | eof = True | 59 | eof = True |
| 60 | else: | 60 | else: |
| 61 | data = data.decode("utf-8") | ||
| 61 | output += data | 62 | output += data |
| 62 | self.log(data) | 63 | self.log(data) |
| 63 | endtime = time.time() + timeout | 64 | endtime = time.time() + timeout |
