From 1e70623cf9a9043c2e36601e4b6721392ecad2b9 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Oct 16 2018 07:00:37 +0000 Subject: Handle clone_distgit_repo exception. This exception can be handled in case the dist-git commit from which the container image has been built does not exist in dist-git anymore. This is probably an issue in the workflow or dist-git itself, but Freshmaker should handle that. Before this commit, Freshmaker marked whole Event as failed. After this commit, it will only mark particular container image build as failed, but it will still rebuild the other images. --- diff --git a/freshmaker/lightblue.py b/freshmaker/lightblue.py index 9991a70..9856eb6 100644 --- a/freshmaker/lightblue.py +++ b/freshmaker/lightblue.py @@ -361,8 +361,12 @@ class ContainerImage(dict): prefix = "freshmaker-%s-%s-%s" % (namespace, name, commit) with temp_dir(prefix=prefix) as repodir: - clone_distgit_repo(namespace, name, repodir, commit=commit, - ssh=False, logger=log) + try: + clone_distgit_repo(namespace, name, repodir, commit=commit, + ssh=False, logger=log) + except OSError as e: + self.log_error("Error while cloning dist-git repo: %s" % e) + return data content_sets_path = os.path.join(repodir, "content_sets.yml") if not os.path.exists(content_sets_path): diff --git a/tests/test_lightblue.py b/tests/test_lightblue.py index eb51c76..9d8ca15 100644 --- a/tests/test_lightblue.py +++ b/tests/test_lightblue.py @@ -171,6 +171,26 @@ class TestGetAdditionalDataFromDistGit(helpers.FreshmakerTestCase): helpers.AnyStringWith('freshmaker-rpms-foo-docker'), commit='commit', logger=log, ssh=False) + def test_generate_os_error(self): + self.clone_distgit_repo.side_effect = OSError( + "Got an error (128) from git: fatal: reference is not a tree: " + "4d42e2009cec70d871c65de821396cd750d523f1") + + image = ContainerImage.create({"brew": {"build": "nvr"}}) + ret = image._get_additional_data_from_distgit( + "rpms/foo-docker", "branch", "commit") + self.assertEqual(ret["generate_pulp_repos"], False) + + self.assertEqual( + image["error"], + "Error while cloning dist-git repo: Got an error (128) from git: " + "fatal: reference is not a tree: 4d42e2009cec70d871c65de821396cd750d523f1") + + self.clone_distgit_repo.assert_called_once_with( + 'rpms', 'foo-docker', + helpers.AnyStringWith('freshmaker-rpms-foo-docker'), + commit='commit', logger=log, ssh=False) + def test_generate_no_namespace(self): self.path_exists.return_value = True self.patched_open.side_effect = [