Merge pull request #97346 from NinjaTrappeur/nin-fix-vm-rm-state
test-driver.py: fix VM state directory deletion
This commit is contained in:
commit
ee55841b22
@ -217,7 +217,7 @@ class Machine:
|
||||
match = re.search("run-(.+)-vm$", cmd)
|
||||
if match:
|
||||
self.name = match.group(1)
|
||||
|
||||
self.logger = args["log"]
|
||||
self.script = args.get("startCommand", self.create_startcommand(args))
|
||||
|
||||
tmp_dir = os.environ.get("TMPDIR", tempfile.gettempdir())
|
||||
@ -227,7 +227,10 @@ class Machine:
|
||||
os.makedirs(path, mode=0o700, exist_ok=True)
|
||||
return path
|
||||
|
||||
self.state_dir = create_dir("vm-state-{}".format(self.name))
|
||||
self.state_dir = os.path.join(tmp_dir, f"vm-state-{self.name}")
|
||||
if not args["keepVmState"]:
|
||||
self.cleanup_statedir()
|
||||
os.makedirs(self.state_dir, mode=0o700, exist_ok=True)
|
||||
self.shared_dir = create_dir("shared-xchg")
|
||||
|
||||
self.booted = False
|
||||
@ -235,7 +238,6 @@ class Machine:
|
||||
self.pid: Optional[int] = None
|
||||
self.socket = None
|
||||
self.monitor: Optional[socket.socket] = None
|
||||
self.logger: Logger = args["log"]
|
||||
self.allow_reboot = args.get("allowReboot", False)
|
||||
|
||||
@staticmethod
|
||||
@ -780,9 +782,10 @@ class Machine:
|
||||
self.log("QEMU running (pid {})".format(self.pid))
|
||||
|
||||
def cleanup_statedir(self) -> None:
|
||||
self.log("delete the VM state directory")
|
||||
if os.path.isfile(self.state_dir):
|
||||
if os.path.isdir(self.state_dir):
|
||||
shutil.rmtree(self.state_dir)
|
||||
self.logger.log(f"deleting VM state directory {self.state_dir}")
|
||||
self.logger.log("if you want to keep the VM state, pass --keep-vm-state")
|
||||
|
||||
def shutdown(self) -> None:
|
||||
if not self.booted:
|
||||
@ -940,10 +943,10 @@ if __name__ == "__main__":
|
||||
for nr, vde_socket, _, _ in vde_sockets:
|
||||
os.environ["QEMU_VDE_SOCKET_{}".format(nr)] = vde_socket
|
||||
|
||||
machines = [create_machine({"startCommand": s}) for s in vm_scripts]
|
||||
for machine in machines:
|
||||
if not cli_args.keep_vm_state:
|
||||
machine.cleanup_statedir()
|
||||
machines = [
|
||||
create_machine({"startCommand": s, "keepVmState": cli_args.keep_vm_state})
|
||||
for s in vm_scripts
|
||||
]
|
||||
machine_eval = [
|
||||
"{0} = machines[{1}]".format(m.name, idx) for idx, m in enumerate(machines)
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user