From 66fe1de8368ba7e754fa6dad798bf351f3c3bf93 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 19 Jan 2018 19:16:57 +0200 Subject: Change: builds are now numbered foo/123, as are logs --- yarns/100-projects.yarn | 15 ++++-- yarns/400-build.yarn | 114 +++++++++++++++++++++++----------------------- yarns/500-build-fail.yarn | 24 +++++----- yarns/900-local.yarn | 6 ++- yarns/lib.py | 6 +++ 5 files changed, 87 insertions(+), 78 deletions(-) (limited to 'yarns') diff --git a/yarns/100-projects.yarn b/yarns/100-projects.yarn index eed83eb..63572e7 100644 --- a/yarns/100-projects.yarn +++ b/yarns/100-projects.yarn @@ -79,7 +79,8 @@ building them. We start by starting an instance of the controller. AND body matches ... { ... "project": "website", - ... "pipelines": ["build"] + ... "pipelines": ["build"], + ... "next_build_id": null ... } AND controller state directory contains project website @@ -99,7 +100,8 @@ Creating a new project with the same name is forbidden. ... "projects": [ ... { ... "project": "website", - ... "pipelines": ["build"] + ... "pipelines": ["build"], + ... "next_build_id": null ... } ... ] ... } @@ -111,7 +113,8 @@ Creating a new project with the same name is forbidden. AND body matches ... { ... "project": "website", - ... "pipelines": ["build"] + ... "pipelines": ["build"], + ... "next_build_id": null ... } WHEN user makes request PUT /projects/website with a valid token @@ -126,7 +129,8 @@ Creating a new project with the same name is forbidden. ... { ... "project": "website", ... "parameters": {"foo": "bar"}, - ... "pipelines": ["build"] + ... "pipelines": ["build"], + ... "next_build_id": null ... } AND controller state directory contains project website @@ -136,7 +140,8 @@ Creating a new project with the same name is forbidden. ... { ... "project": "website", ... "parameters": {"foo": "bar"}, - ... "pipelines": ["build"] + ... "pipelines": ["build"], + ... "next_build_id": null ... } WHEN user makes request DELETE /projects/website diff --git a/yarns/400-build.yarn b/yarns/400-build.yarn index 9ccb7ae..e28bccf 100644 --- a/yarns/400-build.yarn +++ b/yarns/400-build.yarn @@ -115,8 +115,8 @@ the worker to construct a new workspace for the build. THEN result has status code 200 AND body matches ... { - ... "build_id": 1, - ... "log": "/logs/1", + ... "build_id": "rome/1", + ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -132,8 +132,8 @@ the worker to construct a new workspace for the build. THEN result has status code 200 AND body matches ... { - ... "build_id": 1, - ... "log": "/logs/1", + ... "build_id": "rome/1", + ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -160,8 +160,8 @@ User can now see pipeline is running and which worker is building it. ... { ... "worker": "obelix", ... "doing": { - ... "build_id": 1, - ... "log": "/logs/1", + ... "build_id": "rome/1", + ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -180,8 +180,8 @@ User can now see pipeline is running and which worker is building it. ... { ... "builds": [ ... { - ... "build_id": 1, - ... "log": "/logs/1", + ... "build_id": "rome/1", + ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -195,12 +195,12 @@ User can now see pipeline is running and which worker is building it. ... "foo": "bar" ... }, ... "status": "building", - ... "log": "/logs/1" + ... "log": "/logs/rome/1" ... } ... ] ... } - WHEN user makes request GET /logs/1 + WHEN user makes request GET /logs/rome/1 THEN result has status code 200 AND result has header Content-Type: text/plain AND body text is "" @@ -209,7 +209,7 @@ Worker reports workspace creation is done. Note the zero exit code. WHEN worker-manager makes request POST /work with a valid token and body ... { - ... "build_id": 1, + ... "build_id": "rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -226,8 +226,8 @@ Worker requests more work, and gets the first actual build step. THEN result has status code 200 AND body matches ... { - ... "build_id": 1, - ... "log": "/logs/1", + ... "build_id": "rome/1", + ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -244,7 +244,7 @@ hasn't finished yet. WHEN worker-manager makes request POST /work with a valid token and body ... { - ... "build_id": 1, + ... "build_id": "rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -262,8 +262,8 @@ didnt't finish. THEN result has status code 200 AND body matches ... { - ... "build_id": 1, - ... "log": "/logs/1", + ... "build_id": "rome/1", + ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -277,7 +277,7 @@ didnt't finish. The build log is immediately accessible. - WHEN user makes request GET /logs/1 + WHEN user makes request GET /logs/rome/1 THEN result has status code 200 AND result has header Content-Type: text/plain AND body text is "hey ho" @@ -286,7 +286,7 @@ Report the step is done, and successfully. WHEN worker-manager makes request POST /work with a valid token and body ... { - ... "build_id": 1, + ... "build_id": "rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -297,7 +297,7 @@ Report the step is done, and successfully. ... } THEN result has status code 201 - WHEN user makes request GET /logs/1 + WHEN user makes request GET /logs/rome/1 THEN result has status code 200 AND result has header Content-Type: text/plain AND body text is "hey ho, hey ho\n" @@ -310,8 +310,8 @@ The build status now shows the next step as the active one. ... { ... "builds": [ ... { - ... "build_id": 1, - ... "log": "/logs/1", + ... "build_id": "rome/1", + ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -325,7 +325,7 @@ The build status now shows the next step as the active one. ... "foo": "bar" ... }, ... "status": "building", - ... "log": "/logs/1" + ... "log": "/logs/rome/1" ... } ... ] ... } @@ -336,8 +336,8 @@ Now there's another step to do. THEN result has status code 200 AND body matches ... { - ... "build_id": 1, - ... "log": "/logs/1", + ... "build_id": "rome/1", + ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -357,7 +357,7 @@ User sees changed status. ... { ... "worker": "obelix", ... "doing": { - ... "build_id": 1, + ... "build_id": "rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -367,7 +367,7 @@ User sees changed status. ... "step": { ... "shell": "day 2" ... }, - ... "log": "/logs/1" + ... "log": "/logs/rome/1" ... } ... } @@ -375,7 +375,7 @@ Report it done. WHEN worker-manager makes request POST /work with a valid token and body ... { - ... "build_id": 1, + ... "build_id": "rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -407,8 +407,8 @@ no current action. ... { ... "builds": [ ... { - ... "build_id": 1, - ... "log": "/logs/1", + ... "build_id": "rome/1", + ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -421,18 +421,17 @@ no current action. ... "parameters": { ... "foo": "bar" ... }, - ... "status": 0, - ... "log": "/logs/1" + ... "status": 0 ... } ... ] ... } - WHEN user makes request GET /builds/1 + WHEN user makes request GET /builds/rome/1 THEN result has status code 200 AND body matches ... { - ... "build_id": 1, - ... "log": "/logs/1", + ... "build_id": "rome/1", + ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -445,11 +444,10 @@ no current action. ... "parameters": { ... "foo": "bar" ... }, - ... "status": 0, - ... "log": "/logs/1" + ... "status": 0 ... } - WHEN user makes request GET /logs/1 + WHEN user makes request GET /logs/rome/1 THEN result has status code 200 AND result has header Content-Type: text/plain AND body text is "hey ho, hey ho\nto the gold mine we go!\n" @@ -464,8 +462,8 @@ Start build again. This should become build number 2. THEN result has status code 200 AND body matches ... { - ... "build_id": 2, - ... "log": "/logs/2", + ... "build_id": "rome/2", + ... "log": "/logs/rome/2", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -483,8 +481,8 @@ Start build again. This should become build number 2. ... { ... "builds": [ ... { - ... "build_id": 1, - ... "log": "/logs/1", + ... "build_id": "rome/1", + ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -500,8 +498,8 @@ Start build again. This should become build number 2. ... "status": 0 ... }, ... { - ... "build_id": 2, - ... "log": "/logs/2", + ... "build_id": "rome/2", + ... "log": "/logs/rome/2", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -521,7 +519,7 @@ Start build again. This should become build number 2. WHEN worker-manager makes request POST /work with a valid token and body ... { - ... "build_id": 2, + ... "build_id": "rome/2", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -536,8 +534,8 @@ Start build again. This should become build number 2. THEN result has status code 200 AND body matches ... { - ... "build_id": 2, - ... "log": "/logs/2", + ... "build_id": "rome/2", + ... "log": "/logs/rome/2", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -551,7 +549,7 @@ Start build again. This should become build number 2. WHEN worker-manager makes request POST /work with a valid token and body ... { - ... "build_id": 2, + ... "build_id": "rome/2", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -567,7 +565,7 @@ Start build again. This should become build number 2. WHEN worker-manager makes request POST /work with a valid token and body ... { - ... "build_id": 2, + ... "build_id": "rome/2", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -584,8 +582,8 @@ Start build again. This should become build number 2. ... { ... "builds": [ ... { - ... "build_id": 1, - ... "log": "/logs/1", + ... "build_id": "rome/1", + ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -601,8 +599,8 @@ Start build again. This should become build number 2. ... "status": 0 ... }, ... { - ... "build_id": 2, - ... "log": "/logs/2", + ... "build_id": "rome/2", + ... "log": "/logs/rome/2", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -694,7 +692,7 @@ Build the first project. WHEN worker-manager makes request POST /work with a valid token and body ... { - ... "build_id": 1, + ... "build_id": "first/1", ... "worker": "obelix", ... "project": "first", ... "pipeline": "do_something", @@ -713,7 +711,7 @@ Build the first project. WHEN worker-manager makes request POST /work with a valid token and body ... { - ... "build_id": 1, + ... "build_id": "first/1", ... "worker": "obelix", ... "project": "first", ... "pipeline": "do_something", @@ -725,7 +723,7 @@ Build the first project. THEN result has status code 201 WHEN user requests list of builds - THEN the list of builds is [1] + THEN the list of builds is ["first/1"] Build second project. @@ -741,7 +739,7 @@ Build second project. WHEN worker-manager makes request POST /work with a valid token and body ... { - ... "build_id": 2, + ... "build_id": "second/1", ... "worker": "obelix", ... "project": "second", ... "pipeline": "do_something", @@ -760,7 +758,7 @@ Build second project. WHEN worker-manager makes request POST /work with a valid token and body ... { - ... "build_id": 2, + ... "build_id": "second/1", ... "worker": "obelix", ... "project": "second", ... "pipeline": "do_something", @@ -772,7 +770,7 @@ Build second project. THEN result has status code 201 WHEN user requests list of builds - THEN the list of builds is [1, 2] + THEN the list of builds is ["first/1", "second/1"] Finish up. diff --git a/yarns/500-build-fail.yarn b/yarns/500-build-fail.yarn index 64e8333..39a2e32 100644 --- a/yarns/500-build-fail.yarn +++ b/yarns/500-build-fail.yarn @@ -82,8 +82,8 @@ Worker wants work and gets the first step to run. THEN result has status code 200 AND body matches ... { - ... "build_id": 1, - ... "log": "/logs/1", + ... "build_id": "rome/1", + ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -98,7 +98,7 @@ failure. WHEN worker-manager makes request POST /work with a valid token and body ... { - ... "build_id": 1, + ... "build_id": "rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -140,8 +140,8 @@ Also, there's a build with a log. ... { ... "builds": [ ... { - ... "build_id": 1, - ... "log": "/logs/1", + ... "build_id": "rome/1", + ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -152,18 +152,17 @@ Also, there's a build with a log. ... ], ... "current_action": null, ... "parameters": {}, - ... "status": 1, - ... "log": "/logs/1" + ... "status": 1 ... } ... ] ... } - WHEN user makes request GET /builds/1 + WHEN user makes request GET /builds/rome/1 THEN result has status code 200 AND body matches ... { - ... "build_id": 1, - ... "log": "/logs/1", + ... "build_id": "rome/1", + ... "log": "/logs/rome/1", ... "worker": "obelix", ... "project": "rome", ... "pipeline": "construct", @@ -174,11 +173,10 @@ Also, there's a build with a log. ... ], ... "current_action": null, ... "parameters": {}, - ... "status": 1, - ... "log": "/logs/1" + ... "status": 1 ... } - WHEN user makes request GET /logs/1 + WHEN user makes request GET /logs/rome/1 THEN result has status code 200 AND result has header Content-Type: text/plain AND body text is "eek!" diff --git a/yarns/900-local.yarn b/yarns/900-local.yarn index 89652de..5e1b389 100644 --- a/yarns/900-local.yarn +++ b/yarns/900-local.yarn @@ -93,12 +93,14 @@ along with this program. If not, see . IMPLEMENTS THEN controller state directory contains project (\S+) name = get_next_match() - filename = os.path.join(vars['statedir'], 'projects', name + '.yaml') + basename = encode_basename(name) + filename = os.path.join(vars['statedir'], 'projects', basename + '.yaml') assertTrue(os.path.exists(filename)) IMPLEMENTS THEN controller state directory contains worker (\S+) name = get_next_match() - filename = os.path.join(vars['statedir'], 'workers', name + '.yaml') + basename = encode_basename(name) + filename = os.path.join(vars['statedir'], 'workers', basename + '.yaml') assertTrue(os.path.exists(filename)) ## Start and stop blob service diff --git a/yarns/lib.py b/yarns/lib.py index cd95b6e..0914b00 100644 --- a/yarns/lib.py +++ b/yarns/lib.py @@ -13,6 +13,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . + +import base64 import errno import json import os @@ -218,3 +220,7 @@ def list_diff(a, b): if delta: return '\n'.join(delta) return None + + +def encode_basename(basename): + return base64.urlsafe_b64encode(basename.encode()).decode('ascii') -- cgit v1.2.1