Skip to content

Commit 0dc6c2f

Browse files
authored
Merge pull request #6177 from IntersectMBO/jl/ci-binary-test
Checkpoint and peerSnap artifact files with CI binary artifact test
2 parents d0dcd9b + cbe8aa6 commit 0dc6c2f

File tree

5 files changed

+121
-16
lines changed

5 files changed

+121
-16
lines changed

cardano-node/cardano-node.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cabal-version: 3.0
22

33
name: cardano-node
4-
version: 10.3.0
4+
version: 10.3.1
55
synopsis: The cardano full node
66
description: The cardano full node.
77
category: Cardano,

flake.nix

+5-2
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 =

nix/binary-release.nix

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ let
3232
AlonzoGenesisFile = "alonzo-genesis.json";
3333
} // lib.optionalAttrs (env.nodeConfig ? ConwayGenesisFile) {
3434
ConwayGenesisFile = "conway-genesis.json";
35+
} // lib.optionalAttrs (env.nodeConfig ? CheckpointsFile) {
36+
CheckpointsFile = "checkpoints.json";
3537
};
3638
nodeConfig = pkgs.writeText
3739
"config.json"
@@ -43,6 +45,10 @@ let
4345
(builtins.toJSON
4446
(env.nodeConfigBp // genesisAttrs));
4547

48+
peerSnapshot = pkgs.writeText
49+
"peer-snapshot.json"
50+
(builtins.toJSON env.peerSnapshot);
51+
4652
topologyConfig = pkgs.cardanoLib.mkTopology env;
4753

4854
# Genesis files are the same for env.nodeConfig and env.nodeConfigBp
@@ -54,6 +60,7 @@ let
5460
mkdir -p "share/${name}"
5561
jq . < "${nodeConfig}" > share/${name}/config.json
5662
jq . < "${nodeConfigBp}" > share/${name}/config-bp.json
63+
jq . < "${peerSnapshot}" > share/${name}/peer-snapshot.json
5764
jq . < "${topologyConfig}" > share/${name}/topology.json
5865
cp -n --remove-destination -v \
5966
"${ByronGenesisFile}" \
@@ -69,6 +76,11 @@ let
6976
"${env.nodeConfig.ConwayGenesisFile}" \
7077
share/${name}/conway-genesis.json
7178
''}
79+
${lib.optionalString (env.nodeConfig ? CheckpointsFile) ''
80+
cp -n --remove-destination -v \
81+
"${env.nodeConfig.CheckpointsFile}" \
82+
share/${name}/checkpoints.json
83+
''}
7284
'';
7385

7486
in pkgs.runCommand name {
+80
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

+23-13
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)