nixos/test-driver: deprecate --keep-vm-state in favour of --keep-machine-state
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import warnings
|
||||
from pathlib import Path
|
||||
|
||||
import ptpython.ipython
|
||||
@@ -55,9 +57,15 @@ def writeable_dir(arg: str) -> Path:
|
||||
def main() -> None:
|
||||
arg_parser = argparse.ArgumentParser(prog="nixos-test-driver")
|
||||
arg_parser.add_argument(
|
||||
"-K",
|
||||
"--keep-vm-state",
|
||||
help="re-use a VM state coming from a previous run",
|
||||
help=argparse.SUPPRESS,
|
||||
dest="keep_machine_state",
|
||||
action="store_true",
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"-K",
|
||||
"--keep-machine-state",
|
||||
help="re-use a machine state coming from a previous run",
|
||||
action="store_true",
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
@@ -146,6 +154,12 @@ def main() -> None:
|
||||
|
||||
args = arg_parser.parse_args()
|
||||
|
||||
if "--keep-vm-state" in sys.argv:
|
||||
warnings.warn(
|
||||
"The flag '--keep-vm-state' is deprecated. Use '--keep-machine-state' instead.",
|
||||
DeprecationWarning,
|
||||
)
|
||||
|
||||
output_directory = args.output_directory.resolve()
|
||||
logger = CompositeLogger([TerminalLogger()])
|
||||
|
||||
@@ -155,8 +169,10 @@ def main() -> None:
|
||||
if args.junit_xml:
|
||||
logger.add_logger(JunitXMLLogger(output_directory / args.junit_xml))
|
||||
|
||||
if not args.keep_vm_state:
|
||||
logger.info("Machine state will be reset. To keep it, pass --keep-vm-state")
|
||||
if not args.keep_machine_state:
|
||||
logger.info(
|
||||
"Machine state will be reset. To keep it, pass --keep-machine-state"
|
||||
)
|
||||
|
||||
debugger: DebugAbstract = DebugNop()
|
||||
if args.debug_hook_attach is not None:
|
||||
@@ -180,7 +196,7 @@ def main() -> None:
|
||||
tests=args.testscript.read_text(),
|
||||
out_dir=output_directory,
|
||||
logger=logger,
|
||||
keep_vm_state=args.keep_vm_state,
|
||||
keep_machine_state=args.keep_machine_state,
|
||||
global_timeout=args.global_timeout,
|
||||
debug=debugger,
|
||||
) as driver:
|
||||
|
||||
@@ -87,7 +87,7 @@ class Driver:
|
||||
tests: str,
|
||||
out_dir: Path,
|
||||
logger: AbstractLogger,
|
||||
keep_vm_state: bool = False,
|
||||
keep_machine_state: bool = False,
|
||||
global_timeout: int = 24 * 60 * 60 * 7,
|
||||
debug: DebugAbstract = DebugNop(),
|
||||
):
|
||||
@@ -110,7 +110,7 @@ class Driver:
|
||||
QemuMachine(
|
||||
name=name,
|
||||
start_command=vm_start_script,
|
||||
keep_vm_state=keep_vm_state,
|
||||
keep_machine_state=keep_machine_state,
|
||||
tmp_dir=tmp_dir,
|
||||
callbacks=[self.check_polling_conditions],
|
||||
out_dir=self.out_dir,
|
||||
@@ -130,7 +130,7 @@ class Driver:
|
||||
start_command=container_start_script,
|
||||
tmp_dir=tmp_dir,
|
||||
logger=self.logger,
|
||||
keep_vm_state=keep_vm_state,
|
||||
keep_machine_state=keep_machine_state,
|
||||
callbacks=[self.check_polling_conditions],
|
||||
out_dir=self.out_dir,
|
||||
)
|
||||
@@ -360,7 +360,7 @@ class Driver:
|
||||
start_command: str,
|
||||
*,
|
||||
name: str | None = None,
|
||||
keep_vm_state: bool = False,
|
||||
keep_machine_state: bool = False,
|
||||
) -> BaseMachine:
|
||||
"""
|
||||
Create a `QemuMachine`. This currently only supports qemu "nodes", not containers.
|
||||
@@ -372,7 +372,7 @@ class Driver:
|
||||
out_dir=self.out_dir,
|
||||
start_command=start_command,
|
||||
name=name,
|
||||
keep_vm_state=keep_vm_state,
|
||||
keep_machine_state=keep_machine_state,
|
||||
logger=self.logger,
|
||||
)
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import sys
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
import warnings
|
||||
from abc import ABC, abstractmethod
|
||||
from collections.abc import Callable, Generator
|
||||
from contextlib import _GeneratorContextManager, contextmanager, nullcontext
|
||||
@@ -220,7 +221,7 @@ class BaseMachine(ABC):
|
||||
name: str
|
||||
callbacks: list[Callable]
|
||||
tmp_dir: Path
|
||||
keep_vm_state: bool
|
||||
keep_machine_state: bool
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<{self.__class__.__name__} '{self.name}'>"
|
||||
@@ -232,7 +233,7 @@ class BaseMachine(ABC):
|
||||
logger: AbstractLogger,
|
||||
tmp_dir: Path,
|
||||
callbacks: list[Callable] | None,
|
||||
keep_vm_state: bool,
|
||||
keep_machine_state: bool,
|
||||
) -> None:
|
||||
self.out_dir = out_dir
|
||||
self.name = name
|
||||
@@ -240,12 +241,10 @@ class BaseMachine(ABC):
|
||||
self.callbacks = callbacks if callbacks is not None else []
|
||||
self.tmp_dir = tmp_dir
|
||||
|
||||
# Note: "vm" is a bit of a misnomer here as we support both QEMU vms and nspawn containers.
|
||||
# Consider renaming to something more generic ("machine"?)
|
||||
self.keep_vm_state = keep_vm_state
|
||||
self.keep_machine_state = keep_machine_state
|
||||
|
||||
self.state_dir = self.tmp_dir / f"vm-state-{self.name}"
|
||||
if (not self.keep_vm_state) and self.state_dir.exists():
|
||||
if (not self.keep_machine_state) and self.state_dir.exists():
|
||||
self.cleanup_statedir()
|
||||
self.state_dir.mkdir(mode=0o700, exist_ok=True)
|
||||
|
||||
@@ -617,8 +616,10 @@ class BaseMachine(ABC):
|
||||
|
||||
def cleanup_statedir(self) -> None:
|
||||
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")
|
||||
self.logger.log(f"deleting machine state directory {self.state_dir}")
|
||||
self.logger.log(
|
||||
"if you want to keep the machine state, pass --keep-machine-state"
|
||||
)
|
||||
|
||||
def copy_from_vm(self, source: str, target_dir: str = "") -> None:
|
||||
"""Copy a file from the VM (specified by an in-VM source path) to a path
|
||||
@@ -725,7 +726,7 @@ class QemuMachine(BaseMachine):
|
||||
start_command: str,
|
||||
logger: AbstractLogger,
|
||||
name: str | None = None,
|
||||
keep_vm_state: bool = False,
|
||||
keep_machine_state: bool = False,
|
||||
callbacks: list[Callable] | None = None,
|
||||
) -> None:
|
||||
self.start_command = QemuStartCommand(start_command)
|
||||
@@ -735,7 +736,7 @@ class QemuMachine(BaseMachine):
|
||||
logger=logger,
|
||||
callbacks=callbacks,
|
||||
tmp_dir=tmp_dir,
|
||||
keep_vm_state=keep_vm_state,
|
||||
keep_machine_state=keep_machine_state,
|
||||
)
|
||||
|
||||
self.full_console_log = []
|
||||
@@ -1399,7 +1400,7 @@ class NspawnMachine(BaseMachine):
|
||||
tmp_dir: Path,
|
||||
logger: AbstractLogger,
|
||||
callbacks: list[Callable] | None = None,
|
||||
keep_vm_state: bool = False,
|
||||
keep_machine_state: bool = False,
|
||||
):
|
||||
# TODO: don't compute `name` from `start_command` path, instead thread it down explicitly.
|
||||
# See analogous TODO in `QemuStartCommand::machine_name`.
|
||||
@@ -1409,7 +1410,7 @@ class NspawnMachine(BaseMachine):
|
||||
logger=logger,
|
||||
callbacks=callbacks,
|
||||
tmp_dir=tmp_dir,
|
||||
keep_vm_state=keep_vm_state,
|
||||
keep_machine_state=keep_machine_state,
|
||||
)
|
||||
|
||||
self.start_command = start_command
|
||||
|
||||
@@ -34,7 +34,8 @@ class CreateMachineProtocol(Protocol):
|
||||
start_command: str | dict,
|
||||
*,
|
||||
name: Optional[str] = None,
|
||||
keep_vm_state: bool = False,
|
||||
keep_machine_state: bool = False,
|
||||
**kwargs: Any, # to allow usage of deprecated keep_vm_state
|
||||
) -> BaseMachine:
|
||||
raise Exception("This is just type information for the Nix test driver")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user