From 9d4e01e2df83a108c2c44cc4471666b5cecf4c36 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 23 Apr 2018 13:27:22 +0300 Subject: Change: all actions must have a "where" --- ick2/__init__.py | 2 +- ick2/pipelineapi.py | 18 ++++++++++++++++++ ick2/workapi.py | 1 + ick2/workapi_tests.py | 11 +++++++---- ick2/workerapi.py | 24 ------------------------ 5 files changed, 27 insertions(+), 29 deletions(-) (limited to 'ick2') 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': '{}/'.format(path), - 'callback': self.GET(self.show), - }, - { - 'method': 'DELETE', - 'path': '{}/'.format(path), - 'callback': self.DELETE(self.delete), - }, - ] - def get_resource_name(self, resource): return resource['worker'] -- cgit v1.2.1