make output_directory an optional parameter
This commit is contained in:
parent
f9b5f9dba7
commit
7765670c8a
|
@ -33,15 +33,17 @@ class EnvDefault(argparse.Action):
|
|||
setattr(namespace, self.dest, values)
|
||||
|
||||
|
||||
class WriteableDir(argparse.Action): # type: ignore
|
||||
def __call__(self, parser, namespace, values, option_string=None): # type: ignore
|
||||
if not values.is_dir():
|
||||
raise argparse.ArgumentTypeError("{0} is not a directory".format(values))
|
||||
if os.access(values, os.W_OK):
|
||||
setattr(namespace, self.dest, values)
|
||||
else:
|
||||
def raise_if_not_writeable_dir(path: Path) -> None:
|
||||
"""Raises an ArgumentTypeError if the given path isn't a writeable directory
|
||||
Note: We want to fail as early as possible if a directory isn't writeable,
|
||||
since an executed nixos-test could fail (very late) because of the test-driver
|
||||
writing in a directory without proper permissions.
|
||||
"""
|
||||
if not path.is_dir():
|
||||
raise argparse.ArgumentTypeError("{0} is not a directory".format(path))
|
||||
if not os.access(path, os.W_OK):
|
||||
raise argparse.ArgumentTypeError(
|
||||
"{0} is not a writeable directory".format(values)
|
||||
"{0} is not a writeable directory".format(path)
|
||||
)
|
||||
|
||||
|
||||
|
@ -76,10 +78,11 @@ def main() -> None:
|
|||
help="vlans to span by the driver",
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
"output_directory",
|
||||
action=WriteableDir,
|
||||
"-o",
|
||||
"--output_directory",
|
||||
help="""The path to the directory where outputs copied from the VM will be placed.
|
||||
By e.g. Machine.copy_from_vm or Machine.screenshot""",
|
||||
default=Path.cwd(),
|
||||
type=Path,
|
||||
)
|
||||
arg_parser.add_argument(
|
||||
|
@ -92,6 +95,8 @@ def main() -> None:
|
|||
|
||||
args = arg_parser.parse_args()
|
||||
|
||||
raise_if_not_writeable_dir(args.output_directory)
|
||||
|
||||
if not args.keep_vm_state:
|
||||
rootlog.info("Machine state will be reset. To keep it, pass --keep-vm-state")
|
||||
|
||||
|
@ -99,7 +104,7 @@ def main() -> None:
|
|||
args.start_scripts,
|
||||
args.vlans,
|
||||
args.testscript.read_text(),
|
||||
args.output_directory,
|
||||
args.output_directory.resolve(),
|
||||
args.keep_vm_state,
|
||||
) as driver:
|
||||
if args.interactive:
|
||||
|
|
|
@ -48,11 +48,8 @@ class Driver:
|
|||
keep_vm_state=keep_vm_state,
|
||||
name=cmd.machine_name,
|
||||
tmp_dir=tmp_dir,
|
||||
<<<<<<< HEAD
|
||||
callbacks=[self.check_polling_conditions],
|
||||
=======
|
||||
out_dir=self.out_dir,
|
||||
>>>>>>> 68b2e235272 (nixos/test-driver: use an argument instead of the out env-var)
|
||||
)
|
||||
for cmd in cmd(start_scripts)
|
||||
]
|
||||
|
|
|
@ -30,7 +30,7 @@ rec {
|
|||
# effectively mute the XMLLogger
|
||||
export LOGFILE=/dev/null
|
||||
|
||||
${driver}/bin/nixos-test-driver $out
|
||||
${driver}/bin/nixos-test-driver
|
||||
'';
|
||||
|
||||
passthru = driver.passthru // {
|
||||
|
|
Loading…
Reference in a new issue