summary refs log tree commit diff
path: root/nixos/lib
diff options
context:
space:
mode:
authorMarijan Petričević <marijan.petricevic94@gmail.com>2022-01-25 10:21:33 +0100
committerMarijan Petričević <marijan.petricevic94@gmail.com>2022-01-25 10:21:33 +0100
commite17fcbc9663040c932fd49664dc7b8cbd3b5894c (patch)
treeb888ff649f0381bcaf9f5a29bb45c34099d0362c /nixos/lib
parent7765670c8a80695ae1b7c4e4d3ec6389ba533f1f (diff)
downloadnixpkgs-e17fcbc9663040c932fd49664dc7b8cbd3b5894c.tar
nixpkgs-e17fcbc9663040c932fd49664dc7b8cbd3b5894c.tar.gz
nixpkgs-e17fcbc9663040c932fd49664dc7b8cbd3b5894c.tar.bz2
nixpkgs-e17fcbc9663040c932fd49664dc7b8cbd3b5894c.tar.lz
nixpkgs-e17fcbc9663040c932fd49664dc7b8cbd3b5894c.tar.xz
nixpkgs-e17fcbc9663040c932fd49664dc7b8cbd3b5894c.tar.zst
nixpkgs-e17fcbc9663040c932fd49664dc7b8cbd3b5894c.zip
introduce writeable_dir argparse type
Diffstat (limited to 'nixos/lib')
-rwxr-xr-xnixos/lib/test-driver/test_driver/__init__.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/nixos/lib/test-driver/test_driver/__init__.py b/nixos/lib/test-driver/test_driver/__init__.py
index 3ee140894a7..498a4f56c55 100755
--- a/nixos/lib/test-driver/test_driver/__init__.py
+++ b/nixos/lib/test-driver/test_driver/__init__.py
@@ -33,18 +33,20 @@ class EnvDefault(argparse.Action):
         setattr(namespace, self.dest, values)
 
 
-def raise_if_not_writeable_dir(path: Path) -> None:
-    """Raises an ArgumentTypeError if the given path isn't a writeable directory
+def writeable_dir(arg: str) -> Path:
+    """Raises an ArgumentTypeError if the given argument 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.
     """
+    path = Path(arg)
     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(path)
         )
+    return path
 
 
 def main() -> None:
@@ -83,7 +85,7 @@ def main() -> None:
         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,
+        type=writeable_dir,
     )
     arg_parser.add_argument(
         "testscript",
@@ -95,8 +97,6 @@ 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")