git.iko.soy/typeable/nixpkgs
on master help sign in
gocd-agent: 16.7.0 startup fixes + test improvements

- Agent now takes a full URL to the Go.CD server - Instruct the agent to attempt restart every 30s upon failure - Test's Accept header did not match the server's expectation - Replace the tests' complex Awk matches with calls to `jq`

commitd969f3fa5110b458bbfe5d12774024a6329a6580 authorGraham Christensen <graham@grahamc.com> dateWed 10 Aug 2016, 15:47 (10 years ago) parent26d2577
2 files changed+23−30
nixos/modules/services/continuous-integration/gocd-agent/default.nix+8−15 nixos/tests/gocd-agent.nix+15−15
nixos/modules/services/continuous-integration/gocd-agent/default.nix+8−15
@@ -57,18 +57,10 @@ in {
5757 };
5858
5959 goServer = mkOption {
60− default = "127.0.0.1";
60+ default = "https://127.0.0.1:8154/go";
6161 type = types.str;
6262 description = ''
63− Address of GoCD Server to attach the Go.CD Agent to.
64− '';
65− };
66−
67− goServerPort = mkOption {
68− default = 8153;
69− type = types.int;
70− description = ''
71− Port that Go.CD Server is Listening on.
63+ URL of the GoCD Server to attach the Go.CD Agent to.
7264 '';
7365 };
7466
@@ -112,8 +104,8 @@ in {
112104
113105 extraOptions = mkOption {
114106 default = [ ];
115− example = [
116− "-X debug"
107+ example = [
108+ "-X debug"
117109 "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5006"
118110 "-verbose:gc"
119111 "-Xloggc:go-agent-gc.log"
@@ -170,7 +162,7 @@ in {
170162 config.environment.sessionVariables;
171163 in
172164 selectedSessionVars //
173− {
165+ {
174166 NIX_REMOTE = "daemon";
175167 AGENT_WORK_DIR = cfg.workDir;
176168 AGENT_STARTUP_ARGS = ''${concatStringsSep " " cfg.startupOptions}'';
@@ -199,13 +191,14 @@ in {
199191 ${pkgs.jre}/bin/java ${concatStringsSep " " cfg.startupOptions} \
200192 ${concatStringsSep " " cfg.extraOptions} \
201193 -jar ${pkgs.gocd-agent}/go-agent/agent-bootstrapper.jar \
202− ${cfg.goServer} \
203− ${toString cfg.goServerPort}
194+ -serverUrl ${cfg.goServer}
204195 '';
205196
206197 serviceConfig = {
207198 User = cfg.user;
208199 WorkingDirectory = cfg.workDir;
200+ RestartSec = 30;
201+ Restart = "on-failure";
209202 };
210203 };
211204 };
nixos/tests/gocd-agent.nix+15−15
@@ -6,7 +6,7 @@
66
77let
88 serverUrl = "localhost:8153/go/api/agents";
9− header = "Accept: application/vnd./go.cd/v2+json";
9+ header = "Accept: application/vnd.go.cd.v2+json";
1010in
1111
1212import ./make-test.nix ({ pkgs, ...} : {
@@ -15,26 +15,26 @@ import ./make-test.nix ({ pkgs, ...} : {
1515 maintainers = [ grahamc swarren83 ];
1616 };
1717
18−nodes = {
19− gocd_agent =
20− { config, pkgs, ... }:
21− {
22− virtualisation.memorySize = 2048;
23− services.gocd-agent = {
24− enable = true;
18+ nodes = {
19+ gocd_agent =
20+ { config, pkgs, ... }:
21+ {
22+ virtualisation.memorySize = 2048;
23+ services.gocd-agent = {
24+ enable = true;
25+ };
26+ services.gocd-server = {
27+ enable = true;
28+ };
2529 };
26− services.gocd-server = {
27− enable = true;
28− };
29− };
30−};
30+ };
3131
3232 testScript = ''
3333 startAll;
3434 $gocd_agent->waitForUnit("gocd-server");
3535 $gocd_agent->waitForOpenPort("8153");
3636 $gocd_agent->waitForUnit("gocd-agent");
37− $gocd_agent->waitUntilSucceeds("curl -s -f ${serverUrl} -H '${header}' | awk -F \" '/\"uuid\":\s\"[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}/ {print $4}'");
38− $gocd_agent->waitUntilSucceeds("curl -s -f ${serverUrl} -H '${header}' | awk -F \" '/\"agent_state\":\s\"Idle\"/'");
37+ $gocd_agent->waitUntilSucceeds("curl ${serverUrl} -H '${header}' | ${pkgs.jq}/bin/jq -e ._embedded.agents[0].uuid");
38+ $gocd_agent->succeed("curl ${serverUrl} -H '${header}' | ${pkgs.jq}/bin/jq -e ._embedded.agents[0].agent_state | grep -q Idle");
3939 '';
4040})