update test

This commit is contained in:
Kiara Grouwstra 2025-08-25 19:45:04 +02:00
parent d8196d54db
commit 6ec6f1677d
Signed by: kiara
SSH key fingerprint: SHA256:COspvLoLJ5WC5rFb9ZDe5urVCkK4LJZOsjfF4duRJFU

View file

@ -9,6 +9,10 @@ let
in in
{ {
_class = "nixosTest"; _class = "nixosTest";
imports = [
./options.nix
];
name = "deployment-model"; name = "deployment-model";
sourceFileset = lib.fileset.unions [ sourceFileset = lib.fileset.unions [
../../data-model.nix ../../data-model.nix
@ -34,7 +38,25 @@ in
extraTestScript = '' extraTestScript = ''
${lib.concatStringsSep "\n" ( ${lib.concatStringsSep "\n" (
lib.lists.map (nodeName: '' lib.lists.map (
nodeName:
let
deployment-config = {
inherit (config) enableAcme;
acmeNodeIP = if config.enableAcme then config.nodes.acme.networking.primaryIPAddress else null;
host = nodeName;
};
inherit
((import ./deployment.nix {
config = deployment-config;
}).ssh-host.ssh
)
host
username
key-file
;
in
''
with subtest("Check the status before deployment"): with subtest("Check the status before deployment"):
${nodeName}.fail("${nodeName} 1>&2") ${nodeName}.fail("${nodeName} 1>&2")
@ -43,29 +65,27 @@ in
set -euo pipefail set -euo pipefail
# INSTANTIATE # INSTANTIATE
command=(nix-instantiate --expr ' command=(nix-instantiate --show-trace --expr '
import ${pathToRoot}/deployment/nixos.nix { import ${pathToRoot}/deployment/nixos.nix {
configuration = import ${pathToRoot}/deployment/check/data-model/deployment.nix { configuration = (
config = builtins.fromJSON "${ import ${pathToRoot}/deployment/check/data-model/deployment.nix {
escapedJson { config = builtins.fromJSON "${escapedJson deployment-config}";
inherit (config) enableAcme;
acmeNodeIP = if config.enableAcme then config.nodes.acme.networking.primaryIPAddress else null;
} }
}"; ).ssh-host.nixos-configuration;
};
} }
') ')
# DEPLOY # DEPLOY
host="root@${nodeName}" host="${lib.defaultTo "root" username}@${host}"
sshOpts=( sshOpts=(
${if key-file == null then "" else "-i ${key-file}"}
-o StrictHostKeyChecking=no -o StrictHostKeyChecking=no
-o "ConnectTimeout=1" -o "ConnectTimeout=1"
-o "ServerAliveInterval=1" -o "ServerAliveInterval=1"
) )
# instantiate the config in /nix/store # instantiate the config in /nix/store
"''${command[@]}" -A out_path "''${command[@]}" --show-trace -A out_path
# get the realized derivation to deploy # get the realized derivation to deploy
outPath=$(nix-store --realize "$("''${command[@]}" --eval --strict --json | jq -r '.drv_path')") outPath=$(nix-store --realize "$("''${command[@]}" --show-trace --eval --strict --json | jq -r '.drv_path')")
# deploy the config by nix-copy-closure # deploy the config by nix-copy-closure
NIX_SSHOPTS="''${sshOpts[*]}" nix-copy-closure --to "$host" "$outPath" --gzip --use-substitutes NIX_SSHOPTS="''${sshOpts[*]}" nix-copy-closure --to "$host" "$outPath" --gzip --use-substitutes
# switch the remote host to the config # switch the remote host to the config
@ -80,7 +100,8 @@ in
""") """)
${nodeName}.wait_for_unit("multi-user.target") ${nodeName}.wait_for_unit("multi-user.target")
${nodeName}.succeed("${nodeName} 1>&2") ${nodeName}.succeed("${nodeName} 1>&2")
'') targetMachines ''
) targetMachines
)} )}
''; '';
} }