Skip to content

Commit

Permalink
contest: vmtest: add main process to kill list
Browse files Browse the repository at this point in the history
If start() fails we need a way to kill current process
before we retry. Move saving children earlier.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
kuba-moo committed Jan 15, 2024
1 parent 59d1916 commit a408cbd
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions contest/remote/vmtest.py
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ class VM:
def __init__(self, config):
self.fail_state = ""
self.p = None
self.children = []
self.procs = []
self.config = config

self.cfg_boot_to = int(config.get('vm', 'boot_timeout'))
@@ -116,7 +116,12 @@ def start(self):
if init_prompt[-1] != ' ':
init_prompt += ' '
print(f"INFO: expecting prompt: '{init_prompt}'")
self.drain_to_prompt(prompt=init_prompt, dump_after=self.cfg_boot_to)
try:
self.drain_to_prompt(prompt=init_prompt, dump_after=self.cfg_boot_to)
finally:
# Save the children, we'll need to kill them on crash
proc = psutil.Process(self.p.pid)
self.procs = proc.procs(recursive=True) + [proc]

print("INFO: reached initial prompt")
self.cmd("PS1='xx__-> '")
@@ -127,18 +132,15 @@ def start(self):
self.cmd("export PATH=" + self.config.get('vm', 'paths') + ':$PATH')
self.drain_to_prompt()

# Save the children, we'll need to kill them on crash
self.children = psutil.Process(self.p.pid).children(recursive=True)

def stop(self):
self.cmd("exit")
try:
stdout, stderr = self.p.communicate(timeout=3)
except subprocess.TimeoutExpired:
print("WARNING: process did not exit, sending a KILL to", self.p.pid, self.children)
for c in self.children:
print("WARNING: process did not exit, sending a KILL to", self.p.pid, self.procs)
for p in self.procs:
try:
c.kill()
p.kill()
except psutil.NoSuchProcess:
pass
stdout, stderr = self.p.communicate(timeout=2)

0 comments on commit a408cbd

Please sign in to comment.