diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-11-13 19:59:21 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-11-13 19:59:21 +0100 |
commit | 625d8e3b16ccea2eb84de83fd829be180986c829 (patch) | |
tree | c0547cf125b4ae2cf3ffecece9ed8bc1c122e308 /ick2 | |
parent | 23b7b2f901e4291ae4009f845a12b1ae32b66bb3 (diff) | |
download | ick2-625d8e3b16ccea2eb84de83fd829be180986c829.tar.gz |
Add: if a build step fails, terminate build
Diffstat (limited to 'ick2')
-rw-r--r-- | ick2/controllerapi.py | 16 | ||||
-rw-r--r-- | ick2/controllerapi_tests.py | 41 |
2 files changed, 55 insertions, 2 deletions
diff --git a/ick2/controllerapi.py b/ick2/controllerapi.py index 8b4bc29..a9a97e9 100644 --- a/ick2/controllerapi.py +++ b/ick2/controllerapi.py @@ -435,8 +435,8 @@ class WorkAPI(APIbase): pipeline=pipeline, doing=doing) - if update.get('exit_code') == 0: - ick2.log.log('trace', msg_texg='xxx finishing step') + exit_code = update.get('exit_code') + if exit_code == 0: index = doing['step_index'] + 1 actions = pipeline['actions'] if index >= len(actions): @@ -453,6 +453,18 @@ class WorkAPI(APIbase): 'doing': doing, } self._update_worker(worker_state) + elif exit_code is not None: + assert isinstance(exit_code, int) + assert exit_code != 0 + pipeline['status'] = 'idle' + self._finish_build(update) + self._update_project(project) + + worker_state = { + 'worker': update['worker'], + 'doing': {}, + } + self._update_worker(worker_state) def _check_work_update(self, doing, update): # pragma: no cover must_match = ['worker', 'project', 'pipeline', 'build_id'] diff --git a/ick2/controllerapi_tests.py b/ick2/controllerapi_tests.py index 8acfd62..ad638b6 100644 --- a/ick2/controllerapi_tests.py +++ b/ick2/controllerapi_tests.py @@ -358,3 +358,44 @@ class WorkAPITests(unittest.TestCase): self.assertEqual( projects.get_pipeline('foo', 'build'), {'status': 'idle'}) + + def test_worker_manager_posts_failure(self): + projects = self.create_project_api() + projects.set_pipeline('triggered', 'foo', 'build') + self.create_worker_api() + work = self.create_work_api() + + # Ask for some work. + expected = { + 'build_id': 1, + 'worker': 'asterix', + 'project': 'foo', + 'pipeline': 'build', + 'step': { + 'shell': 'step-1', + }, + 'step_index': 0, + 'log': '/logs/1', + } + self.assertEqual(work.get_work('asterix'), expected) + + # Post a partial update. + done = { + 'build_id': 1, + 'worker': 'asterix', + 'project': 'foo', + 'pipeline': 'build', + 'exit_code': 1, + 'stdout': 'out', + 'stderr': 'err', + 'timestamp': '2000-01-01T00:00:00', + } + work.update_work(done) + + # Ask for work again. + self.assertEqual(work.get_work('asterix'), {}) + + # An pipeline status has changed. + self.assertEqual( + projects.get_pipeline('foo', 'build'), + {'status': 'idle'}) |