summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils
diff options
context:
space:
mode:
authorRoss Burton <ross.burton@intel.com>2015-07-22 15:20:48 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-07-23 08:48:40 +0100
commit1b17b58c5142611d1dc3e7635dafb9b3980fe2d0 (patch)
tree5dafbc5a331122a4995ec3aaa504272e0b89b41e /meta/lib/oeqa/utils
parentd87878ee12b9fcf9699e55817f137c1682d58ce4 (diff)
downloadpoky-1b17b58c5142611d1dc3e7635dafb9b3980fe2d0.tar.gz
oeqa/QemuRunner: don't use bb for logging
Instead of using bb.note() etc for logging use logging.Logger directly, allowing the use of QemuRunner outside of bitbake. Also clean up the logging/errors by moving create_socket() out of __init__()/restart() and into start(). (From OE-Core rev: 519e381278d40bdac79add340e4c0460a9f97e17) Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/utils')
-rw-r--r--meta/lib/oeqa/utils/qemurunner.py61
1 files changed, 32 insertions, 29 deletions
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py
index f1a7e24ab7..a15990eaa8 100644
--- a/meta/lib/oeqa/utils/qemurunner.py
+++ b/meta/lib/oeqa/utils/qemurunner.py
@@ -12,7 +12,10 @@ import signal
12import re 12import re
13import socket 13import socket
14import select 14import select
15import bb 15
16import logging
17logger = logging.getLogger("QemuRunner")
18logger.setLevel(logging.DEBUG - 2)
16 19
17class QemuRunner: 20class QemuRunner:
18 21
@@ -37,9 +40,6 @@ class QemuRunner:
37 40
38 self.runqemutime = 60 41 self.runqemutime = 60
39 42
40 self.create_socket()
41
42
43 def create_socket(self): 43 def create_socket(self):
44 44
45 self.bootlog = '' 45 self.bootlog = ''
@@ -51,10 +51,12 @@ class QemuRunner:
51 self.server_socket.bind(("127.0.0.1",0)) 51 self.server_socket.bind(("127.0.0.1",0))
52 self.server_socket.listen(2) 52 self.server_socket.listen(2)
53 self.serverport = self.server_socket.getsockname()[1] 53 self.serverport = self.server_socket.getsockname()[1]
54 bb.note("Created listening socket for qemu serial console on: 127.0.0.1:%s" % self.serverport) 54 logging.info("Created listening socket for qemu serial console on: 127.0.0.1:%s" % self.serverport)
55 return True
55 except socket.error, msg: 56 except socket.error, msg:
56 self.server_socket.close() 57 self.server_socket.close()
57 bb.fatal("Failed to create listening socket: %s" %msg[1]) 58 logging.error("Failed to create listening socket: %s" % msg[1])
59 return False
58 60
59 61
60 def log(self, msg): 62 def log(self, msg):
@@ -63,26 +65,28 @@ class QemuRunner:
63 f.write("%s" % msg) 65 f.write("%s" % msg)
64 66
65 def start(self, qemuparams = None): 67 def start(self, qemuparams = None):
66
67 if self.display: 68 if self.display:
68 os.environ["DISPLAY"] = self.display 69 os.environ["DISPLAY"] = self.display
69 else: 70 else:
70 bb.error("To start qemu I need a X desktop, please set DISPLAY correctly (e.g. DISPLAY=:1)") 71 logging.error("To start qemu I need a X desktop, please set DISPLAY correctly (e.g. DISPLAY=:1)")
71 return False 72 return False
72 if not os.path.exists(self.rootfs): 73 if not os.path.exists(self.rootfs):
73 bb.error("Invalid rootfs %s" % self.rootfs) 74 logging.error("Invalid rootfs %s" % self.rootfs)
74 return False 75 return False
75 if not os.path.exists(self.tmpdir): 76 if not os.path.exists(self.tmpdir):
76 bb.error("Invalid TMPDIR path %s" % self.tmpdir) 77 logging.error("Invalid TMPDIR path %s" % self.tmpdir)
77 return False 78 return False
78 else: 79 else:
79 os.environ["OE_TMPDIR"] = self.tmpdir 80 os.environ["OE_TMPDIR"] = self.tmpdir
80 if not os.path.exists(self.deploy_dir_image): 81 if not os.path.exists(self.deploy_dir_image):
81 bb.error("Invalid DEPLOY_DIR_IMAGE path %s" % self.deploy_dir_image) 82 logging.error("Invalid DEPLOY_DIR_IMAGE path %s" % self.deploy_dir_image)
82 return False 83 return False
83 else: 84 else:
84 os.environ["DEPLOY_DIR_IMAGE"] = self.deploy_dir_image 85 os.environ["DEPLOY_DIR_IMAGE"] = self.deploy_dir_image
85 86
87 if not self.create_socket():
88 return False
89
86 # Set this flag so that Qemu doesn't do any grabs as SDL grabs interact 90 # Set this flag so that Qemu doesn't do any grabs as SDL grabs interact
87 # badly with screensavers. 91 # badly with screensavers.
88 os.environ["QEMU_DONT_GRAB"] = "1" 92 os.environ["QEMU_DONT_GRAB"] = "1"
@@ -93,28 +97,28 @@ class QemuRunner:
93 launch_cmd = 'runqemu %s %s %s' % (self.machine, self.rootfs, self.qemuparams) 97 launch_cmd = 'runqemu %s %s %s' % (self.machine, self.rootfs, self.qemuparams)
94 self.runqemu = subprocess.Popen(launch_cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,preexec_fn=os.setpgrp) 98 self.runqemu = subprocess.Popen(launch_cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,preexec_fn=os.setpgrp)
95 99
96 bb.note("runqemu started, pid is %s" % self.runqemu.pid) 100 logging.info("runqemu started, pid is %s" % self.runqemu.pid)
97 bb.note("waiting at most %s seconds for qemu pid" % self.runqemutime) 101 logging.info("waiting at most %s seconds for qemu pid" % self.runqemutime)
98 endtime = time.time() + self.runqemutime 102 endtime = time.time() + self.runqemutime
99 while not self.is_alive() and time.time() < endtime: 103 while not self.is_alive() and time.time() < endtime:
100 time.sleep(1) 104 time.sleep(1)
101 105
102 if self.is_alive(): 106 if self.is_alive():
103 bb.note("qemu started - qemu procces pid is %s" % self.qemupid) 107 logging.info("qemu started - qemu procces pid is %s" % self.qemupid)
104 cmdline = '' 108 cmdline = ''
105 with open('/proc/%s/cmdline' % self.qemupid) as p: 109 with open('/proc/%s/cmdline' % self.qemupid) as p:
106 cmdline = p.read() 110 cmdline = p.read()
107 ips = re.findall("((?:[0-9]{1,3}\.){3}[0-9]{1,3})", cmdline.split("ip=")[1]) 111 ips = re.findall("((?:[0-9]{1,3}\.){3}[0-9]{1,3})", cmdline.split("ip=")[1])
108 if not ips or len(ips) != 3: 112 if not ips or len(ips) != 3:
109 bb.note("Couldn't get ip from qemu process arguments! Here is the qemu command line used: %s" % cmdline) 113 logging.info("Couldn't get ip from qemu process arguments! Here is the qemu command line used: %s" % cmdline)
110 self.stop() 114 self.stop()
111 return False 115 return False
112 else: 116 else:
113 self.ip = ips[0] 117 self.ip = ips[0]
114 self.server_ip = ips[1] 118 self.server_ip = ips[1]
115 bb.note("Target IP: %s" % self.ip) 119 logging.info("Target IP: %s" % self.ip)
116 bb.note("Server IP: %s" % self.server_ip) 120 logging.info("Server IP: %s" % self.server_ip)
117 bb.note("Waiting at most %d seconds for login banner" % self.boottime ) 121 logging.info("Waiting at most %d seconds for login banner" % self.boottime)
118 endtime = time.time() + self.boottime 122 endtime = time.time() + self.boottime
119 socklist = [self.server_socket] 123 socklist = [self.server_socket]
120 reachedlogin = False 124 reachedlogin = False
@@ -127,7 +131,7 @@ class QemuRunner:
127 self.qemusock.setblocking(0) 131 self.qemusock.setblocking(0)
128 socklist.append(self.qemusock) 132 socklist.append(self.qemusock)
129 socklist.remove(self.server_socket) 133 socklist.remove(self.server_socket)
130 bb.note("Connection from %s:%s" % addr) 134 logging.info("Connection from %s:%s" % addr)
131 else: 135 else:
132 data = sock.recv(1024) 136 data = sock.recv(1024)
133 if data: 137 if data:
@@ -136,24 +140,24 @@ class QemuRunner:
136 if re.search("qemu.* login:", self.bootlog): 140 if re.search("qemu.* login:", self.bootlog):
137 stopread = True 141 stopread = True
138 reachedlogin = True 142 reachedlogin = True
139 bb.note("Reached login banner") 143 logging.info("Reached login banner")
140 else: 144 else:
141 socklist.remove(sock) 145 socklist.remove(sock)
142 sock.close() 146 sock.close()
143 stopread = True 147 stopread = True
144 148
145 if not reachedlogin: 149 if not reachedlogin:
146 bb.note("Target didn't reached login boot in %d seconds" % self.boottime) 150 logging.info("Target didn't reached login boot in %d seconds" % self.boottime)
147 lines = "\n".join(self.bootlog.splitlines()[-5:]) 151 lines = "\n".join(self.bootlog.splitlines()[-5:])
148 bb.note("Last 5 lines of text:\n%s" % lines) 152 logging.info("Last 5 lines of text:\n%s" % lines)
149 bb.note("Check full boot log: %s" % self.logfile) 153 logging.info("Check full boot log: %s" % self.logfile)
150 self.stop() 154 self.stop()
151 return False 155 return False
152 else: 156 else:
153 bb.note("Qemu pid didn't appeared in %s seconds" % self.runqemutime) 157 logging.info("Qemu pid didn't appeared in %s seconds" % self.runqemutime)
154 output = self.runqemu.stdout 158 output = self.runqemu.stdout
155 self.stop() 159 self.stop()
156 bb.note("Output from runqemu:\n%s" % output.read()) 160 logging.info("Output from runqemu:\n%s" % output.read())
157 return False 161 return False
158 162
159 return self.is_alive() 163 return self.is_alive()
@@ -161,13 +165,13 @@ class QemuRunner:
161 def stop(self): 165 def stop(self):
162 166
163 if self.runqemu: 167 if self.runqemu:
164 bb.note("Sending SIGTERM to runqemu") 168 logging.info("Sending SIGTERM to runqemu")
165 os.killpg(self.runqemu.pid, signal.SIGTERM) 169 os.killpg(self.runqemu.pid, signal.SIGTERM)
166 endtime = time.time() + self.runqemutime 170 endtime = time.time() + self.runqemutime
167 while self.runqemu.poll() is None and time.time() < endtime: 171 while self.runqemu.poll() is None and time.time() < endtime:
168 time.sleep(1) 172 time.sleep(1)
169 if self.runqemu.poll() is None: 173 if self.runqemu.poll() is None:
170 bb.note("Sending SIGKILL to runqemu") 174 logging.info("Sending SIGKILL to runqemu")
171 os.killpg(self.runqemu.pid, signal.SIGKILL) 175 os.killpg(self.runqemu.pid, signal.SIGKILL)
172 self.runqemu = None 176 self.runqemu = None
173 if self.server_socket: 177 if self.server_socket:
@@ -177,10 +181,9 @@ class QemuRunner:
177 self.ip = None 181 self.ip = None
178 182
179 def restart(self, qemuparams = None): 183 def restart(self, qemuparams = None):
180 bb.note("Restarting qemu process") 184 logging.info("Restarting qemu process")
181 if self.runqemu.poll() is None: 185 if self.runqemu.poll() is None:
182 self.stop() 186 self.stop()
183 self.create_socket()
184 if self.start(qemuparams): 187 if self.start(qemuparams):
185 return True 188 return True
186 return False 189 return False