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`

+23 -30
+8 -15
nixos/modules/services/continuous-integration/gocd-agent/default.nix
··· 57 57 }; 58 58 59 59 goServer = mkOption { 60 - default = "127.0.0.1"; 60 + default = "https://127.0.0.1:8154/go"; 61 61 type = types.str; 62 62 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. 72 64 ''; 73 65 }; 74 66 ··· 112 104 113 105 extraOptions = mkOption { 114 106 default = [ ]; 115 - example = [ 116 - "-X debug" 107 + example = [ 108 + "-X debug" 117 109 "-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5006" 118 110 "-verbose:gc" 119 111 "-Xloggc:go-agent-gc.log" ··· 170 162 config.environment.sessionVariables; 171 163 in 172 164 selectedSessionVars // 173 - { 165 + { 174 166 NIX_REMOTE = "daemon"; 175 167 AGENT_WORK_DIR = cfg.workDir; 176 168 AGENT_STARTUP_ARGS = ''${concatStringsSep " " cfg.startupOptions}''; ··· 199 191 ${pkgs.jre}/bin/java ${concatStringsSep " " cfg.startupOptions} \ 200 192 ${concatStringsSep " " cfg.extraOptions} \ 201 193 -jar ${pkgs.gocd-agent}/go-agent/agent-bootstrapper.jar \ 202 - ${cfg.goServer} \ 203 - ${toString cfg.goServerPort} 194 + -serverUrl ${cfg.goServer} 204 195 ''; 205 196 206 197 serviceConfig = { 207 198 User = cfg.user; 208 199 WorkingDirectory = cfg.workDir; 200 + RestartSec = 30; 201 + Restart = "on-failure"; 209 202 }; 210 203 }; 211 204 };
+15 -15
nixos/tests/gocd-agent.nix
··· 6 6 7 7 let 8 8 serverUrl = "localhost:8153/go/api/agents"; 9 - header = "Accept: application/vnd./go.cd/v2+json"; 9 + header = "Accept: application/vnd.go.cd.v2+json"; 10 10 in 11 11 12 12 import ./make-test.nix ({ pkgs, ...} : { ··· 15 15 maintainers = [ grahamc swarren83 ]; 16 16 }; 17 17 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; 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 + }; 28 29 }; 29 - }; 30 - }; 30 + }; 31 31 32 32 testScript = '' 33 33 startAll; 34 34 $gocd_agent->waitForUnit("gocd-server"); 35 35 $gocd_agent->waitForOpenPort("8153"); 36 36 $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"); 39 39 ''; 40 40 })