Skip to content

Commit cbe8aa6

Browse files
committed
ci: cardano-node artifact test using nixosTests
1 parent cf906d2 commit cbe8aa6

File tree

3 files changed

+108
-15
lines changed

3 files changed

+108
-15
lines changed

flake.nix

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,12 @@
166166
profiled = project.profiled.shell;
167167
};
168168

169-
# NixOS tests run a node and submit-api and validate it listens
169+
# NixOS tests a sandboxed mainnet edge node with submit-api, ensuring
170+
# startup and port listening functionality using the nixos service. It
171+
# also tests Linux binary artifact start up with each set of pre-bundled
172+
# environment configuration files.
170173
nixosTests = import ./nix/nixos/tests {
171-
inherit pkgs;
174+
inherit pkgs ciJobs;
172175
};
173176

174177
checks =
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
{
2+
pkgs,
3+
cardano-node-linux,
4+
...
5+
}: let
6+
inherit (builtins) attrNames fromJSON readFile toString;
7+
inherit (cardanoLib) environments;
8+
inherit (cardanoNodePackages) cardano-cli;
9+
inherit (lib) getAttrs getExe foldl' makeBinPath recursiveUpdate;
10+
inherit (pkgs) cardanoLib cardanoNodePackages gnutar gzip jq lib;
11+
12+
# NixosTest script fns supporting a timeout have a default of 900 seconds.
13+
timeout = toString 30;
14+
15+
environments' = getAttrs ["mainnet" "preprod" "preview"] environments;
16+
envs = attrNames environments';
17+
getMagic = env: toString (fromJSON (readFile environments.${env}.nodeConfig.ShelleyGenesisFile)).networkMagic;
18+
19+
mkSvcTest = env: {
20+
"cardano-node-${env}" = {
21+
serviceConfig = {
22+
WorkingDirectory = "/var/lib/cardano-node-${env}";
23+
StateDirectory = "cardano-node-${env}";
24+
};
25+
26+
preStart = ''
27+
mkdir config
28+
cp -v /opt/cardano-node-linux/share/${env}/* ./
29+
'';
30+
31+
script = ''
32+
/opt/cardano-node-linux/bin/cardano-node run \
33+
--config config.json \
34+
--topology topology.json \
35+
--database-path db \
36+
--socket-path node.socket \
37+
--port 3001
38+
'';
39+
};
40+
};
41+
42+
mkScriptTest = env: ''
43+
machine.systemctl("start cardano-node-${env}")
44+
machine.wait_until_succeeds("[ -S /var/lib/cardano-node-${env}/node.socket ]", timeout=${timeout})
45+
machine.wait_until_succeeds("nc -z localhost 12798", timeout=${timeout})
46+
machine.wait_until_succeeds("nc -z localhost 3001", timeout=${timeout})
47+
out = machine.succeed(
48+
"${getExe cardano-cli} ping -h 127.0.0.1 -c 1 -m ${getMagic env} -q --json | ${getExe jq} -c"
49+
)
50+
print("ping ${env}:", out)
51+
machine.succeed("systemctl status cardano-node-${env}")
52+
machine.succeed("systemctl stop cardano-node-${env}")
53+
machine.wait_until_fails("nc -z localhost 12798", timeout=${timeout})
54+
machine.wait_until_fails("nc -z localhost 3001", timeout=${timeout})
55+
'';
56+
in {
57+
name = "cardano-node-artifact-test";
58+
nodes = {
59+
machine = {config, ...}: {
60+
nixpkgs.pkgs = pkgs;
61+
62+
system.activationScripts.prepTest.text = let
63+
binPath = makeBinPath [gnutar gzip];
64+
in ''
65+
export PATH=${binPath}:$PATH
66+
mkdir -p /opt/cardano-node-linux
67+
cp -v ${cardano-node-linux}/cardano-node-*-linux.tar.gz /opt/cardano-node-linux.tar.gz
68+
tar -zxvf /opt/cardano-node-linux.tar.gz -C /opt/cardano-node-linux
69+
'';
70+
71+
systemd.services = foldl' (acc: env: recursiveUpdate acc (mkSvcTest env)) {} envs;
72+
};
73+
};
74+
75+
testScript =
76+
''
77+
start_all()
78+
''
79+
+ lib.concatMapStringsSep "\n" mkScriptTest envs;
80+
}

nix/nixos/tests/default.nix

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1-
{ pkgs
2-
, supportedSystems ? [ "x86_64-linux" ]
3-
}:
1+
{
2+
pkgs,
3+
ciJobs,
4+
supportedSystems ? ["x86_64-linux"],
5+
}: let
6+
inherit (ciJobs.musl) cardano-node-linux;
7+
inherit (pkgs.lib) genAttrs hydraJob;
48

5-
with pkgs;
6-
with pkgs.commonLib;
7-
8-
let
99
forAllSystems = genAttrs supportedSystems;
10+
1011
importTest = fn: args: system: let
1112
imported = import fn;
1213
test = import (pkgs.path + "/nixos/tests/make-test-python.nix") imported;
13-
in test ({
14-
inherit pkgs system config;
15-
} // args);
14+
in
15+
test ({
16+
inherit pkgs system;
17+
inherit (pkgs.commonLib) config;
18+
}
19+
// args);
20+
21+
# These tests are sandboxed and don't transmit data across the network for
22+
# syncing but can still ensure services start and listen as expected.
1623
callTest = fn: args: forAllSystems (system: hydraJob (importTest fn args system));
17-
in rec {
18-
# only tests that port is open since the test can't access network to actually sync
19-
cardanoNodeEdge = callTest ./cardano-node-edge.nix {};
24+
in {
25+
# Tests the linux release binary envs with pre-bundled config.
26+
cardanoNodeArtifact = callTest ./cardano-node-artifact.nix {inherit cardano-node-linux;};
27+
28+
# Tests a mainnet edge node with submit-api using nixos service config.
29+
cardanoNodeEdge = callTest ./cardano-node-edge.nix {};
2030
}

0 commit comments

Comments
 (0)