summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils/qemurunner.py
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/qemurunner.py
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/qemurunner.py')
-rw-r--r--meta/lib/oeqa/utils/qemurunner.py26
1 files changed, 16 insertions, 10 deletions
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 = {}