summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2016-05-20 11:17:05 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-06-02 08:24:00 +0100
commita7309d5790f5dac46e84d3c14959943eb2496fda (patch)
tree48e1fcb886b8ef2974bade09694356f3230fb8a8 /meta/lib/oeqa/utils
parent297438e965053b2eb56cc8ef3e59465642f10a24 (diff)
downloadpoky-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/utils')
-rw-r--r--meta/lib/oeqa/utils/commands.py2
-rw-r--r--meta/lib/oeqa/utils/qemurunner.py26
-rw-r--r--meta/lib/oeqa/utils/qemutinyrunner.py4
-rw-r--r--meta/lib/oeqa/utils/sshcontrol.py1
4 files changed, 20 insertions, 13 deletions
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