From cf8aa48605d68997be93f69ce853d76449ff68cc Mon Sep 17 00:00:00 2001 From: Luflosi Date: Sun, 8 Oct 2023 18:56:05 +0200 Subject: [PATCH] nixos/tests/kubo: various improvements Add new test to check if kubo.passthru.repoVersion is set correctly. Also split the existing NixOS VM test into two independent parts. The test already used two independent VMs but just one testScript. This made experimenting with just one of the two VMs slower than it needed to be. It should also increase parallelism slightly since both test scripts can now run at the same time. --- nixos/tests/all-tests.nix | 2 +- nixos/tests/kubo/default.nix | 5 +++ nixos/tests/kubo/kubo-fuse.nix | 42 +++++++++++++++++++ nixos/tests/{ => kubo}/kubo.nix | 32 -------------- pkgs/applications/networking/kubo/default.nix | 6 ++- .../networking/kubo/test-repoVersion.nix | 13 ++++++ 6 files changed, 66 insertions(+), 34 deletions(-) create mode 100644 nixos/tests/kubo/default.nix create mode 100644 nixos/tests/kubo/kubo-fuse.nix rename nixos/tests/{ => kubo}/kubo.nix (60%) create mode 100644 pkgs/applications/networking/kubo/test-repoVersion.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 3f19ed548121..443364f06e85 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -424,7 +424,7 @@ in { ksm = handleTest ./ksm.nix {}; kthxbye = handleTest ./kthxbye.nix {}; kubernetes = handleTestOn ["x86_64-linux"] ./kubernetes {}; - kubo = runTest ./kubo.nix; + kubo = import ./kubo { inherit recurseIntoAttrs runTest; }; ladybird = handleTest ./ladybird.nix {}; languagetool = handleTest ./languagetool.nix {}; latestKernel.login = handleTest ./login.nix { latestKernel = true; }; diff --git a/nixos/tests/kubo/default.nix b/nixos/tests/kubo/default.nix new file mode 100644 index 000000000000..629922fc366d --- /dev/null +++ b/nixos/tests/kubo/default.nix @@ -0,0 +1,5 @@ +{ recurseIntoAttrs, runTest }: +recurseIntoAttrs { + kubo = runTest ./kubo.nix; + kubo-fuse = runTest ./kubo-fuse.nix; +} diff --git a/nixos/tests/kubo/kubo-fuse.nix b/nixos/tests/kubo/kubo-fuse.nix new file mode 100644 index 000000000000..71a5bf61649f --- /dev/null +++ b/nixos/tests/kubo/kubo-fuse.nix @@ -0,0 +1,42 @@ +{ lib, ...} : { + name = "kubo-fuse"; + meta = with lib.maintainers; { + maintainers = [ mguentner Luflosi ]; + }; + + nodes.machine = { config, ... }: { + services.kubo = { + enable = true; + autoMount = true; + }; + users.users.alice = { + isNormalUser = true; + extraGroups = [ config.services.kubo.group ]; + }; + users.users.bob = { + isNormalUser = true; + }; + }; + + testScript = '' + start_all() + + with subtest("FUSE mountpoint"): + machine.fail("echo a | su bob -l -c 'ipfs add --quieter'") + # The FUSE mount functionality is broken as of v0.13.0 and v0.17.0. + # See https://github.com/ipfs/kubo/issues/9044. + # Workaround: using CID Version 1 avoids that. + ipfs_hash = machine.succeed( + "echo fnord3 | su alice -l -c 'ipfs add --quieter --cid-version=1'" + ).strip() + + machine.succeed(f"cat /ipfs/{ipfs_hash} | grep fnord3") + + with subtest("Unmounting of /ipns and /ipfs"): + # Force Kubo to crash and wait for it to restart + machine.systemctl("kill --signal=SIGKILL ipfs.service") + machine.wait_for_unit("ipfs.service", timeout = 30) + + machine.succeed(f"cat /ipfs/{ipfs_hash} | grep fnord3") + ''; +} diff --git a/nixos/tests/kubo.nix b/nixos/tests/kubo/kubo.nix similarity index 60% rename from nixos/tests/kubo.nix rename to nixos/tests/kubo/kubo.nix index 496f409a40a9..7965ad277385 100644 --- a/nixos/tests/kubo.nix +++ b/nixos/tests/kubo/kubo.nix @@ -18,20 +18,6 @@ }; }; - nodes.fuse = { config, ... }: { - services.kubo = { - enable = true; - autoMount = true; - }; - users.users.alice = { - isNormalUser = true; - extraGroups = [ config.services.kubo.group ]; - }; - users.users.bob = { - isNormalUser = true; - }; - }; - testScript = '' start_all() @@ -63,23 +49,5 @@ with subtest("Setting dataDir works properly with the hardened systemd unit"): machine.succeed("test -e /mnt/ipfs/config") machine.succeed("test ! -e /var/lib/ipfs/") - - with subtest("FUSE mountpoint"): - fuse.fail("echo a | su bob -l -c 'ipfs add --quieter'") - # The FUSE mount functionality is broken as of v0.13.0 and v0.17.0. - # See https://github.com/ipfs/kubo/issues/9044. - # Workaround: using CID Version 1 avoids that. - ipfs_hash = fuse.succeed( - "echo fnord3 | su alice -l -c 'ipfs add --quieter --cid-version=1'" - ).strip() - - fuse.succeed(f"cat /ipfs/{ipfs_hash} | grep fnord3") - - with subtest("Unmounting of /ipns and /ipfs"): - # Force Kubo to crash and wait for it to restart - fuse.systemctl("kill --signal=SIGKILL ipfs.service") - fuse.wait_for_unit("ipfs.service", timeout = 30) - - fuse.succeed(f"cat /ipfs/{ipfs_hash} | grep fnord3") ''; } diff --git a/pkgs/applications/networking/kubo/default.nix b/pkgs/applications/networking/kubo/default.nix index defb898b4472..8ffeb2e9fcc1 100644 --- a/pkgs/applications/networking/kubo/default.nix +++ b/pkgs/applications/networking/kubo/default.nix @@ -2,6 +2,7 @@ , buildGoModule , fetchurl , nixosTests +, callPackage }: buildGoModule rec { @@ -29,7 +30,10 @@ buildGoModule rec { subPackages = [ "cmd/ipfs" ]; - passthru.tests.kubo = nixosTests.kubo; + passthru.tests = { + inherit (nixosTests) kubo; + repoVersion = callPackage ./test-repoVersion.nix {}; + }; vendorHash = null; diff --git a/pkgs/applications/networking/kubo/test-repoVersion.nix b/pkgs/applications/networking/kubo/test-repoVersion.nix new file mode 100644 index 000000000000..25fd8fcfbf43 --- /dev/null +++ b/pkgs/applications/networking/kubo/test-repoVersion.nix @@ -0,0 +1,13 @@ +{ runCommand, kubo }: + +runCommand "kubo-test-repoVersion" { } '' + export IPFS_PATH="$TMPDIR" + "${kubo}/bin/ipfs" init --empty-repo + declared_repo_version='${kubo.repoVersion}' + actual_repo_version="$(cat "$IPFS_PATH/version")" + if [ "$declared_repo_version" != "$actual_repo_version" ]; then + echo "kubo.repoVersion is not set correctly. It should be $actual_repo_version but is $declared_repo_version." + exit 1 + fi + touch "$out" +''