Merge pull request #91046 from NinjaTrappeur/nin-delete-vm-state
test-driver.py: delete VM state directory after test run
This commit is contained in:
commit
9e248c9ec9
|
@ -38,7 +38,12 @@ starting VDE switch for network 1
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The machine state is kept across VM restarts in
|
You can re-use the VM states coming from a previous run
|
||||||
<filename>/tmp/vm-state-</filename><varname>machinename</varname>.
|
by setting the <command>--keep-vm-state</command> flag.
|
||||||
|
<screen>
|
||||||
|
<prompt>$ </prompt>./result/bin/nixos-run-vms --keep-vm-state
|
||||||
|
</screen>
|
||||||
|
The machine state is stored in the
|
||||||
|
<filename>$TMPDIR/vm-state-</filename><varname>machinename</varname> directory.
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -675,6 +675,12 @@ systemd.services.nginx.serviceConfig.ReadWritePaths = [ "/var/www" ];
|
||||||
<package>nextcloud18</package> before upgrading to <package>nextcloud19</package>
|
<package>nextcloud18</package> before upgrading to <package>nextcloud19</package>
|
||||||
since Nextcloud doesn't support upgrades across multiple major versions.
|
since Nextcloud doesn't support upgrades across multiple major versions.
|
||||||
</para>
|
</para>
|
||||||
|
<para>
|
||||||
|
The <literal>nixos-run-vms</literal> script now deletes the
|
||||||
|
previous run machines states on test startup. You can use the
|
||||||
|
<literal>--keep-vm-state</literal> flag to match the previous
|
||||||
|
behaviour and keep the same VM state between different test runs.
|
||||||
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</itemizedlist>
|
</itemizedlist>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -4,6 +4,7 @@ from queue import Queue, Empty
|
||||||
from typing import Tuple, Any, Callable, Dict, Iterator, Optional, List
|
from typing import Tuple, Any, Callable, Dict, Iterator, Optional, List
|
||||||
from xml.sax.saxutils import XMLGenerator
|
from xml.sax.saxutils import XMLGenerator
|
||||||
import _thread
|
import _thread
|
||||||
|
import argparse
|
||||||
import atexit
|
import atexit
|
||||||
import base64
|
import base64
|
||||||
import codecs
|
import codecs
|
||||||
|
@ -751,6 +752,11 @@ class Machine:
|
||||||
|
|
||||||
self.log("QEMU running (pid {})".format(self.pid))
|
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):
|
||||||
|
shutil.rmtree(self.state_dir)
|
||||||
|
|
||||||
def shutdown(self) -> None:
|
def shutdown(self) -> None:
|
||||||
if not self.booted:
|
if not self.booted:
|
||||||
return
|
return
|
||||||
|
@ -889,6 +895,15 @@ def subtest(name: str) -> Iterator[None]:
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
arg_parser = argparse.ArgumentParser()
|
||||||
|
arg_parser.add_argument(
|
||||||
|
"-K",
|
||||||
|
"--keep-vm-state",
|
||||||
|
help="re-use a VM state coming from a previous run",
|
||||||
|
action="store_true",
|
||||||
|
)
|
||||||
|
(cli_args, vm_scripts) = arg_parser.parse_known_args()
|
||||||
|
|
||||||
log = Logger()
|
log = Logger()
|
||||||
|
|
||||||
vlan_nrs = list(dict.fromkeys(os.environ.get("VLANS", "").split()))
|
vlan_nrs = list(dict.fromkeys(os.environ.get("VLANS", "").split()))
|
||||||
|
@ -896,8 +911,10 @@ if __name__ == "__main__":
|
||||||
for nr, vde_socket, _, _ in vde_sockets:
|
for nr, vde_socket, _, _ in vde_sockets:
|
||||||
os.environ["QEMU_VDE_SOCKET_{}".format(nr)] = vde_socket
|
os.environ["QEMU_VDE_SOCKET_{}".format(nr)] = vde_socket
|
||||||
|
|
||||||
vm_scripts = sys.argv[1:]
|
|
||||||
machines = [create_machine({"startCommand": s}) for s in vm_scripts]
|
machines = [create_machine({"startCommand": s}) for s in vm_scripts]
|
||||||
|
for machine in machines:
|
||||||
|
if not cli_args.keep_vm_state:
|
||||||
|
machine.cleanup_statedir()
|
||||||
machine_eval = [
|
machine_eval = [
|
||||||
"{0} = machines[{1}]".format(m.name, idx) for idx, m in enumerate(machines)
|
"{0} = machines[{1}]".format(m.name, idx) for idx, m in enumerate(machines)
|
||||||
]
|
]
|
||||||
|
@ -911,7 +928,6 @@ if __name__ == "__main__":
|
||||||
continue
|
continue
|
||||||
log.log("killing {} (pid {})".format(machine.name, machine.pid))
|
log.log("killing {} (pid {})".format(machine.name, machine.pid))
|
||||||
machine.process.kill()
|
machine.process.kill()
|
||||||
|
|
||||||
for _, _, process, _ in vde_sockets:
|
for _, _, process, _ in vde_sockets:
|
||||||
process.terminate()
|
process.terminate()
|
||||||
log.close()
|
log.close()
|
||||||
|
|
Loading…
Reference in a new issue