summaryrefslogtreecommitdiff
path: root/ick2
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-04-23 13:27:22 +0300
committerLars Wirzenius <liw@liw.fi>2018-04-23 15:21:39 +0300
commit9d4e01e2df83a108c2c44cc4471666b5cecf4c36 (patch)
tree272049de3e1e30f67aee4ce6304c92e349bccea0 /ick2
parentde851333b5a0c90aa8cb7fb75e188b9e391b582d (diff)
downloadick2-9d4e01e2df83a108c2c44cc4471666b5cecf4c36.tar.gz
Change: all actions must have a "where"
Diffstat (limited to 'ick2')
-rw-r--r--ick2/__init__.py2
-rw-r--r--ick2/pipelineapi.py18
-rw-r--r--ick2/workapi.py1
-rw-r--r--ick2/workapi_tests.py11
-rw-r--r--ick2/workerapi.py24
5 files changed, 27 insertions, 29 deletions
diff --git a/ick2/__init__.py b/ick2/__init__.py
index 8b784c9..8ceb989 100644
--- a/ick2/__init__.py
+++ b/ick2/__init__.py
@@ -42,7 +42,7 @@ from .apibase import APIbase, ResourceApiBase
from .buildsapi import BuildsAPI
from .logapi import LogAPI
from .versionapi import VersionAPI
-from .pipelineapi import PipelineAPI
+from .pipelineapi import (PipelineAPI, NoWhere)
from .projectapi import ProjectAPI
from .workapi import WorkAPI
from .workerapi import WorkerAPI
diff --git a/ick2/pipelineapi.py b/ick2/pipelineapi.py
index 22db2b8..da774d4 100644
--- a/ick2/pipelineapi.py
+++ b/ick2/pipelineapi.py
@@ -23,3 +23,21 @@ class PipelineAPI(ick2.ResourceApiBase):
def get_resource_name(self, resource):
return resource.get('pipeline')
+
+ def create(self, body, **kwargs):
+ resource = self.mangle_new_resource(body)
+
+ actions = resource.get('actions', [])
+ for action in actions:
+ where = action.get('where')
+ if where is None:
+ raise NoWhere(action)
+
+ return super().create(body, **kwargs)
+
+
+class NoWhere(Exception):
+
+ def __init__(self, action):
+ super().__init__(
+ 'Every action MUST specify a "where": {}'.format(action))
diff --git a/ick2/workapi.py b/ick2/workapi.py
index fa9c2bc..1f8c827 100644
--- a/ick2/workapi.py
+++ b/ick2/workapi.py
@@ -106,6 +106,7 @@ class WorkAPI(ick2.APIbase):
parameters = project.get('parameters', {})
create_workspace = {
'action': 'create_workspace',
+ 'where': 'host',
}
actions = [create_workspace] + self._get_actions(project)
build = {
diff --git a/ick2/workapi_tests.py b/ick2/workapi_tests.py
index 92d34e5..d2d9df6 100644
--- a/ick2/workapi_tests.py
+++ b/ick2/workapi_tests.py
@@ -37,8 +37,8 @@ class WorkAPITests(unittest.TestCase):
pipeline = {
'pipeline': 'build',
'actions': [
- {'shell': 'step-1'},
- {'shell': 'step-2'},
+ {'shell': 'step-1', 'where': 'host'},
+ {'shell': 'step-2', 'where': 'host'},
],
}
@@ -88,6 +88,7 @@ class WorkAPITests(unittest.TestCase):
},
'step': {
'action': 'create_workspace',
+ 'where': 'host',
},
'log': '/logs/foo/1',
}
@@ -113,6 +114,7 @@ class WorkAPITests(unittest.TestCase):
},
'step': {
'action': 'create_workspace',
+ 'where': 'host',
},
'log': '/logs/foo/1',
}
@@ -139,7 +141,7 @@ class WorkAPITests(unittest.TestCase):
work.update_work(done)
# We should get the next step now.
- expected['step'] = {'shell': 'step-1'}
+ expected['step'] = {'shell': 'step-1', 'where': 'host'}
self.assertEqual(work.get_work('asterix'), expected)
# Finish the step.
@@ -147,7 +149,7 @@ class WorkAPITests(unittest.TestCase):
work.update_work(done)
# We should get the next step now.
- expected['step'] = {'shell': 'step-2'}
+ expected['step'] = {'shell': 'step-2', 'where': 'host'}
self.assertEqual(work.get_work('asterix'), expected)
# Finish the step.
@@ -179,6 +181,7 @@ class WorkAPITests(unittest.TestCase):
},
'step': {
'action': 'create_workspace',
+ 'where': 'host',
},
'log': '/logs/foo/1',
}
diff --git a/ick2/workerapi.py b/ick2/workerapi.py
index 2e53758..7f2f0b7 100644
--- a/ick2/workerapi.py
+++ b/ick2/workerapi.py
@@ -21,30 +21,6 @@ class WorkerAPI(ick2.ResourceApiBase): # pragma: no cover
def __init__(self, state):
super().__init__('workers', state)
- def get_routes(self, path):
- return [
- {
- 'method': 'POST',
- 'path': path,
- 'callback': self.POST(self.create),
- },
- {
- 'method': 'GET',
- 'path': path,
- 'callback': self.GET(self.list),
- },
- {
- 'method': 'GET',
- 'path': '{}/<name>'.format(path),
- 'callback': self.GET(self.show),
- },
- {
- 'method': 'DELETE',
- 'path': '{}/<name>'.format(path),
- 'callback': self.DELETE(self.delete),
- },
- ]
-
def get_resource_name(self, resource):
return resource['worker']