forked from DGNum/colmena
integration-tests: Allow configuring the presence of nodes
For example, there's no need to spin up any target nodes when we just want to test `colmena apply-local` on the deployer node.
This commit is contained in:
parent
0f8873027f
commit
f849a757d2
3 changed files with 48 additions and 25 deletions
|
@ -1,5 +1,8 @@
|
||||||
let
|
let
|
||||||
tools = import ../tools.nix {};
|
tools = import ../tools.nix {
|
||||||
|
targets = [];
|
||||||
|
prebuiltTarget = "deployer";
|
||||||
|
};
|
||||||
in tools.makeTest {
|
in tools.makeTest {
|
||||||
name = "colmena-apply-local";
|
name = "colmena-apply-local";
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
let
|
let
|
||||||
tools = import ./tools.nix { insideVm = true; };
|
tools = import ./tools.nix {
|
||||||
|
insideVm = true;
|
||||||
|
targets = [];
|
||||||
|
prebuiltTarget = "deployer";
|
||||||
|
};
|
||||||
in {
|
in {
|
||||||
meta = {
|
meta = {
|
||||||
nixpkgs = tools.pkgs;
|
nixpkgs = tools.pkgs;
|
||||||
|
@ -16,8 +20,4 @@ in {
|
||||||
|
|
||||||
environment.etc."deployment".text = "SUCCESS";
|
environment.etc."deployment".text = "SUCCESS";
|
||||||
};
|
};
|
||||||
|
|
||||||
alpha = tools.getStandaloneConfigFor "alpha";
|
|
||||||
beta = tools.getStandaloneConfigFor "beta";
|
|
||||||
gamma = tools.getStandaloneConfigFor "gamma";
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,21 @@
|
||||||
# Adapted from the NixOps test in Nixpkgs.
|
# Adapted from the NixOps test in Nixpkgs.
|
||||||
#
|
#
|
||||||
# We have four nodes: deployer, alpha, beta, gamma.
|
# By default, we have four nodes: deployer, alpha, beta, gamma.
|
||||||
# deployer is where colmena will run.
|
# deployer is where colmena will run.
|
||||||
#
|
#
|
||||||
# `nixos/lib/build-vms.nix` will generate NixOS configurations
|
# `nixos/lib/build-vms.nix` will generate NixOS configurations
|
||||||
# for each node, and we need to include those configurations
|
# for each node, and we need to include those configurations
|
||||||
# in our Colmena setup as well.
|
# in our Colmena setup as well.
|
||||||
|
|
||||||
{ insideVm ? false }:
|
{ insideVm ? false
|
||||||
|
, deployers ? [ "deployer" ] # Nodes configured as deployers (with Colmena and pre-built system closure)
|
||||||
|
, targets ? [ "alpha" "beta" "gamma" ] # Nodes configured as targets (minimal config)
|
||||||
|
, prebuiltTarget ? "alpha" # Target node to prebuild system closure for, or null
|
||||||
|
}:
|
||||||
|
|
||||||
|
with builtins;
|
||||||
|
|
||||||
|
assert elem "deployer" deployers;
|
||||||
|
|
||||||
let
|
let
|
||||||
lock = builtins.fromJSON (builtins.readFile ../flake.lock);
|
lock = builtins.fromJSON (builtins.readFile ../flake.lock);
|
||||||
|
@ -16,6 +24,7 @@ let
|
||||||
sha256 = lock.nodes.nixpkgs.locked.narHash;
|
sha256 = lock.nodes.nixpkgs.locked.narHash;
|
||||||
};
|
};
|
||||||
pkgs = import pinned {};
|
pkgs = import pinned {};
|
||||||
|
inherit (pkgs) lib;
|
||||||
|
|
||||||
colmena =
|
colmena =
|
||||||
if !insideVm then import ../default.nix { inherit pkgs; }
|
if !insideVm then import ../default.nix { inherit pkgs; }
|
||||||
|
@ -29,7 +38,12 @@ let
|
||||||
|
|
||||||
# Common setup
|
# Common setup
|
||||||
nodes = let
|
nodes = let
|
||||||
deployer = { lib, config, ... }: {
|
# Setup for deployer nodes
|
||||||
|
#
|
||||||
|
# We include the input closure of a prebuilt system profile
|
||||||
|
# so it can build system profiles for the targets without
|
||||||
|
# network access.
|
||||||
|
deployerConfig = { lib, config, ... }: {
|
||||||
nix.nixPath = [
|
nix.nixPath = [
|
||||||
"nixpkgs=${pkgs.path}"
|
"nixpkgs=${pkgs.path}"
|
||||||
];
|
];
|
||||||
|
@ -41,8 +55,9 @@ let
|
||||||
writableStore = true;
|
writableStore = true;
|
||||||
additionalPaths = [
|
additionalPaths = [
|
||||||
"${pkgs.path}"
|
"${pkgs.path}"
|
||||||
prebuiltNode
|
] ++ lib.optionals (prebuiltTarget != null) [
|
||||||
(inputClosureOf prebuiltNode)
|
prebuiltSystem
|
||||||
|
(inputClosureOf prebuiltSystem)
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -54,7 +69,11 @@ let
|
||||||
'')
|
'')
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
target = { lib, ... }: {
|
|
||||||
|
# Setup for target nodes
|
||||||
|
#
|
||||||
|
# Kept as minimal as possible.
|
||||||
|
targetConfig = { lib, ... }: {
|
||||||
nix.binaryCaches = lib.mkForce [];
|
nix.binaryCaches = lib.mkForce [];
|
||||||
|
|
||||||
services.openssh.enable = true;
|
services.openssh.enable = true;
|
||||||
|
@ -63,16 +82,14 @@ let
|
||||||
];
|
];
|
||||||
virtualisation.writableStore = true;
|
virtualisation.writableStore = true;
|
||||||
};
|
};
|
||||||
in {
|
|
||||||
inherit deployer;
|
|
||||||
alpha = target;
|
|
||||||
beta = target;
|
|
||||||
gamma = target;
|
|
||||||
};
|
|
||||||
|
|
||||||
prebuiltNode = let
|
deployerNodes = map (name: lib.nameValuePair name deployerConfig) deployers;
|
||||||
|
targetNodes = map (name: lib.nameValuePair name targetConfig) targets;
|
||||||
|
in listToAttrs (deployerNodes ++ targetNodes);
|
||||||
|
|
||||||
|
prebuiltSystem = let
|
||||||
all = buildVms.buildVirtualNetwork nodes;
|
all = buildVms.buildVirtualNetwork nodes;
|
||||||
in all.alpha.config.system.build.toplevel;
|
in all.${prebuiltTarget}.config.system.build.toplevel;
|
||||||
|
|
||||||
# Utilities
|
# Utilities
|
||||||
getStandaloneConfigFor = node: let
|
getStandaloneConfigFor = node: let
|
||||||
|
@ -109,17 +126,20 @@ let
|
||||||
'';
|
'';
|
||||||
|
|
||||||
makeTest = test: let
|
makeTest = test: let
|
||||||
|
targetList = "[${concatStringsSep ", " targets}]";
|
||||||
|
|
||||||
fullScript = ''
|
fullScript = ''
|
||||||
start_all()
|
start_all()
|
||||||
|
'' + lib.optionalString (prebuiltTarget != null) ''
|
||||||
deployer.succeed("nix-store -qR ${prebuiltNode}")
|
deployer.succeed("nix-store -qR ${prebuiltSystem}")
|
||||||
|
'' + ''
|
||||||
deployer.succeed("nix-store -qR ${pkgs.path}")
|
deployer.succeed("nix-store -qR ${pkgs.path}")
|
||||||
deployer.succeed("ln -sf ${pkgs.path} /nixpkgs")
|
deployer.succeed("ln -sf ${pkgs.path} /nixpkgs")
|
||||||
deployer.succeed("mkdir -p /root/.ssh && touch /root/.ssh/id_rsa && chmod 600 /root/.ssh/id_rsa && cat ${sshKeys.snakeOilPrivateKey} > /root/.ssh/id_rsa")
|
deployer.succeed("mkdir -p /root/.ssh && touch /root/.ssh/id_rsa && chmod 600 /root/.ssh/id_rsa && cat ${sshKeys.snakeOilPrivateKey} > /root/.ssh/id_rsa")
|
||||||
|
|
||||||
for node in [alpha, beta, gamma]:
|
for node in ${targetList}:
|
||||||
node.wait_for_unit("sshd.service")
|
node.wait_for_unit("sshd.service")
|
||||||
deployer.succeed("ssh -o StrictHostKeyChecking=accept-new alpha ls")
|
deployer.succeed(f"ssh -o StrictHostKeyChecking=accept-new {node.name} true")
|
||||||
|
|
||||||
deployer.succeed("cp --no-preserve=mode -r ${bundle} /tmp/bundle && chmod u+w /tmp/bundle")
|
deployer.succeed("cp --no-preserve=mode -r ${bundle} /tmp/bundle && chmod u+w /tmp/bundle")
|
||||||
|
|
||||||
|
@ -151,6 +171,6 @@ let
|
||||||
};
|
};
|
||||||
in pkgs.nixosTest combined;
|
in pkgs.nixosTest combined;
|
||||||
in {
|
in {
|
||||||
inherit pkgs nodes colmena colmenaExec prebuiltNode
|
inherit pkgs nodes colmena colmenaExec
|
||||||
getStandaloneConfigFor inputClosureOf makeTest;
|
getStandaloneConfigFor inputClosureOf makeTest;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue