summaryrefslogtreecommitdiff
path: root/yarns
diff options
context:
space:
mode:
authorLars Wirzenius <liw@exolobe1>2018-05-13 15:30:23 +0300
committerLars Wirzenius <liw@liw.fi>2018-05-17 21:44:59 +0300
commitb11d31ef23c5dfee6bfa54afbec47fc8b8bab7b1 (patch)
tree2e6b085f8fb023d53c8ac20a97aef2c7d1c11d4b /yarns
parent531dd2c50bfdfcf50bb37f57cf9fc2b69787adcf (diff)
downloadick2-b11d31ef23c5dfee6bfa54afbec47fc8b8bab7b1.tar.gz
Change: how controller stores persistent data
Replace old State class with new FilePersistentState and TransactionalState classes. Use new Resource class instead of raw dicts. Use context managers for creating, updating resources, to avoid mistakes from accidentally not saving changes. Overall persistence should now be rather simpler. This should open up a possibility for changing the controller to insert more actions into the build graph, to trigger notifcations via the workers.
Diffstat (limited to 'yarns')
-rw-r--r--yarns/400-build.yarn49
-rw-r--r--yarns/500-build-fail.yarn11
-rw-r--r--yarns/600-unauthz.yarn9
-rw-r--r--yarns/900-implements.yarn7
-rw-r--r--yarns/900-local.yarn6
-rw-r--r--yarns/lib.py3
6 files changed, 22 insertions, 63 deletions
diff --git a/yarns/400-build.yarn b/yarns/400-build.yarn
index c167ac2..4b3c085 100644
--- a/yarns/400-build.yarn
+++ b/yarns/400-build.yarn
@@ -74,11 +74,7 @@ Add a second project so we know each project gets its own work steps.
... }
THEN result has status code 201
-There are no builds for the project yet, and is idle.
-
- WHEN user makes request GET /projects/rome/status
- THEN result has status code 200
- AND body matches { "status": "idle" }
+There are no builds yet.
WHEN user makes request GET /builds
THEN result has status code 200
@@ -95,14 +91,9 @@ Register a worker.
... }
THEN result has status code 201
-Trigger build. First with an invalid status, then a real one.
-
- WHEN user makes request PUT /projects/rome/status
- ... with a valid token and body { "status": "VANDALS!" }
- THEN result has status code 400
+Trigger build.
- WHEN user makes request PUT /projects/rome/status
- ... with a valid token and body { "status": "triggered" }
+ WHEN user makes request GET /projects/rome/+trigger
THEN result has status code 200
Worker wants work and gets the first step to run. If the worker asks
@@ -150,13 +141,6 @@ the worker to construct a new workspace for the build.
User can now see pipeline is running and which worker is building it.
- WHEN user makes request GET /projects/rome/status
- THEN result has status code 200
- AND body matches
- ... {
- ... "status": "building"
- ... }
-
WHEN user makes request GET /workers/obelix
THEN result has status code 200
AND body matches
@@ -396,14 +380,8 @@ Now there's no more work to do.
THEN result has status code 200
AND body matches {}
-The pipeline status indicates success.
-
- WHEN user makes request GET /projects/rome/status
- THEN result has status code 200
- AND body matches { "status": "idle" }
-
-Also, there's a build with a log. Also, the build status shows there's
-no current action.
+There's a build with a log. Also, the build status shows there's no
+current action.
WHEN user makes request GET /builds
THEN result has status code 200
@@ -458,8 +436,7 @@ no current action.
Start build again. This should become build number 2.
- WHEN user makes request PUT /projects/rome/status
- ... with a valid token and body { "status": "triggered" }
+ WHEN user makes request GET /projects/rome/+trigger
THEN result has status code 200
WHEN obelix makes request GET /work
@@ -684,8 +661,7 @@ Register a worker.
Build the first project.
- WHEN user makes request PUT /projects/first/status
- ... with a valid token and body { "status": "triggered" }
+ WHEN user makes request GET /projects/first/+trigger
THEN result has status code 200
WHEN obelix makes request GET /work
@@ -733,8 +709,7 @@ Build the first project.
Build second project.
- WHEN user makes request PUT /projects/second/status
- ... with a valid token and body { "status": "triggered" }
+ WHEN user makes request GET /projects/second/+trigger
THEN result has status code 200
WHEN obelix makes request GET /work
@@ -854,12 +829,11 @@ Register a couple of workers.
Trigger both projects.
- WHEN user makes request PUT /projects/first/status
- ... with a valid token and body { "status": "triggered" }
+ WHEN user makes request GET /projects/first/+trigger
THEN result has status code 200
WHEN user requests list of builds
- THEN the list of builds is []
+ THEN the list of builds is ["first/1"]
WHEN asterix makes request GET /work
THEN result is step
@@ -871,8 +845,7 @@ Trigger both projects.
WHEN user requests list of builds
THEN the list of builds is ["first/1"]
- WHEN user makes request PUT /projects/second/status
- ... with a valid token and body { "status": "triggered" }
+ WHEN user makes request GET /projects/second/+trigger
THEN result has status code 200
WHEN obelix makes request GET /work
diff --git a/yarns/500-build-fail.yarn b/yarns/500-build-fail.yarn
index 79d4be6..59a2e67 100644
--- a/yarns/500-build-fail.yarn
+++ b/yarns/500-build-fail.yarn
@@ -73,8 +73,7 @@ Register a worker.
Trigger build.
- WHEN user makes request PUT /projects/rome/status
- ... with a valid token and body { "status": "triggered" }
+ WHEN user makes request GET /projects/rome/+trigger
THEN result has status code 200
Worker wants work and gets the first step to run.
@@ -127,13 +126,7 @@ User sees changed status.
... "doing": {}
... }
-The pipeline status indicates it's idle.
-
- WHEN user makes request GET /projects/rome/status
- THEN result has status code 200
- AND body matches { "status": "idle" }
-
-Also, there's a build with a log.
+There's a build with a log.
WHEN user makes request GET /builds
THEN result has status code 200
diff --git a/yarns/600-unauthz.yarn b/yarns/600-unauthz.yarn
index 55cac30..c656f0e 100644
--- a/yarns/600-unauthz.yarn
+++ b/yarns/600-unauthz.yarn
@@ -62,11 +62,6 @@ Set up the controller.
... with an invalid token and body {}
THEN result has status code 401
- WHEN outsider makes request
- ... GET /projects/rome/status
- ... with an invalid token
- THEN result has status code 401
-
WHEN outsider makes request GET /builds with an invalid token
THEN result has status code 401
@@ -75,10 +70,6 @@ Set up the controller.
THEN result has status code 401
WHEN outsider makes request
- ... PUT /projects/rome/status with an invalid token
- THEN result has status code 401
-
- WHEN outsider makes request
... GET /work with an invalid token
THEN result has status code 401
diff --git a/yarns/900-implements.yarn b/yarns/900-implements.yarn
index 8a7dff1..4086a2f 100644
--- a/yarns/900-implements.yarn
+++ b/yarns/900-implements.yarn
@@ -161,8 +161,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
IMPLEMENTS THEN the list of builds is (.+)
expected = set(json.loads(get_next_match()))
print('expected', expected)
- body = json.loads(vars['body'])
+ body = json.loads(vars['body'])['builds']
print('body', body)
- actual = set(o['build_id'] for o in body['builds'])
- print('actual', actual)
- assertEqual(actual, expected)
+ builds = set(build['build_id'] for build in body)
+ assertEqual(builds, expected)
diff --git a/yarns/900-local.yarn b/yarns/900-local.yarn
index b8b6695..40bf762 100644
--- a/yarns/900-local.yarn
+++ b/yarns/900-local.yarn
@@ -104,13 +104,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
IMPLEMENTS THEN controller state directory contains project (\S+)
name = get_next_match()
basename = encode_basename(name)
- filename = os.path.join(vars['statedir'], 'projects', basename + '.yaml')
+ filename = os.path.join(vars['statedir'], 'projects', basename)
+ print 'filename', filename
assertTrue(os.path.exists(filename))
IMPLEMENTS THEN controller state directory contains worker (\S+)
name = get_next_match()
basename = encode_basename(name)
- filename = os.path.join(vars['statedir'], 'workers', basename + '.yaml')
+ filename = os.path.join(vars['statedir'], 'workers', basename)
+ print 'filename', filename
assertTrue(os.path.exists(filename))
## Check version result
diff --git a/yarns/lib.py b/yarns/lib.py
index d57e11f..f3ac9d9 100644
--- a/yarns/lib.py
+++ b/yarns/lib.py
@@ -22,6 +22,7 @@ import random
import socket
import sys
import time
+import urllib
import cliapp
import requests
@@ -225,4 +226,4 @@ def list_diff(a, b):
def encode_basename(basename):
- return base64.urlsafe_b64encode(basename.encode()).decode('ascii')
+ return urllib.quote(basename, safe='')