From f4f35c3ae3c504d231250536dc1f1cb16abb0405 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 11 Aug 2024 00:54:36 +0200 Subject: [PATCH] cluster/services/ways: test in simulacrum --- cluster/services/ways/default.nix | 6 ++ .../services/ways/simulacrum/test-data.nix | 11 ++++ cluster/services/ways/simulacrum/test.nix | 55 +++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 cluster/services/ways/simulacrum/test-data.nix create mode 100644 cluster/services/ways/simulacrum/test.nix diff --git a/cluster/services/ways/default.nix b/cluster/services/ways/default.nix index 013d697..67ff6ef 100644 --- a/cluster/services/ways/default.nix +++ b/cluster/services/ways/default.nix @@ -3,11 +3,17 @@ { imports = [ ./options + ./simulacrum/test-data.nix ]; services.ways = { nodes.host = config.services.websites.nodes.host; nixos.host = ./host.nix; + simulacrum = { + enable = true; + deps = [ "nginx" "acme-client" "dns" "certificates" "consul" ]; + settings = ./simulacrum/test.nix; + }; }; dns.records = lib.mapAttrs' diff --git a/cluster/services/ways/simulacrum/test-data.nix b/cluster/services/ways/simulacrum/test-data.nix new file mode 100644 index 0000000..4a6cd15 --- /dev/null +++ b/cluster/services/ways/simulacrum/test-data.nix @@ -0,0 +1,11 @@ +{ config, lib, ... }: +{ + ways = lib.mkIf config.simulacrum { + ways-test-simple = config.lib.forService "ways" { + target = "http://nowhere"; + }; + ways-test-consul = config.lib.forService "ways" { + consulService = "ways-test-service"; + }; + }; +} diff --git a/cluster/services/ways/simulacrum/test.nix b/cluster/services/ways/simulacrum/test.nix new file mode 100644 index 0000000..e2b3b8e --- /dev/null +++ b/cluster/services/ways/simulacrum/test.nix @@ -0,0 +1,55 @@ +{ cluster, config, lib, ... }: + +let + inherit (cluster._module.specialArgs.depot.lib.meta) domain; +in + +{ + nodes = lib.mkMerge [ + { + nowhere = { pkgs, ... }: { + networking.firewall.allowedTCPPorts = [ 8080 ]; + systemd.services.ways-simple-service = let + webroot = pkgs.writeTextDir "example.txt" "hello world"; + in { + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + ExecStart = "${pkgs.darkhttpd}/bin/darkhttpd ${webroot} --port 8080"; + DynamicUser = true; + }; + }; + }; + } + (lib.genAttrs cluster.config.services.ways.nodes.host (lib.const { + services.nginx.upstreams.nowhere.servers = { + "${(builtins.head config.nodes.nowhere.networking.interfaces.eth1.ipv4.addresses).address}:8080" = {}; + }; + consul.services.ways-test-service = { + unit = "consul"; + mode = "external"; + definition = { + name = "ways-test-service"; + address = (builtins.head config.nodes.nowhere.networking.interfaces.eth1.ipv4.addresses).address; + port = 8080; + }; + }; + })) + ]; + + testScript = '' + import json + nodeNames = json.loads('${builtins.toJSON cluster.config.services.ways.nodes.host}') + nodes = [ n for n in machines if n.name in nodeNames ] + + start_all() + nowhere.wait_for_unit("multi-user.target") + for node in nodes: + node.wait_for_unit("multi-user.target") + + with subtest("single-target service"): + nowhere.succeed("curl -f https://ways-test-simple.${domain}") + + with subtest("consul-managed service"): + nowhere.succeed("curl -f https://ways-test-consul.${domain}") + ''; +}