From 5173ddc34c3d644f1e05482a678eea12042319c4 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 27 Oct 2017 17:52:38 +0300 Subject: Add: first draft of yarn scenario for building a project --- yarns/400-build.yarn | 241 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 yarns/400-build.yarn (limited to 'yarns/400-build.yarn') diff --git a/yarns/400-build.yarn b/yarns/400-build.yarn new file mode 100644 index 0000000..0e030fd --- /dev/null +++ b/yarns/400-build.yarn @@ -0,0 +1,241 @@ + + +# Build a project + +This scenario tests the controller API to simulate a build. + + SCENARIO build a project + +Set up the controller. + + GIVEN an RSA key pair for token signing + AND controller config uses statedir at the state directory + AND a running ick controller + +Add up a project. + + GIVEN an access token for user with scopes + ... uapi_projects_post + ... uapi_projects_id_pipeline_id_put + ... uapi_projects_id_pipeline_id_get + ... uapi_projects_id_builds_get + WHEN user makes request POST /projects + ... { + ... "project": "rome", + ... "pipelines": [ + ... { + ... "name": "construct", + ... "actions": [ + ... { "shell": "day 1" }, + ... { "shell": "day 2" } + ... ] + ... } + ... ] + ... } + THEN result has status code 201 + +There are no builds for the project yet, and is idle. + + WHEN user makes request GET /projects/rome/pipelines/construct + THEN result has status code 200 + AND body matches { "status": "idle" } + + WHEN user makes request GET /projects/rome/builds + THEN result has status code 200 + AND body matches { "project": "rome", "builds": []} + +Register a worker. + + GIVEN an access token for worker-manager with scopes + ... uapi_workers_post + WHEN worker-manager makes request POST /workers + ... { + ... "worker": "obelix", + ... } + THEN result has status code 201 + +Trigger build. First with an invalid status, then a real one. + + WHEN user makes request PUT /projects/rome/pipelines/construct + ... { "status": "VANDALS!" } + THEN result has status code 400 + + WHEN user makes request PUT /projects/rome/pipelines/construct + ... { "status": "triggered" } + THEN result has status code 200 + +Worker wants work and gets the first step to run. If the worker asks +again, it gets the same answer. **FIXME: should the name of the worker +be in the path or can we get it in the access token?** + + WHEN worker-manager makes request GET /work/obelix + THEN result has status code 200 + AND body matches + ... { + ... "project": "rome", + ... "pipeline": "construct", + ... "step": { + ... "shell": "day 1" + ... } + ... } + + WHEN worker-manager makes request GET /work/obelix + THEN result has status code 200 + AND body matches + ... { + ... "project": "rome", + ... "pipeline": "construct", + ... "step": { + ... "shell": "day 1" + ... } + ... } + +User can now see pipeline is running and which worker is building it. + + WHEN user makes request GET /projects/rome/pipelines/construct + THEN result has status code 200 + AND body matches + ... { + ... "status": "running", + ... "worker": "obelix", + ... "step_number": 1, + ... "step": { + ... "shell": "day 1" + ... } + ... } + +Worker reports some build output. Note the null exit code. + + WHEN worker-manager makes request POST /work + ... { + ... "worker": "obelix", + ... "project": "rome", + ... "pipeline": "construct", + ... "exít_code": null, + ... "stdout": "hey ho hey ho", + ... "stderr": "", + ... "timestamp": "2017-10-27T17:08:49" + ... } + THEN result has status code 200 + AND body matches { "result": "waiting for more" } + +Still the same job, since the first build step didnt't finish. + + WHEN worker-manager makes request GET /work/obelix + THEN result has status code 200 + AND body matches + ... { + ... "project": "rome", + ... "pipeline": "construct", + ... "step": { + ... "shell": "day 1" + ... } + ... } + +Report the step is done, and successfully. + + WHEN worker-manager makes request POST /work + ... { + ... "worker": "obelix", + ... "project": "rome", + ... "pipeline": "construct", + ... "exít_code": 0, + ... "stdout": "hey ho, hey ho\n", + ... "stderr": "", + ... "timestamp": "2017-10-27T17:08:49" + ... } + THEN result has status code 200 + AND body matches { "result": "next step awaits you" } + +Now there's another step to do. + + WHEN worker-manager makes request GET /work/obelix + THEN result has status code 200 + AND body matches + ... { + ... "project": "rome", + ... "pipeline": "construct", + ... "step": { + ... "shell": "day 2" + ... } + ... } + +User sees changed status. + + WHEN user makes request GET /projects/rome/pipelines/construct + THEN result has status code 200 + AND body matches + ... { + ... "status": "running", + ... "worker": "obelix", + ... "step_number": 2, + ... "step": { + ... "shell": "day 2" + ... } + ... } + +Report it done. + + WHEN worker-manager makes request POST /work + ... { + ... "worker": "obelix", + ... "project": "rome", + ... "pipeline": "construct", + ... "exít_code": 0, + ... "stdout": "to the gold mine we go!\n", + ... "stderr": "", + ... "timestamp": "2017-10-27T17:08:49" + ... } + THEN result has status code 200 + AND body matches { "result": "no more steps" } + +Now there's no more work to do. + + WHEN worker-manager makes request GET /work/obelix + THEN result has status code 200 + AND body matches {} + +The pipeline status indicates success. + + WHEN user makes request GET /projects/rome/pipelines/construct + THEN result has status code 200 + AND body matches { "status": "idle" } + +Also, there's a build with a log. + + WHEN user makes request GET /projects/rome/builds + THEN result has status code 200 + AND body matches + ... { + ... "project": "rome", + ... "builds": [ + ... { + ... "pipeline": "construct", + ... "build_number": 1, + ... "status": "success", + ... "log": "/projects/rome/logs/1" + ... } + ... ] + ... } + + WHEN user makes request GET /projects/rome/logs/1 + THEN result has status code 200 + AND result has header Content-Type: text/plain + AND body matches "hey ho, hey ho\nto the gold mine we go!\n" -- cgit v1.2.1