#362 Change the ArtifactBuild.rebuilt_nvr when retrying failed build.
Merged 7 months ago by jkaluza. Opened 7 months ago by jkaluza.
jkaluza/freshmaker factory-3772  into  master

@@ -33,6 +33,7 @@ 

      ContainerBuildHandler, fail_event_on_handler_exception)

  from freshmaker.kojiservice import koji_service

  from freshmaker.types import ArtifactType, ArtifactBuildState, EventState

+ from freshmaker.utils import get_rebuilt_nvr

  

  

  class RebuildImagesOnParentImageBuild(ContainerBuildHandler):

@@ -93,6 +94,11 @@ 

                  args["retry_count"] += 1

                  found_build.build_args = json.dumps(args)

                  if args["retry_count"] < 3:

+                     # Change the rebuilt_nvr, because Koji/OSBS might be in weird

+                     # state in which the build for old NVR already exists and rebuild

+                     # would fail because of NVR conflict.

+                     found_build.rebuilt_nvr = get_rebuilt_nvr(

+                         found_build.type, found_build.original_nvr)

                      found_build.transition(

                          ArtifactBuildState.PLANNED.value,

                          "Retrying failed build %s" % (str(found_build.build_id)))

@@ -90,18 +90,23 @@ 

          self.assertEqual(build_1.build_id, 2)

          self.assertEqual(build_2.build_id, 3)

  

+     @mock.patch('freshmaker.handlers.koji.rebuild_images_on_parent_image_build.get_rebuilt_nvr')

      @mock.patch('freshmaker.handlers.ContainerBuildHandler.build_image_artifact_build')

      @mock.patch('freshmaker.handlers.ContainerBuildHandler.get_repo_urls')

-     def test_not_build_containers_when_dependency_container_build_task_failed(self, repo_urls, build_image):

+     def test_not_build_containers_when_dependency_container_build_task_failed(

+             self, repo_urls, build_image, rebuilt_nvr):

          """

          Tests when dependency container build task failed in brew, only update build state in db.

          """

          build_image.side_effect = [1, 2, 3, 4]

          repo_urls.return_value = ["url"]

+         rebuilt_nvr.side_effect = ["foo-1-1.2", "foo-1-1.3"]

          e1 = models.Event.create(db.session, "test_msg_id", "RHSA-2018-001", events.TestingEvent)

          event = self.get_event_from_msg(get_fedmsg('brew_container_task_failed'))

  

-         base_build = models.ArtifactBuild.create(db.session, e1, 'test-product-docker', ArtifactType.IMAGE, event.task_id)

+         base_build = models.ArtifactBuild.create(

+             db.session, e1, 'test-product-docker', ArtifactType.IMAGE, event.task_id,

+             original_nvr='foo-1-1', rebuilt_nvr='foo-1-1.1')

          base_build.build_args = json.dumps({})

  

          models.ArtifactBuild.create(db.session, e1, 'docker-up', ArtifactType.IMAGE, 0,

@@ -109,10 +114,12 @@ 

          self.handler.handle(event)

          self.assertEqual(base_build.state, ArtifactBuildState.BUILD.value)

          self.assertEqual(base_build.build_id, 1)

+         self.assertEqual(base_build.rebuilt_nvr, "foo-1-1.2")

          event.task_id = 1

          self.handler.handle(event)

          self.assertEqual(base_build.state, ArtifactBuildState.BUILD.value)

          self.assertEqual(base_build.build_id, 2)

+         self.assertEqual(base_build.rebuilt_nvr, "foo-1-1.3")

          event.task_id = 2

          self.handler.handle(event)

          self.assertEqual(base_build.state, ArtifactBuildState.FAILED.value)

Koji or OSBS might be in weird state in which the build for old
NVR already exists and rebuild would fail because of NVR conflict.

Commit 85f4cbe fixes this pull-request

Pull-Request has been merged by jkaluza

7 months ago

Pull-Request has been merged by jkaluza

7 months ago