diff options
Diffstat (limited to 'meta/lib/oeqa/utils/qemurunner.py')
-rw-r--r-- | meta/lib/oeqa/utils/qemurunner.py | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/meta/lib/oeqa/utils/qemurunner.py b/meta/lib/oeqa/utils/qemurunner.py index 256cf3c6a8..5366a635fe 100644 --- a/meta/lib/oeqa/utils/qemurunner.py +++ b/meta/lib/oeqa/utils/qemurunner.py | |||
@@ -16,25 +16,30 @@ import bb | |||
16 | 16 | ||
17 | class QemuRunner: | 17 | class QemuRunner: |
18 | 18 | ||
19 | def __init__(self, machine, rootfs, display = None, tmpdir = None, deploy_dir_image = None, logfile = None, boottime = 400, runqemutime = 60): | 19 | def __init__(self, machine, rootfs, display, tmpdir, deploy_dir_image, logfile, boottime): |
20 | # Popen object | ||
21 | self.runqemu = None | ||
22 | |||
23 | self.machine = machine | ||
24 | self.rootfs = rootfs | ||
25 | 20 | ||
21 | # Popen object for runqemu | ||
22 | self.runqemu = None | ||
23 | # pid of the qemu process that runqemu will start | ||
26 | self.qemupid = None | 24 | self.qemupid = None |
25 | # target ip - from the command line | ||
27 | self.ip = None | 26 | self.ip = None |
27 | # host ip - where qemu is running | ||
28 | self.server_ip = None | ||
28 | 29 | ||
30 | self.machine = machine | ||
31 | self.rootfs = rootfs | ||
29 | self.display = display | 32 | self.display = display |
30 | self.tmpdir = tmpdir | 33 | self.tmpdir = tmpdir |
31 | self.deploy_dir_image = deploy_dir_image | 34 | self.deploy_dir_image = deploy_dir_image |
32 | self.logfile = logfile | 35 | self.logfile = logfile |
33 | self.boottime = boottime | 36 | self.boottime = boottime |
34 | self.runqemutime = runqemutime | 37 | |
38 | self.runqemutime = 60 | ||
35 | 39 | ||
36 | self.create_socket() | 40 | self.create_socket() |
37 | 41 | ||
42 | |||
38 | def create_socket(self): | 43 | def create_socket(self): |
39 | 44 | ||
40 | self.bootlog = '' | 45 | self.bootlog = '' |
@@ -57,7 +62,7 @@ class QemuRunner: | |||
57 | with open(self.logfile, "a") as f: | 62 | with open(self.logfile, "a") as f: |
58 | f.write("%s" % msg) | 63 | f.write("%s" % msg) |
59 | 64 | ||
60 | def launch(self, qemuparams = None): | 65 | def start(self, qemuparams = None): |
61 | 66 | ||
62 | if self.display: | 67 | if self.display: |
63 | os.environ["DISPLAY"] = self.display | 68 | os.environ["DISPLAY"] = self.display |
@@ -96,14 +101,19 @@ class QemuRunner: | |||
96 | 101 | ||
97 | if self.is_alive(): | 102 | if self.is_alive(): |
98 | bb.note("qemu started - qemu procces pid is %s" % self.qemupid) | 103 | bb.note("qemu started - qemu procces pid is %s" % self.qemupid) |
99 | cmdline = open('/proc/%s/cmdline' % self.qemupid).read() | 104 | cmdline = '' |
100 | self.ip, _, self.host_ip = cmdline.split('ip=')[1].split(' ')[0].split(':')[0:3] | 105 | with open('/proc/%s/cmdline' % self.qemupid) as p: |
101 | if not re.search("^((?:[0-9]{1,3}\.){3}[0-9]{1,3})$", self.ip): | 106 | cmdline = p.read() |
102 | bb.note("Couldn't get ip from qemu process arguments, I got '%s'" % self.ip) | 107 | ips = re.findall("((?:[0-9]{1,3}\.){3}[0-9]{1,3})", cmdline.split("ip=")[1]) |
103 | bb.note("Here is the ps output:\n%s" % cmdline) | 108 | if not ips or len(ips) != 3: |
104 | self.kill() | 109 | bb.note("Couldn't get ip from qemu process arguments! Here is the qemu command line used: %s" % cmdline) |
110 | self.stop() | ||
105 | return False | 111 | return False |
106 | bb.note("IP found: %s" % self.ip) | 112 | else: |
113 | self.ip = ips[0] | ||
114 | self.server_ip = ips[1] | ||
115 | bb.note("Target IP: %s" % self.ip) | ||
116 | bb.note("Server IP: %s" % self.server_ip) | ||
107 | bb.note("Waiting at most %d seconds for login banner" % self.boottime ) | 117 | bb.note("Waiting at most %d seconds for login banner" % self.boottime ) |
108 | endtime = time.time() + self.boottime | 118 | endtime = time.time() + self.boottime |
109 | socklist = [self.server_socket] | 119 | socklist = [self.server_socket] |
@@ -138,18 +148,18 @@ class QemuRunner: | |||
138 | lines = "\n".join(self.bootlog.splitlines()[-5:]) | 148 | lines = "\n".join(self.bootlog.splitlines()[-5:]) |
139 | bb.note("Last 5 lines of text:\n%s" % lines) | 149 | bb.note("Last 5 lines of text:\n%s" % lines) |
140 | bb.note("Check full boot log: %s" % self.logfile) | 150 | bb.note("Check full boot log: %s" % self.logfile) |
141 | self.kill() | 151 | self.stop() |
142 | return False | 152 | return False |
143 | else: | 153 | else: |
144 | bb.note("Qemu pid didn't appeared in %s seconds" % self.runqemutime) | 154 | bb.note("Qemu pid didn't appeared in %s seconds" % self.runqemutime) |
145 | output = self.runqemu.stdout | 155 | output = self.runqemu.stdout |
146 | self.kill() | 156 | self.stop() |
147 | bb.note("Output from runqemu:\n%s" % output.read()) | 157 | bb.note("Output from runqemu:\n%s" % output.read()) |
148 | return False | 158 | return False |
149 | 159 | ||
150 | return self.is_alive() | 160 | return self.is_alive() |
151 | 161 | ||
152 | def kill(self): | 162 | def stop(self): |
153 | 163 | ||
154 | if self.runqemu: | 164 | if self.runqemu: |
155 | bb.note("Sending SIGTERM to runqemu") | 165 | bb.note("Sending SIGTERM to runqemu") |
@@ -170,9 +180,9 @@ class QemuRunner: | |||
170 | def restart(self, qemuparams = None): | 180 | def restart(self, qemuparams = None): |
171 | bb.note("Restarting qemu process") | 181 | bb.note("Restarting qemu process") |
172 | if self.runqemu.poll() is None: | 182 | if self.runqemu.poll() is None: |
173 | self.kill() | 183 | self.stop() |
174 | self.create_socket() | 184 | self.create_socket() |
175 | if self.launch(qemuparams): | 185 | if self.start(qemuparams): |
176 | return True | 186 | return True |
177 | return False | 187 | return False |
178 | 188 | ||