forked from Fediversity/Fediversity
update test
This commit is contained in:
parent
d8196d54db
commit
6ec6f1677d
1 changed files with 67 additions and 46 deletions
|
@ -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,53 +38,70 @@ in
|
||||||
|
|
||||||
extraTestScript = ''
|
extraTestScript = ''
|
||||||
${lib.concatStringsSep "\n" (
|
${lib.concatStringsSep "\n" (
|
||||||
lib.lists.map (nodeName: ''
|
lib.lists.map (
|
||||||
with subtest("Check the status before deployment"):
|
nodeName:
|
||||||
${nodeName}.fail("${nodeName} 1>&2")
|
let
|
||||||
|
deployment-config = {
|
||||||
with subtest("Run the deployment for ${nodeName}"):
|
inherit (config) enableAcme;
|
||||||
deployer.succeed("""
|
acmeNodeIP = if config.enableAcme then config.nodes.acme.networking.primaryIPAddress else null;
|
||||||
set -euo pipefail
|
host = nodeName;
|
||||||
|
};
|
||||||
# INSTANTIATE
|
inherit
|
||||||
command=(nix-instantiate --expr '
|
((import ./deployment.nix {
|
||||||
import ${pathToRoot}/deployment/nixos.nix {
|
config = deployment-config;
|
||||||
configuration = import ${pathToRoot}/deployment/check/data-model/deployment.nix {
|
}).ssh-host.ssh
|
||||||
config = builtins.fromJSON "${
|
|
||||||
escapedJson {
|
|
||||||
inherit (config) enableAcme;
|
|
||||||
acmeNodeIP = if config.enableAcme then config.nodes.acme.networking.primaryIPAddress else null;
|
|
||||||
}
|
|
||||||
}";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
')
|
|
||||||
# DEPLOY
|
|
||||||
host="root@${nodeName}"
|
|
||||||
sshOpts=(
|
|
||||||
-o StrictHostKeyChecking=no
|
|
||||||
-o "ConnectTimeout=1"
|
|
||||||
-o "ServerAliveInterval=1"
|
|
||||||
)
|
)
|
||||||
# instantiate the config in /nix/store
|
host
|
||||||
"''${command[@]}" -A out_path
|
username
|
||||||
# get the realized derivation to deploy
|
key-file
|
||||||
outPath=$(nix-store --realize "$("''${command[@]}" --eval --strict --json | jq -r '.drv_path')")
|
;
|
||||||
# deploy the config by nix-copy-closure
|
in
|
||||||
NIX_SSHOPTS="''${sshOpts[*]}" nix-copy-closure --to "$host" "$outPath" --gzip --use-substitutes
|
''
|
||||||
# switch the remote host to the config
|
with subtest("Check the status before deployment"):
|
||||||
output=$(ssh "''${sshOpts[@]}" "$host" "nix-env --profile /nix/var/nix/profiles/system --set $outPath; nohup $outPath/bin/switch-to-configuration switch &" 2>&1) || echo "status code: $?"
|
${nodeName}.fail("${nodeName} 1>&2")
|
||||||
echo "output: $output"
|
|
||||||
if [[ $output != *"Timeout, server ${nodeName} not responding"* ]]; then
|
with subtest("Run the deployment for ${nodeName}"):
|
||||||
echo "non-timeout error: $output"
|
deployer.succeed("""
|
||||||
exit 1
|
set -euo pipefail
|
||||||
else
|
|
||||||
exit 0
|
# INSTANTIATE
|
||||||
fi
|
command=(nix-instantiate --show-trace --expr '
|
||||||
""")
|
import ${pathToRoot}/deployment/nixos.nix {
|
||||||
${nodeName}.wait_for_unit("multi-user.target")
|
configuration = (
|
||||||
${nodeName}.succeed("${nodeName} 1>&2")
|
import ${pathToRoot}/deployment/check/data-model/deployment.nix {
|
||||||
'') targetMachines
|
config = builtins.fromJSON "${escapedJson deployment-config}";
|
||||||
|
}
|
||||||
|
).ssh-host.nixos-configuration;
|
||||||
|
}
|
||||||
|
')
|
||||||
|
# DEPLOY
|
||||||
|
host="${lib.defaultTo "root" username}@${host}"
|
||||||
|
sshOpts=(
|
||||||
|
${if key-file == null then "" else "-i ${key-file}"}
|
||||||
|
-o StrictHostKeyChecking=no
|
||||||
|
-o "ConnectTimeout=1"
|
||||||
|
-o "ServerAliveInterval=1"
|
||||||
|
)
|
||||||
|
# instantiate the config in /nix/store
|
||||||
|
"''${command[@]}" --show-trace -A out_path
|
||||||
|
# get the realized derivation to deploy
|
||||||
|
outPath=$(nix-store --realize "$("''${command[@]}" --show-trace --eval --strict --json | jq -r '.drv_path')")
|
||||||
|
# deploy the config by nix-copy-closure
|
||||||
|
NIX_SSHOPTS="''${sshOpts[*]}" nix-copy-closure --to "$host" "$outPath" --gzip --use-substitutes
|
||||||
|
# switch the remote host to the config
|
||||||
|
output=$(ssh "''${sshOpts[@]}" "$host" "nix-env --profile /nix/var/nix/profiles/system --set $outPath; nohup $outPath/bin/switch-to-configuration switch &" 2>&1) || echo "status code: $?"
|
||||||
|
echo "output: $output"
|
||||||
|
if [[ $output != *"Timeout, server ${nodeName} not responding"* ]]; then
|
||||||
|
echo "non-timeout error: $output"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
""")
|
||||||
|
${nodeName}.wait_for_unit("multi-user.target")
|
||||||
|
${nodeName}.succeed("${nodeName} 1>&2")
|
||||||
|
''
|
||||||
|
) targetMachines
|
||||||
)}
|
)}
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue