Skip to content

Commit 158aba8

Browse files
committed
qemu: Simplyify pexpect timeout handling
Give each pexpect call 60 seconds by default. Calculate the other timeouts based on that, by default allow 5 minutes to boot, that is the value we were previously using for cloud image boots, for cpio boots it gives them longer than before. Set the global timeout at 10 x the pexpect timeout.
1 parent 096301e commit 158aba8

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

lib/pexpect_utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ def __init__(self):
2121
self.prompt = None
2222
self.prompt_stack = []
2323
self.bug_patterns = self.default_bug_patterns
24-
self.timeout = 60
2524

2625
def spawn(self, *args, **kwargs):
2726
logging.info("Spawning '%s'" % args)
28-
self.child = pexpect.spawn(*args, timeout=self.timeout, encoding='utf-8', echo=False, **kwargs)
27+
self.child = pexpect.spawn(*args, encoding='utf-8', echo=False, **kwargs)
2928
if '--quiet' not in sys.argv:
3029
self.log_to(sys.stdout)
3130

lib/qemu.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,6 @@ def qemu_main(qemu_machine, cpuinfo_platform, cpu, net, args):
140140

141141
cloud_image = os.environ.get('CLOUD_IMAGE', False)
142142
if cloud_image:
143-
boot_timeout = 300
144-
145143
# Create snapshot image
146144
rdpath = get_root_disk_path()
147145
src = f'{rdpath}/{cloud_image}'
@@ -170,7 +168,6 @@ def qemu_main(qemu_machine, cpuinfo_platform, cpu, net, args):
170168
drive += f'-drive file={dst},format=qcow2,if={interface},id=drive0 ' \
171169
f'-drive file={rdpath}/cloud-init-user-data.img,format=raw,if={interface},readonly=on,id=drive1'
172170
else:
173-
boot_timeout = 120
174171
drive = None
175172

176173
host_mount = os.environ.get('QEMU_HOST_MOUNT', '')
@@ -180,14 +177,13 @@ def qemu_main(qemu_machine, cpuinfo_platform, cpu, net, args):
180177

181178
cmdline += get_env_var('LINUX_CMDLINE', '')
182179

183-
p = PexpectHelper()
180+
# Default timeout for a single pexpect call
181+
pexpect_timeout = 60
184182

183+
gdb = None
185184
if '--gdb' in args:
186185
gdb = '-s -S'
187-
p.timeout = None
188-
boot_timeout = None
189-
else:
190-
gdb = None
186+
pexpect_timeout = 0
191187

192188
cmd = qemu_command(machine=qemu_machine, cpu=cpu, mem='4G', smp=smp, vmlinux=vmlinux,
193189
drive=drive, host_mount=host_mount, cmdline=cmdline, accel=accel,
@@ -198,16 +194,18 @@ def qemu_main(qemu_machine, cpuinfo_platform, cpu, net, args):
198194
rc = subprocess.run(cmd, shell=True).returncode
199195
return rc == 0
200196

201-
if not gdb:
202-
setup_timeout(600)
197+
setup_timeout(10 * pexpect_timeout)
198+
boot_timeout = pexpect_timeout * 5
203199

204200
logpath = get_env_var('QEMU_CONSOLE_LOG', 'console.log')
205-
p.spawn(cmd, logfile=open(logpath, 'w'))
201+
202+
p = PexpectHelper()
203+
p.spawn(cmd, logfile=open(logpath, 'w'), timeout=pexpect_timeout)
206204

207205
if cloud_image:
208206
standard_boot(p, prompt=prompt, login=True, password='linuxppc', timeout=boot_timeout)
209207
else:
210-
standard_boot(p)
208+
standard_boot(p, timeout=boot_timeout)
211209

212210
p.send("echo -n 'booted-revision: '; uname -r")
213211
p.expect(f'booted-revision: {expected_release}')

0 commit comments

Comments
 (0)