From a5ce18bac98148bb7531a1d3cde1587f11778b37 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Sep 08 2020 13:26:10 +0000 Subject: hub: deleteBuild should skip deleted builds We can return ASAP from the call if build is already deleted. Fixes: https://pagure.io/koji/issue/2475 --- diff --git a/hub/kojihub.py b/hub/kojihub.py index 7492674..8537990 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -8025,6 +8025,9 @@ def delete_build(build, strict=True, min_ref_age=604800): """ context.session.assertPerm('admin') binfo = get_build(build, strict=True) + if binfo['state'] == koji.BUILD_STATES['DELETED']: + # silently return on already deleted build + return refs = build_references(binfo['id'], limit=10, lazy=True) if refs.get('tags'): if strict: diff --git a/tests/test_hub/test_delete_build.py b/tests/test_hub/test_delete_build.py index df9ca18..00fa52a 100644 --- a/tests/test_hub/test_delete_build.py +++ b/tests/test_hub/test_delete_build.py @@ -1,10 +1,11 @@ import mock -import unittest -import kojihub import time -from koji import GenericError +import unittest from collections import defaultdict +import koji +import kojihub + class TestDeleteBuild(unittest.TestCase): @@ -21,7 +22,7 @@ class TestDeleteBuild(unittest.TestCase): retval = defaultdict(dict) retval[ref] = True refs.return_value = retval - with self.assertRaises(GenericError): + with self.assertRaises(koji.GenericError): kojihub.delete_build(build='', strict=True) @mock.patch('kojihub.context') @@ -64,7 +65,7 @@ class TestDeleteBuild(unittest.TestCase): '''Test that we can handle lazy return from build_references''' context.session.assertPerm = mock.MagicMock() buildrefs.return_value = {'tags': []} - binfo = {'id': 'BUILD ID'} + binfo = {'id': 'BUILD ID', 'state': koji.BUILD_STATES['COMPLETE']} build.return_value = binfo kojihub.delete_build(build=binfo, strict=True)