From 8adce7593b2850bc4a7a83ad6ea8718692dccedd Mon Sep 17 00:00:00 2001 From: Valerij Maljulin Date: Fri, 9 Nov 2018 09:03:55 +0100 Subject: [PATCH] set module build state to 'failed' imediately Fixes #1009 Signed-off-by: Valerij Maljulin --- module_build_service/utils/batches.py | 2 ++ tests/test_utils/test_utils.py | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/module_build_service/utils/batches.py b/module_build_service/utils/batches.py index 6288dd44..018856be 100644 --- a/module_build_service/utils/batches.py +++ b/module_build_service/utils/batches.py @@ -78,12 +78,14 @@ def start_build_component(builder, c): c.state = koji.BUILD_STATES['FAILED'] c.state_reason = "Failed to build artifact %s: %s" % (c.package, str(e)) log.exception(e) + c.module_build.transition(conf, models.BUILD_STATES['failed']) return if not c.task_id and c.state == koji.BUILD_STATES['BUILDING']: c.state = koji.BUILD_STATES['FAILED'] c.state_reason = ("Failed to build artifact %s: " "Builder did not return task ID" % (c.package)) + c.module_build.transition(conf, models.BUILD_STATES['failed']) return diff --git a/tests/test_utils/test_utils.py b/tests/test_utils/test_utils.py index e3d6f8d1..c28ecd0e 100644 --- a/tests/test_utils/test_utils.py +++ b/tests/test_utils/test_utils.py @@ -861,6 +861,18 @@ class TestBatches: # Make sure that both components in the batch were submitted assert len(mock_sbc.mock_calls) == 2 + def test_start_build_component_failed_state(self, default_buildroot_groups): + """ + Tests whether exception occured while building sets the state to failed + """ + builder = mock.MagicMock() + builder.build.side_effect = Exception('Something have gone terribly wrong') + component = mock.MagicMock() + + module_build_service.utils.batches.start_build_component(builder, component) + + assert component.state == koji.BUILD_STATES['FAILED'] + @patch('module_build_service.utils.batches.start_build_component') @patch('module_build_service.config.Config.rebuild_strategy', new_callable=mock.PropertyMock, return_value='only-changed')