diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index c577a2d7a000..51aa5ac033c5 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -1033,6 +1033,7 @@ in imports = [ ./ncps.nix ]; defaults.services.ncps.cache.storage.local = "/path/to/ncps"; }; + ncps-storage-s3 = runTest ./ncps-storage-s3.nix; ndppd = runTest ./ndppd.nix; nebula-lighthouse-service = runTest ./nebula-lighthouse-service.nix; nebula.connectivity = runTest ./nebula/connectivity.nix; diff --git a/nixos/tests/ncps-storage-s3.nix b/nixos/tests/ncps-storage-s3.nix new file mode 100644 index 000000000000..890158dd8c4a --- /dev/null +++ b/nixos/tests/ncps-storage-s3.nix @@ -0,0 +1,137 @@ +{ + lib, + pkgs, + ... +}: +let + bucket = "ncps"; + region = "us-west-1"; + accessKey = "test-access-key"; + secretKey = "test-secret-key"; + + initMinio = pkgs.writeShellScriptBin "init-minio.sh" '' + set -euo pipefail + + mc alias set local "http://127.0.0.1:9000" minioadmin minioadmin + mc mb local/${bucket} + mc admin user svcacct add --access-key ${accessKey} --secret-key ${secretKey} local minioadmin + ''; +in +{ + name = "ncps-storage-s3"; + meta = with lib.maintainers; { + maintainers = [ kalbasit ]; + }; + + nodes = { + harmonia = { + services.harmonia = { + enable = true; + signKeyPaths = [ + (pkgs.writeText "cache-key" "cache.example.com-1:9FhO0w+7HjZrhvmzT1VlAZw4OSAlFGTgC24Seg3tmPl4gZBdwZClzTTHr9cVzJpwsRSYLTu7hEAQe3ljy92CWg==") + ]; + settings.priority = 35; + }; + + networking.firewall.allowedTCPPorts = [ 5000 ]; + system.extraDependencies = [ pkgs.emptyFile ]; + }; + + minio = { + services.minio = { + inherit region; + + enable = true; + }; + + networking.firewall.allowedTCPPorts = [ 9000 ]; + environment.systemPackages = [ + pkgs.minio-client + initMinio + ]; + }; + + ncps = { + services.ncps = { + enable = true; + + cache = { + hostName = "ncps"; + + secretKeyPath = builtins.toString ( + pkgs.writeText "ncps-cache-key" "ncps:dcrGsrku0KvltFhrR5lVIMqyloAdo0y8vYZOeIFUSLJS2IToL7dPHSSCk/fi+PJf8EorpBn8PU7MNhfvZoI8mA==" + ); + + storage.s3 = { + inherit bucket region; + + endpoint = "http://minio:9000"; + + accessKeyIdPath = builtins.toFile "minio-access-key" accessKey; + secretAccessKeyPath = builtins.toFile "minio-secret-key" secretKey; + }; + + upstream = { + urls = [ "http://harmonia:5000" ]; + publicKeys = [ + "cache.example.com-1:eIGQXcGQpc00x6/XFcyacLEUmC07u4RAEHt5Y8vdglo=" + ]; + }; + }; + }; + + networking.firewall.allowedTCPPorts = [ 8501 ]; + }; + + client = { + nix.settings = { + substituters = lib.mkForce [ "http://ncps:8501" ]; + trusted-public-keys = lib.mkForce [ + "ncps:UtiE6C+3Tx0kgpP34vjyX/BKK6QZ/D1OzDYX72aCPJg=" + ]; + }; + }; + }; + + testScript = + { nodes, ... }: + let + narinfoName = + (lib.strings.removePrefix "/nix/store/" ( + lib.strings.removeSuffix "-empty-file" pkgs.emptyFile.outPath + )) + + ".narinfo"; + + narinfoNameChars = lib.strings.stringToCharacters narinfoName; + + narinfoPath = lib.concatStringsSep "/" [ + (builtins.head nodes.minio.services.minio.dataDir) + bucket + "store/narinfo" + (lib.lists.elemAt narinfoNameChars 0) + ((lib.lists.elemAt narinfoNameChars 0) + (lib.lists.elemAt narinfoNameChars 1)) + narinfoName + "xl.meta" + ]; + in + '' + minio.start() + + minio.wait_for_unit("minio.service") + + minio.wait_until_succeeds("init-minio.sh") + + start_all() + + harmonia.wait_for_unit("harmonia.service") + + ncps.wait_for_unit("ncps.service") + + client.wait_until_succeeds("curl -f http://ncps:8501/ | grep '\"hostname\":\"${toString nodes.ncps.services.ncps.cache.hostName}\"' >&2") + + client.succeed("cat /etc/nix/nix.conf >&2") + client.succeed("nix-store --realise ${pkgs.emptyFile}") + + minio.succeed("cat ${narinfoPath} >&2") + ''; +}