From 83fb8f661eb574f32fad1d51bbebd0c36595db01 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 25 Aug 2022 15:08:26 +0200 Subject: add zfs support/test/example --- tests/zfs.nix | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/zfs.nix (limited to 'tests/zfs.nix') diff --git a/tests/zfs.nix b/tests/zfs.nix new file mode 100644 index 0000000..bc807bc --- /dev/null +++ b/tests/zfs.nix @@ -0,0 +1,40 @@ +{ makeTest ? import +, pkgs ? (import {}) +}: +let + makeTest' = args: + makeTest args { + inherit pkgs; + inherit (pkgs) system; + }; + disko-config = import ../example/zfs.nix; + tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config); + tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. {}).mount disko-config); +in makeTest' { + name = "disko"; + + nodes.machine = + { config, pkgs, modulesPath, ... }: + + { + imports = [ + (modulesPath + "/profiles/installation-device.nix") + (modulesPath + "/profiles/base.nix") + ]; + + # speed-up eval + documentation.enable = false; + + virtualisation.emptyDiskImages = [ 512 512 ]; + }; + + testScript = '' + machine.succeed("echo 'secret' > /tmp/secret.key"); + machine.succeed("${tsp-create}"); + machine.succeed("${tsp-mount}"); + machine.succeed("${tsp-mount}"); # verify that the command is idempotent + machine.succeed("test -b /dev/zvol/zroot/zfs_testvolume"); + machine.succeed("grep -qs '/mnt/ext4onzfs' /proc/mounts"); + ''; +} + -- cgit v1.2.3 From 1ac0e76b15a3b13c83d25a78b32dee4070a584b7 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 25 Aug 2022 23:12:49 +0200 Subject: tests: add lib, autoimport tests --- tests/zfs.nix | 38 ++++---------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) (limited to 'tests/zfs.nix') diff --git a/tests/zfs.nix b/tests/zfs.nix index bc807bc..3c8216c 100644 --- a/tests/zfs.nix +++ b/tests/zfs.nix @@ -1,40 +1,10 @@ -{ makeTest ? import -, pkgs ? (import {}) +{ pkgs ? (import {}) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix {}).makeDiskoTest }: -let - makeTest' = args: - makeTest args { - inherit pkgs; - inherit (pkgs) system; - }; +makeDiskoTest { disko-config = import ../example/zfs.nix; - tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. {}).create disko-config); - tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. {}).mount disko-config); -in makeTest' { - name = "disko"; - - nodes.machine = - { config, pkgs, modulesPath, ... }: - - { - imports = [ - (modulesPath + "/profiles/installation-device.nix") - (modulesPath + "/profiles/base.nix") - ]; - - # speed-up eval - documentation.enable = false; - - virtualisation.emptyDiskImages = [ 512 512 ]; - }; - - testScript = '' - machine.succeed("echo 'secret' > /tmp/secret.key"); - machine.succeed("${tsp-create}"); - machine.succeed("${tsp-mount}"); - machine.succeed("${tsp-mount}"); # verify that the command is idempotent + extraTestScript = '' machine.succeed("test -b /dev/zvol/zroot/zfs_testvolume"); machine.succeed("grep -qs '/mnt/ext4onzfs' /proc/mounts"); ''; } - -- cgit v1.2.3 From 69f1337980756fe4ac001cadce7760e7b06c75da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 26 Aug 2022 08:41:58 +0200 Subject: fix inconsistent indentation with nixpkgs-fmt --- tests/zfs.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/zfs.nix') diff --git a/tests/zfs.nix b/tests/zfs.nix index 3c8216c..9e5e746 100644 --- a/tests/zfs.nix +++ b/tests/zfs.nix @@ -1,5 +1,5 @@ -{ pkgs ? (import {}) -, makeDiskoTest ? (pkgs.callPackage ./lib.nix {}).makeDiskoTest +{ pkgs ? (import { }) +, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest }: makeDiskoTest { disko-config = import ../example/zfs.nix; -- cgit v1.2.3 From 05a90d4227dd14ab08fa3982f320ec771e5626db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 26 Aug 2022 08:49:46 +0200 Subject: tests: use mountpoint program to check for mountpoints --- tests/zfs.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/zfs.nix') diff --git a/tests/zfs.nix b/tests/zfs.nix index 9e5e746..e0c8fab 100644 --- a/tests/zfs.nix +++ b/tests/zfs.nix @@ -5,6 +5,6 @@ makeDiskoTest { disko-config = import ../example/zfs.nix; extraTestScript = '' machine.succeed("test -b /dev/zvol/zroot/zfs_testvolume"); - machine.succeed("grep -qs '/mnt/ext4onzfs' /proc/mounts"); + machine.succeed("mountpoint /mnt/ext4onzfs"); ''; } -- cgit v1.2.3 From 57b7c5506a64e169370f291bffa75d2888027ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 26 Aug 2022 09:07:24 +0200 Subject: also test zfs filesystem options --- tests/zfs.nix | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests/zfs.nix') diff --git a/tests/zfs.nix b/tests/zfs.nix index e0c8fab..ebc6b04 100644 --- a/tests/zfs.nix +++ b/tests/zfs.nix @@ -5,6 +5,23 @@ makeDiskoTest { disko-config = import ../example/zfs.nix; extraTestScript = '' machine.succeed("test -b /dev/zvol/zroot/zfs_testvolume"); + + def assert_property(ds, property, expected_value): + out = machine.succeed(f"zfs get -H {property} {ds} -o value").rstrip() + assert ( + out == expected_value + ), f"Expected {property}={expected_value} on {ds}, got: {out}" + + assert_property("zroot", "compression", "lz4") + assert_property("zroot/zfs_fs", "compression", "lz4") + assert_property("zroot", "com.sun:auto-snapshot", "false") + assert_property("zroot/zfs_fs", "com.sun:auto-snapshot", "true") + assert_property("zroot/zfs_testvolume", "volsize", "10M") + + # FIXME: we cannot mount rootfs yet + #machine.succeed("mountpoint /mnt"); + machine.succeed("mountpoint /mnt/zfs_fs"); + machine.succeed("mountpoint /mnt/zfs_legacy_fs"); machine.succeed("mountpoint /mnt/ext4onzfs"); ''; } -- cgit v1.2.3 From 722dde361ca51864fd9b3b6b9a78875e436fbc24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 26 Aug 2022 10:28:07 +0200 Subject: zfs: support for root dataset mountpoint and mountpoint=none --- tests/zfs.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/zfs.nix') diff --git a/tests/zfs.nix b/tests/zfs.nix index ebc6b04..5940c4d 100644 --- a/tests/zfs.nix +++ b/tests/zfs.nix @@ -17,9 +17,9 @@ makeDiskoTest { assert_property("zroot", "com.sun:auto-snapshot", "false") assert_property("zroot/zfs_fs", "com.sun:auto-snapshot", "true") assert_property("zroot/zfs_testvolume", "volsize", "10M") + assert_property("zroot/zfs_unmounted_fs", "mountpoint", "none") - # FIXME: we cannot mount rootfs yet - #machine.succeed("mountpoint /mnt"); + machine.succeed("mountpoint /mnt"); machine.succeed("mountpoint /mnt/zfs_fs"); machine.succeed("mountpoint /mnt/zfs_legacy_fs"); machine.succeed("mountpoint /mnt/ext4onzfs"); -- cgit v1.2.3