From 6b1c8bdc98c0c1567225526abf85925f56915959 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 24 Jun 2024 09:43:26 +0200 Subject: [PATCH] nixos-module: Test check that termination signal is sent --- nixos-module.nix | 20 ++++--------------- tests/flake-module.nix | 8 ++++---- .../nixos-virtualization-arion-test/test.nix | 15 +++++++++++--- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/nixos-module.nix b/nixos-module.nix index 58d096d..c4f7beb 100644 --- a/nixos-module.nix +++ b/nixos-module.nix @@ -42,22 +42,10 @@ let cfg.docker.client.package ]; environment.ARION_PREBUILT = config.settings.out.dockerComposeYaml; - serviceConfig.Type = "oneshot"; - serviceConfig.RemainAfterExit = true; - serviceConfig.ExecStart = [ - (lib.getExe (pkgs.writeScriptBin "nixos-arion-start" '' - #!${pkgs.runtimeShell} - echo 1>&2 "starting arion project: $ARION_PREBUILT" - arion --prebuilt-file "$ARION_PREBUILT" up --detach - '')) - ]; - serviceConfig.ExecStop = [ - (lib.getExe (pkgs.writeScriptBin "nixos-arion-stop" '' - #!${pkgs.runtimeShell} - echo 1>&2 "stopping arion project: $ARION_PREBUILT" - arion --prebuilt-file "$ARION_PREBUILT" down - '')) - ]; + script = '' + echo 1>&2 "docker compose file: $ARION_PREBUILT" + arion --prebuilt-file "$ARION_PREBUILT" up + ''; }; }; }; diff --git a/tests/flake-module.nix b/tests/flake-module.nix index 09f1c01..5c11fff 100644 --- a/tests/flake-module.nix +++ b/tests/flake-module.nix @@ -13,10 +13,10 @@ }; # Currently broken; kafka can't reach zookeeper - # nixosModuleWithPodman = - # import ./nixos-virtualization-arion-test/test.nix final { - # virtualisation.arion.backend = "podman-socket"; - # }; + nixosModuleWithPodman = + import ./nixos-virtualization-arion-test/test.nix final { + virtualisation.arion.backend = "podman-socket"; + }; testWithPodman = nixosTest (import ./arion-test { usePodman = true; pkgs = final; }); diff --git a/tests/nixos-virtualization-arion-test/test.nix b/tests/nixos-virtualization-arion-test/test.nix index d7e0d47..212a4b0 100644 --- a/tests/nixos-virtualization-arion-test/test.nix +++ b/tests/nixos-virtualization-arion-test/test.nix @@ -1,6 +1,6 @@ pkgs: module: -pkgs.nixosTest { +pkgs.testers.runNixOSTest ({ lib, ... }:{ name = "test-basic-arion-kafka"; nodes = { machine = { ... }: { @@ -16,10 +16,13 @@ pkgs.nixosTest { }; }; }; - testScript = '' + testScript = { nodes, ... }: '' machine.wait_for_unit("sockets.target") machine.wait_for_unit("arion-whale.service") + ${# TODO: make the kafka service work on podman-socket; some networking issue + lib.optionalString (nodes.machine.virtualisation.arion.backend != "podman-socket") '' + machine.succeed(""" (echo "hello"; echo "world") \ | ${pkgs.apacheKafka}/bin/kafka-console-producer.sh \ @@ -42,6 +45,12 @@ pkgs.nixosTest { journalctl --output json | ${pkgs.jq}/bin/jq 'select(.CONTAINER_NAME=="whale-zookeeper-1") | .MESSAGE' | grep -F 'org.apache.zookeeper' """) + ''} + + machine.wait_until_succeeds(""" + journalctl --grep 'Registering SIGTERM handler' >/dev/null + """) + # explore the shared mounts, as they're undocumented machine.succeed(""" mount >&2 @@ -60,4 +69,4 @@ pkgs.nixosTest { assert os.path.exists(f'{dir}/stop-probe-terminated-cleanly'), f'{dir}/stop-probe-terminated-cleanly does not exist' ''; -} +})