From fb0d94f51c54a518e81b9de056916e009b8ddac8 Mon Sep 17 00:00:00 2001 From: Andrey Pavlov Date: Thu, 8 Sep 2016 09:07:15 +0300 Subject: [PATCH] Child images should not be built if parent build failed Change-Id: Ief35fcf2acb23aea8305096b59b7d9f876ba4d98 --- fuel_ccp/build.py | 10 +++++++-- fuel_ccp/tests/test_build.py | 43 +++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/fuel_ccp/build.py b/fuel_ccp/build.py index dc2fa14e..ffb29a3c 100644 --- a/fuel_ccp/build.py +++ b/fuel_ccp/build.py @@ -227,8 +227,14 @@ def process_dockerfile(dockerfile, tmp_dir, config, executor, future_list, for child in dockerfile['children']: if child['match'] or (CONF.builder.keep_image_tree_consistency and child['name'] in ready_images): - submit_dockerfile_processing(child, tmp_dir, config, executor, - future_list, ready_images) + if dockerfile['build_result'] == 'Failure': + LOG.error("%s: Build will be skipped due to parent image (%s) " + "build failure", child['name'], dockerfile['name']) + child['build_result'] = 'Failure' + child['push_result'] = 'Failure' + else: + submit_dockerfile_processing(child, tmp_dir, config, executor, + future_list, ready_images) def submit_dockerfile_processing(dockerfile, tmp_dir, config, executor, diff --git a/fuel_ccp/tests/test_build.py b/fuel_ccp/tests/test_build.py index a3d0e72c..7487e0cd 100644 --- a/fuel_ccp/tests/test_build.py +++ b/fuel_ccp/tests/test_build.py @@ -101,7 +101,8 @@ class TestBuild(base.TestCase): 'parent': 'root', 'children': ['leaf'], 'match': True, - 'path': '/tmp' + 'path': '/tmp', + 'build_result': 'Success' }, 'leaf': { 'name': 'leaf', @@ -129,6 +130,46 @@ class TestBuild(base.TestCase): dockerfiles["leaf"], mock.ANY, mock.ANY, mock.ANY, mock.ANY, ["root", "middle", "leaf"]) + @mock.patch("docker.Client") + @mock.patch("fuel_ccp.build.build_dockerfile") + @mock.patch("fuel_ccp.build.submit_dockerfile_processing") + @mock.patch("fuel_ccp.build.create_rendered_dockerfile") + def test_process_dockerfile_parent_build_failed( + self, render_mock, submit_dockerfile_processing_mock, + build_dockerfile_mock, dc_mock): + dockerfiles = { + 'parent': { + 'name': 'parent', + 'full_name': 'ms/parent', + 'parent': None, + 'children': ['child'], + 'match': True, + 'path': '/tmp', + 'build_result': 'Failure' + }, + 'child': { + 'name': 'child', + 'full_name': 'ms/child', + 'parent': 'parent', + 'children': [], + 'match': True, + 'path': '/tmp' + } + } + + for dockerfile in dockerfiles.values(): + if dockerfile['parent']: + dockerfile['parent'] = dockerfiles[dockerfile['parent']] + for i in range(len(dockerfile['children'])): + dockerfile['children'][i] = ( + dockerfiles[dockerfile['children'][i]] + ) + + build.process_dockerfile( + dockerfiles["parent"], mock.ANY, mock.ANY, mock.ANY, mock.ANY, + []) + submit_dockerfile_processing_mock.assert_not_called() + @mock.patch("docker.Client") @mock.patch("fuel_ccp.build.build_dockerfile") @mock.patch("fuel_ccp.build.submit_dockerfile_processing")