#336 Refactor "handlers" layout.
Merged 3 months ago by jkaluza. Opened 3 months ago by jkaluza.
jkaluza/freshmaker errata-refactor  into  master

file modified
+2 -2

@@ -43,8 +43,8 @@ 

  

  The handler which rebuilds all the modules after the `.spec` file of RPM including in a module is updated can look like this:

  

-     class GitRPMSpecChangeHandler(BaseHandler):

-         name = "GitRPMSpecChangeHandler"

+     class RebuildImagesOnGitRPMSpecChange(BaseHandler):

+         name = "RebuildImagesOnGitRPMSpecChange"

  

          def can_handle(self, event):

              return isinstance(event, GitRPMSpecChangeEvent)

file modified
+7 -9

@@ -51,18 +51,16 @@ 

          'freshmaker.parsers.internal:FreshmakerManualRebuildParser',

          'freshmaker.parsers.bodhi:BodhiUpdateCompleteStableParser',

          'freshmaker.parsers.git:GitReceiveParser',

-         'freshmaker.parsers.koji:KojiTaskStateChangeParser',

          'freshmaker.parsers.mbs:MBSModuleStateChangeParser',

      ]

  

      # List of enabled composing handlers.

      HANDLERS = [

-         "freshmaker.handlers.bodhi:BodhiUpdateCompleteStableHandler",

-         "freshmaker.handlers.git:GitDockerfileChangeHandler",

-         "freshmaker.handlers.git:GitModuleMetadataChangeHandler",

-         "freshmaker.handlers.git:GitRPMSpecChangeHandler",

-         "freshmaker.handlers.koji:KojiTaskStateChangeHandler",

-         "freshmaker.handlers.mbs:MBSModuleStateChangeHandler",

+         "freshmaker.handlers.koji:RebuildImagesOnRPMBodhiUpdate",

+         "freshmaker.handlers.koji:RebuildImagesOnGitDockerfileChange",

+         "freshmaker.handlers.mbs:RebuildModulesOnGitMMDChange",

+         "freshmaker.handlers.mbs:RebuildModulesOnGitRPMSpecChange",

+         "freshmaker.handlers.internal:UpdateDBOnModuleBuild",

      ]

  

      # Base URL of git repository with source artifacts.

@@ -309,12 +307,12 @@ 

      MAX_THREAD_WORKERS = 1

  

      HANDLER_BUILD_WHITELIST = {

-         'BrewSignRPMHandler': {

+         'GenerateAdvisorySignedEventOnRPMSign': {

              'image': {

                  'advisory_state': 'REL_PREP|PUSH_READY|IN_PUSH|SHIPPED_LIVE',

              },

          },

-         'ErrataAdvisoryStateChangedHandler': {

+         'UpdateDBOnAdvisoryChange': {

              'image': {

                  'advisory_state': 'REL_PREP|PUSH_READY|IN_PUSH|SHIPPED_LIVE',

              },

freshmaker/handlers/internal/__init__.py freshmaker/handlers/bodhi/__init__.py
file renamed
+3 -1

@@ -19,4 +19,6 @@ 

  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

  # SOFTWARE.

  

- from .update_complete_stable import BodhiUpdateCompleteStableHandler  # noqa

+ from .update_db_on_advisory_change import UpdateDBOnAdvisoryChange  # noqa

+ from .update_db_on_module_build import UpdateDBOnModuleBuild  # noqa

+ from .generate_advisory_signed_event_on_rpm_sign import GenerateAdvisorySignedEventOnRPMSign  # noqa

file renamed
+2 -2

@@ -29,14 +29,14 @@ 

  from freshmaker.models import Event

  

  

- class BrewSignRPMHandler(BaseHandler):

+ class GenerateAdvisorySignedEventOnRPMSign(BaseHandler):

      """

      Checks whether all RPMs in Errata advisories for signed package are signed

      and in case they are, generates ErrataAdvisoryRPMsSignedEvent events for

      each advisory.

      """

  

-     name = 'BrewSignRPMHandler'

+     name = 'GenerateAdvisorySignedEventOnRPMSign'

  

      def can_handle(self, event):

          return isinstance(event, BrewSignRPMEvent)

freshmaker/handlers/internal/update_db_on_advisory_change.py freshmaker/handlers/errata/errata_advisory_state_changed.py
file renamed
+3 -3

@@ -28,18 +28,18 @@ 

  from freshmaker.types import EventState

  

  

- class ErrataAdvisoryStateChangedHandler(BaseHandler):

+ class UpdateDBOnAdvisoryChange(BaseHandler):

      """Mark Errata advisory as released

  

      When an advisory state is changed to SHIPPED_LIVE, mark it as released in

-     associated event object of ``ErrataAdvisoryStateChangedHandler``.

+     associated event object of ``UpdateDBOnAdvisoryChange``.

  

      This is used to avoiding generating YUM repository to include RPMs

      inlcuded in a SHIPPED_LIVE advisory, because at that state, RPMs will be

      available in official YUM repositories.

      """

  

-     name = 'ErrataAdvisoryStateChangedHandler'

+     name = 'UpdateDBOnAdvisoryChange'

  

      def can_handle(self, event):

          if not isinstance(event, ErrataAdvisoryStateChangedEvent):

freshmaker/handlers/internal/update_db_on_module_build.py freshmaker/handlers/mbs/module_state_change.py
file renamed
+2 -2

@@ -29,8 +29,8 @@ 

  from freshmaker.events import MBSModuleStateChangeEvent

  

  

- class MBSModuleStateChangeHandler(BaseHandler):

-     name = "MBSModuleStateChangeHandler"

+ class UpdateDBOnModuleBuild(BaseHandler):

+     name = "UpdateDBOnModuleBuild"

  

      def can_handle(self, event):

          if isinstance(event, MBSModuleStateChangeEvent):

@@ -19,4 +19,8 @@ 

  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

  # SOFTWARE.

  

- from .task_state_change import KojiTaskStateChangeHandler  # noqa

+ from .rebuild_images_on_git_dockerfile_change import RebuildImagesOnGitDockerfileChange # noqa

+ from .rebuild_images_on_odcs_compose_done import RebuildImagesOnODCSComposeDone  # noqa

+ from .rebuild_images_on_parent_image_build import RebuildImagesOnParentImageBuild  # noqa

+ from .rebuild_images_on_rpm_advisory_change import RebuildImagesOnRPMAdvisoryChange  # noqa

+ from .rebuild_images_on_rpm_bodhi_update import RebuildImagesOnRPMBodhiUpdate  # noqa

freshmaker/handlers/koji/rebuild_images_on_git_dockerfile_change.py freshmaker/handlers/git/dockerfile_change.py
file renamed
+2 -2

@@ -29,8 +29,8 @@ 

  from freshmaker.events import GitDockerfileChangeEvent

  

  

- class GitDockerfileChangeHandler(ContainerBuildHandler):

-     name = 'GitDockerfileChangeHandler'

+ class RebuildImagesOnGitDockerfileChange(ContainerBuildHandler):

+     name = 'RebuildImagesOnGitDockerfileChange'

  

      def can_handle(self, event):

          return isinstance(event, GitDockerfileChangeEvent)

freshmaker/handlers/koji/rebuild_images_on_odcs_compose_done.py freshmaker/handlers/odcs/compose_state_change.py
file renamed
+2 -2

@@ -31,10 +31,10 @@ 

  

  from odcs.common.types import COMPOSE_STATES

  

- __all__ = ('ComposeStateChangeHandler',)

+ __all__ = ('RebuildImagesOnODCSComposeDone',)

  

  

- class ComposeStateChangeHandler(ContainerBuildHandler):

+ class RebuildImagesOnODCSComposeDone(ContainerBuildHandler):

      """Start image rebuild with this compose containing included packages"""

  

      def can_handle(self, event):

freshmaker/handlers/koji/rebuild_images_on_parent_image_build.py freshmaker/handlers/brew/container_task_state_change.py
file renamed
+2 -2

@@ -35,10 +35,10 @@ 

  from freshmaker.types import ArtifactType, ArtifactBuildState, EventState

  

  

- class BrewContainerTaskStateChangeHandler(ContainerBuildHandler):

+ class RebuildImagesOnParentImageBuild(ContainerBuildHandler):

      """Rebuild container when a dependecy container is built in Brew"""

  

-     name = 'BrewContainerTaskStateChangeHandler'

+     name = 'RebuildImagesOnParentImageBuild'

  

      def can_handle(self, event):

          return isinstance(event, BrewContainerTaskStateChangeEvent)

freshmaker/handlers/koji/rebuild_images_on_rpm_advisory_change.py freshmaker/handlers/errata/errata_advisory_rpms_signed.py
file renamed
+2 -2

@@ -37,13 +37,13 @@ 

  from freshmaker.utils import get_rebuilt_nvr

  

  

- class ErrataAdvisoryRPMsSignedHandler(ContainerBuildHandler):

+ class RebuildImagesOnRPMAdvisoryChange(ContainerBuildHandler):

      """

      Rebuilds all Docker images which contain packages from the Errata

      advisory.

      """

  

-     name = 'ErrataAdvisoryRPMsSignedHandler'

+     name = 'RebuildImagesOnRPMAdvisoryChange'

  

      def can_handle(self, event):

          return isinstance(event, ErrataAdvisoryRPMsSignedEvent)

freshmaker/handlers/koji/rebuild_images_on_rpm_bodhi_update.py freshmaker/handlers/bodhi/update_complete_stable.py
file renamed
+2 -2

@@ -33,9 +33,9 @@ 

  from freshmaker.kojiservice import koji_service

  

  

- class BodhiUpdateCompleteStableHandler(ContainerBuildHandler):

+ class RebuildImagesOnRPMBodhiUpdate(ContainerBuildHandler):

      """Rebuild docker images when RPMs are synced by Bodhi"""

-     name = 'BodhiUpdateCompleteStableHandler'

+     name = 'RebuildImagesOnRPMBodhiUpdate'

  

      def can_handle(self, event):

          return isinstance(event, BodhiUpdateCompleteStableEvent)

@@ -1,59 +0,0 @@ 

- # -*- coding: utf-8 -*-

- # Copyright (c) 2017  Red Hat, Inc.

- #

- # Permission is hereby granted, free of charge, to any person obtaining a copy

- # of this software and associated documentation files (the "Software"), to deal

- # in the Software without restriction, including without limitation the rights

- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

- # copies of the Software, and to permit persons to whom the Software is

- # furnished to do so, subject to the following conditions:

- #

- # The above copyright notice and this permission notice shall be included in all

- # copies or substantial portions of the Software.

- #

- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR

- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,

- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE

- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER

- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

- # SOFTWARE.

- 

- from freshmaker import log, db, models

- from freshmaker.types import ArtifactType, ArtifactBuildState

- from freshmaker.handlers import BaseHandler, fail_event_on_handler_exception

- from freshmaker.events import KojiTaskStateChangeEvent

- 

- 

- class KojiTaskStateChangeHandler(BaseHandler):

-     name = "KojiTaskStateChangeHandler"

- 

-     def can_handle(self, event):

-         if isinstance(event, KojiTaskStateChangeEvent):

-             return True

- 

-         return False

- 

-     @fail_event_on_handler_exception

-     def handle(self, event):

-         task_id = event.task_id

-         task_state = event.task_state

- 

-         # check whether the task exists in db as image build

-         builds = db.session.query(models.ArtifactBuild).filter_by(build_id=task_id,

-                                                                   type=ArtifactType.IMAGE.value).all()

-         if len(builds) > 1:

-             raise RuntimeError("Found duplicate image build '%s' in db" % task_id)

-         if len(builds) == 1:

-             build = builds.pop()

-             self.set_context(build)

-             if task_state in ['CLOSED', 'FAILED']:

-                 log.info("Image build '%s' state changed in koji, updating it in db.", task_id)

-             if task_state == 'CLOSED':

-                 build.state = ArtifactBuildState.DONE.value

-                 db.session.commit()

-             if task_state == 'FAILED':

-                 build.state = ArtifactBuildState.FAILED.value

-                 db.session.commit()

- 

-         return []

@@ -19,4 +19,5 @@ 

  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

  # SOFTWARE.

  

- from .module_state_change import MBSModuleStateChangeHandler  # noqa

+ from .rebuild_modules_on_git_mmd_change import RebuildModulesOnGitMMDChange  # noqa

+ from .rebuild_modules_on_git_rpm_spec_change import RebuildModulesOnGitRPMSpecChange  # noqa

freshmaker/handlers/mbs/rebuild_modules_on_git_mmd_change.py freshmaker/handlers/git/module_metadata_change.py
file renamed
+2 -2

@@ -28,8 +28,8 @@ 

  from freshmaker.events import GitModuleMetadataChangeEvent

  

  

- class GitModuleMetadataChangeHandler(BaseHandler):

-     name = "GitModuleMetadataChangeHandler"

+ class RebuildModulesOnGitMMDChange(BaseHandler):

+     name = "RebuildModulesOnGitMMDChange"

  

      def can_handle(self, event):

          if isinstance(event, GitModuleMetadataChangeEvent):

freshmaker/handlers/mbs/rebuild_modules_on_git_rpm_spec_change.py freshmaker/handlers/git/rpm_spec_change.py
file renamed
+2 -2

@@ -26,8 +26,8 @@ 

  from freshmaker.events import GitRPMSpecChangeEvent

  

  

- class GitRPMSpecChangeHandler(BaseHandler):

-     name = "GitRPMSpecChangeHandler"

+ class RebuildModulesOnGitRPMSpecChange(BaseHandler):

+     name = "RebuildModulesOnGitRPMSpecChange"

  

      def can_handle(self, event):

          if isinstance(event, GitRPMSpecChangeEvent):

tests/handlers/__init__.py freshmaker/handlers/odcs/__init__.py
file renamed
+2 -2

@@ -18,5 +18,5 @@ 

  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

  # SOFTWARE.

- 

- from .compose_state_change import ComposeStateChangeHandler  # noqa

+ #

+ # Written by Jan Kaluza <jkaluza@redhat.com>

tests/handlers/internal/__init__.py freshmaker/handlers/git/__init__.py
file renamed
+2 -4

@@ -18,7 +18,5 @@ 

  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

  # SOFTWARE.

- 

- from .dockerfile_change import GitDockerfileChangeHandler  # noqa

- from .module_metadata_change import GitModuleMetadataChangeHandler  # noqa

- from .rpm_spec_change import GitRPMSpecChangeHandler  # noqa

+ #

+ # Written by Jan Kaluza <jkaluza@redhat.com>

file renamed
+17 -17

@@ -23,19 +23,19 @@ 

  

  from mock import patch, MagicMock, PropertyMock

  

- from freshmaker.handlers.brew.sign_rpm import BrewSignRPMHandler

+ from freshmaker.handlers.internal import GenerateAdvisorySignedEventOnRPMSign

  from freshmaker.errata import ErrataAdvisory

  from tests import helpers

  

  

  class TestBrewSignHandler(helpers.ModelsTestCase):

-     """Test BrewSignRPMHandler.handle"""

+     """Test GenerateAdvisorySignedEventOnRPMSign.handle"""

  

      @patch('freshmaker.errata.Errata.advisories_from_event')

      @patch('freshmaker.errata.Errata.builds_signed')

      @patch("freshmaker.config.Config.handler_build_whitelist",

             new_callable=PropertyMock, return_value={

-                "BrewSignRPMHandler": {"image": {"advisory_name": "RHSA-.*"}}})

+                "GenerateAdvisorySignedEventOnRPMSign": {"image": {"advisory_name": "RHSA-.*"}}})

      def test_return_value(self, handler_build_whitelist, builds_signed,

                            advisories_from_event):

          """

@@ -47,7 +47,7 @@ 

  

          event = MagicMock()

          event.msg_id = "msg_123"

-         handler = BrewSignRPMHandler()

+         handler = GenerateAdvisorySignedEventOnRPMSign()

          ret = handler.handle(event)

  

          self.assertTrue(len(ret), 1)

@@ -69,7 +69,7 @@ 

          builds_signed.return_value = False

  

          event = MagicMock()

-         handler = BrewSignRPMHandler()

+         handler = GenerateAdvisorySignedEventOnRPMSign()

          ret = handler.handle(event)

  

          self.assertTrue(not ret)

@@ -91,7 +91,7 @@ 

          builds_signed.return_value = False

  

          event = MagicMock()

-         handler = BrewSignRPMHandler()

+         handler = GenerateAdvisorySignedEventOnRPMSign()

          handler.handle(event)

  

          builds_signed.assert_called_once()

@@ -100,7 +100,7 @@ 

      @patch('freshmaker.errata.Errata.builds_signed')

      @patch("freshmaker.config.Config.handler_build_whitelist",

             new_callable=PropertyMock, return_value={

-                "BrewSignRPMHandler": {"image": {"advisory_name": "RHSA-.*"}}})

+                "GenerateAdvisorySignedEventOnRPMSign": {"image": {"advisory_name": "RHSA-.*"}}})

      def test_allow_build_false(self, handler_build_whitelist, builds_signed,

                                 advisories_from_event):

          """

@@ -111,7 +111,7 @@ 

          builds_signed.return_value = False

  

          event = MagicMock()

-         handler = BrewSignRPMHandler()

+         handler = GenerateAdvisorySignedEventOnRPMSign()

          ret = handler.handle(event)

  

          self.assertTrue(not ret)

@@ -121,7 +121,7 @@ 

      @patch('freshmaker.errata.Errata.builds_signed')

      @patch("freshmaker.config.Config.handler_build_whitelist",

             new_callable=PropertyMock, return_value={

-                "BrewSignRPMHandler": {"image": {"advisory_name": "RHSA-.*"}}})

+                "GenerateAdvisorySignedEventOnRPMSign": {"image": {"advisory_name": "RHSA-.*"}}})

      def test_allow_build_true(self, handler_build_whitelist, builds_signed,

                                advisories_from_event):

          """

@@ -133,7 +133,7 @@ 

          builds_signed.return_value = False

  

          event = MagicMock()

-         handler = BrewSignRPMHandler()

+         handler = GenerateAdvisorySignedEventOnRPMSign()

          handler.handle(event)

  

          builds_signed.assert_called_once()

@@ -144,7 +144,7 @@ 

          "freshmaker.config.Config.handler_build_whitelist",

          new_callable=PropertyMock,

          return_value={

-             "BrewSignRPMHandler": {

+             "GenerateAdvisorySignedEventOnRPMSign": {

                  "image": {

                      "advisory_security_impact": [

                          "Normal", "Important"

@@ -164,7 +164,7 @@ 

          builds_signed.return_value = False

  

          event = MagicMock()

-         handler = BrewSignRPMHandler()

+         handler = GenerateAdvisorySignedEventOnRPMSign()

          handler.handle(event)

  

          builds_signed.assert_called_once()

@@ -175,7 +175,7 @@ 

          "freshmaker.config.Config.handler_build_whitelist",

          new_callable=PropertyMock,

          return_value={

-             "BrewSignRPMHandler": {

+             "GenerateAdvisorySignedEventOnRPMSign": {

                  "image": {

                      "advisory_security_impact": [

                          "Normal", "Important"

@@ -195,7 +195,7 @@ 

          builds_signed.return_value = False

  

          event = MagicMock()

-         handler = BrewSignRPMHandler()

+         handler = GenerateAdvisorySignedEventOnRPMSign()

          handler.handle(event)

  

          builds_signed.assert_not_called()

@@ -204,12 +204,12 @@ 

      @patch('freshmaker.errata.Errata.builds_signed')

      @patch("freshmaker.config.Config.handler_build_whitelist",

             new_callable=PropertyMock, return_value={

-                "BrewSignRPMHandler": {"image": {"advisory_name": "RHSA-.*"}}})

+                "GenerateAdvisorySignedEventOnRPMSign": {"image": {"advisory_name": "RHSA-.*"}}})

      def test_do_not_create_already_handled_event(

              self, handler_build_whitelist, builds_signed,

              advisories_from_event):

          """

-         Tests that BrewSignRPMHandler don't return Event which already exists

+         Tests that GenerateAdvisorySignedEventOnRPMSign don't return Event which already exists

          in Freshmaker DB.

          """

          builds_signed.return_value = True

@@ -218,7 +218,7 @@ 

  

          event = MagicMock()

          event.msg_id = "msg_123"

-         handler = BrewSignRPMHandler()

+         handler = GenerateAdvisorySignedEventOnRPMSign()

          handler.handle(event)

  

          builds_signed.assert_called_once()

tests/handlers/internal/test_update_db_on_advisory_change.py tests/test_errata_advisory_state_changed.py
file renamed
+54 -54

@@ -30,8 +30,8 @@ 

  from freshmaker.errata import ErrataAdvisory

  from freshmaker.events import ErrataAdvisoryRPMsSignedEvent

  from freshmaker.events import ErrataAdvisoryStateChangedEvent

- from freshmaker.handlers.errata import ErrataAdvisoryRPMsSignedHandler

- from freshmaker.handlers.errata import ErrataAdvisoryStateChangedHandler

+ from freshmaker.handlers.koji import RebuildImagesOnRPMAdvisoryChange

+ from freshmaker.handlers.internal import UpdateDBOnAdvisoryChange

  from freshmaker.lightblue import ContainerImage

  from freshmaker.models import Event, ArtifactBuild, EVENT_TYPES

  from freshmaker.types import ArtifactBuildState, ArtifactType, EventState

@@ -39,13 +39,13 @@ 

  

  

  class TestAllowBuild(helpers.ModelsTestCase):

-     """Test ErrataAdvisoryRPMsSignedHandler.allow_build"""

+     """Test RebuildImagesOnRPMAdvisoryChange.allow_build"""

  

-     @patch("freshmaker.handlers.errata.ErrataAdvisoryRPMsSignedHandler."

+     @patch("freshmaker.handlers.koji.RebuildImagesOnRPMAdvisoryChange."

             "_find_images_to_rebuild", return_value=[])

      @patch("freshmaker.config.Config.handler_build_whitelist",

             new_callable=PropertyMock, return_value={

-                "ErrataAdvisoryRPMsSignedHandler": {"image": {"advisory_name": "RHSA-.*"}}})

+                "RebuildImagesOnRPMAdvisoryChange": {"image": {"advisory_name": "RHSA-.*"}}})

      def test_allow_build_false(self, handler_build_whitelist, record_images):

          """

          Tests that allow_build filters out advisories based on advisory_name.

@@ -55,16 +55,16 @@ 

              ErrataAdvisory(123, "RHBA-2017", "REL_PREP", [],

                             security_impact="",

                             product_short_name="product"))

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler.handle(event)

  

          record_images.assert_not_called()

  

-     @patch("freshmaker.handlers.errata.ErrataAdvisoryRPMsSignedHandler."

+     @patch("freshmaker.handlers.koji.RebuildImagesOnRPMAdvisoryChange."

             "_find_images_to_rebuild", return_value=[])

      @patch("freshmaker.config.Config.handler_build_whitelist",

             new_callable=PropertyMock, return_value={

-                "ErrataAdvisoryRPMsSignedHandler": {"image": {"advisory_name": "RHSA-.*"}}})

+                "RebuildImagesOnRPMAdvisoryChange": {"image": {"advisory_name": "RHSA-.*"}}})

      def test_allow_build_true(self, handler_build_whitelist, record_images):

          """

          Tests that allow_build does not filter out advisories based on

@@ -75,19 +75,19 @@ 

              ErrataAdvisory(123, "RHSA-2017", "REL_PREP", [],

                             security_impact="",

                             product_short_name="product"))

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler.handle(event)

  

          record_images.assert_called_once()

          self.assertEqual(handler.current_db_event_id, 1)

  

-     @patch("freshmaker.handlers.errata.ErrataAdvisoryRPMsSignedHandler."

+     @patch("freshmaker.handlers.koji.RebuildImagesOnRPMAdvisoryChange."

             "_find_images_to_rebuild", return_value=[])

      @patch(

          "freshmaker.config.Config.handler_build_whitelist",

          new_callable=PropertyMock,

          return_value={

-             "ErrataAdvisoryRPMsSignedHandler": {

+             "RebuildImagesOnRPMAdvisoryChange": {

                  "image": {

                      "advisory_security_impact": [

                          "Normal", "Important"

@@ -107,18 +107,18 @@ 

              ErrataAdvisory(123, "RHSA-2017", "REL_PREP", [],

                             security_impact="Important",

                             product_short_name="product"))

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler.handle(event)

  

          record_images.assert_called_once()

  

-     @patch("freshmaker.handlers.errata.ErrataAdvisoryRPMsSignedHandler."

+     @patch("freshmaker.handlers.koji.RebuildImagesOnRPMAdvisoryChange."

             "_find_images_to_rebuild", return_value=[])

      @patch(

          "freshmaker.config.Config.handler_build_whitelist",

          new_callable=PropertyMock,

          return_value={

-             "ErrataAdvisoryRPMsSignedHandler": {

+             "RebuildImagesOnRPMAdvisoryChange": {

                  "image": {

                      "advisory_security_impact": [

                          "Normal", "Important"

@@ -137,7 +137,7 @@ 

              ErrataAdvisory(123, "RHSA-2017", "REL_PREP", [],

                             security_impact="None",

                             product_short_name="product"))

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler.handle(event)

  

          record_images.assert_not_called()

@@ -146,7 +146,7 @@ 

          "freshmaker.config.Config.handler_build_whitelist",

          new_callable=PropertyMock,

          return_value={

-             "ErrataAdvisoryRPMsSignedHandler": {

+             "RebuildImagesOnRPMAdvisoryChange": {

                  "image": {

                      "image_name": ["foo", "bar"]

                  }

@@ -158,7 +158,7 @@ 

          Tests that allow_build does filter images based on image_name.

          """

  

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler.event = ErrataAdvisoryRPMsSignedEvent(

              "123",

              ErrataAdvisory(123, "RHSA-2017", "REL_PREP", [],

@@ -185,7 +185,7 @@ 

          "freshmaker.config.Config.handler_build_whitelist",

          new_callable=PropertyMock,

          return_value={

-             "ErrataAdvisoryRPMsSignedHandler": {

+             "RebuildImagesOnRPMAdvisoryChange": {

                  "image": {

                      "image_name": ["foo", "bar"],

                      "advisory_name": "RHSA-.*",

@@ -198,7 +198,7 @@ 

          Tests that allow_build does filter images based on image_name.

          """

  

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler.event = ErrataAdvisoryRPMsSignedEvent(

              "123",

              ErrataAdvisory(123, "RHSA-2017", "REL_PREP", [],

@@ -217,7 +217,7 @@ 

          "freshmaker.config.Config.handler_build_whitelist",

          new_callable=PropertyMock,

          return_value={

-             "ErrataAdvisoryRPMsSignedHandler": {

+             "RebuildImagesOnRPMAdvisoryChange": {

                  "image": {

                      "image_name": ["foo", "bar"]

                  }

@@ -227,7 +227,7 @@ 

          "freshmaker.config.Config.handler_build_blacklist",

          new_callable=PropertyMock,

          return_value={

-             "ErrataAdvisoryRPMsSignedHandler": {

+             "RebuildImagesOnRPMAdvisoryChange": {

                  "image": all_(

                      {

                          "image_name": "foo",

@@ -238,7 +238,7 @@ 

          })

      def test_filter_out_not_allowed_builds_image_version(

              self, handler_build_blacklist, handler_build_whitelist):

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler.event = ErrataAdvisoryRPMsSignedEvent(

              "123",

              ErrataAdvisory(123, "RHSA-2017", "REL_PREP", [],

@@ -268,7 +268,7 @@ 

      def setUp(self):

          super(TestBatches, self).setUp()

          self.patcher = helpers.Patcher(

-             'freshmaker.handlers.errata.ErrataAdvisoryRPMsSignedHandler.')

+             'freshmaker.handlers.koji.RebuildImagesOnRPMAdvisoryChange.')

  

      def tearDown(self):

          super(TestBatches, self).tearDown()

@@ -341,7 +341,7 @@ 

  

          # Record the batches.

          event = events.BrewSignRPMEvent("123", "openssl-1.1.0-1")

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler._record_batches(batches, event)

  

          # Check that the images have proper data in proper db columns.

@@ -409,7 +409,7 @@ 

              "child-1-25": self.b2

          }

  

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler.set_context(self.ev)

          handler._check_images_to_rebuild(self.ev, builds)

  

@@ -425,7 +425,7 @@ 

              "parent-1-25": self.b1

          }

  

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler.set_context(self.ev)

          handler._check_images_to_rebuild(self.ev, builds)

  

@@ -441,7 +441,7 @@ 

              "something-1-25": self.b1,

          }

  

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler.set_context(self.ev)

          handler._check_images_to_rebuild(self.ev, builds)

  

@@ -451,11 +451,11 @@ 

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

  

  

- class TestErrataAdvisoryStateChangedHandler(helpers.ModelsTestCase):

+ class TestUpdateDBOnAdvisoryChange(helpers.ModelsTestCase):

  

      @patch('freshmaker.errata.Errata.advisories_from_event')

      def test_rebuild_if_not_exists(self, advisories_from_event):

-         handler = ErrataAdvisoryStateChangedHandler()

+         handler = UpdateDBOnAdvisoryChange()

  

          for state in ["REL_PREP", "PUSH_READY", "IN_PUSH", "SHIPPED_LIVE"]:

              advisories_from_event.return_value = [

@@ -471,7 +471,7 @@ 

  

      @patch('freshmaker.errata.Errata.advisories_from_event')

      @patch.object(conf, 'handler_build_whitelist', new={

-         'ErrataAdvisoryStateChangedHandler': {

+         'UpdateDBOnAdvisoryChange': {

              'image': {

                  'advisory_state': r'REL_PREP|SHIPPED_LIVE',

              }

@@ -479,7 +479,7 @@ 

      })

      def test_rebuild_if_not_exists_unknown_states(

              self, advisories_from_event):

-         handler = ErrataAdvisoryStateChangedHandler()

+         handler = UpdateDBOnAdvisoryChange()

  

          for state in ["NEW_FILES", "QE", "UNKNOWN"]:

              advisories_from_event.return_value = [

@@ -492,7 +492,7 @@ 

  

      @patch('freshmaker.errata.Errata.advisories_from_event')

      @patch.object(conf, 'handler_build_whitelist', new={

-         'ErrataAdvisoryStateChangedHandler': {

+         'UpdateDBOnAdvisoryChange': {

              'image': {

                  'advisory_state': '.*',

              }

@@ -500,7 +500,7 @@ 

      })

      def test_rebuild_if_not_exists_already_exists(

              self, advisories_from_event):

-         handler = ErrataAdvisoryStateChangedHandler()

+         handler = UpdateDBOnAdvisoryChange()

  

          db_event = Event.create(

              db.session, "msg124", "123", ErrataAdvisoryRPMsSignedEvent)

@@ -533,7 +533,7 @@ 

      def test_rebuild_if_not_exists_unknown_errata_id(

              self, advisories_from_event):

          advisories_from_event.return_value = []

-         handler = ErrataAdvisoryStateChangedHandler()

+         handler = UpdateDBOnAdvisoryChange()

  

          for state in ["REL_PREP", "PUSH_READY", "IN_PUSH", "SHIPPED_LIVE"]:

              ev = ErrataAdvisoryStateChangedEvent(

@@ -566,7 +566,7 @@ 

          ev = ErrataAdvisoryStateChangedEvent(

              "msg123", ErrataAdvisory(123, "name", "SHIPPED_LIVE", ["rpm"]))

  

-         handler = ErrataAdvisoryStateChangedHandler()

+         handler = UpdateDBOnAdvisoryChange()

          handler.handle(ev)

  

          db.session.refresh(db_event)

@@ -581,7 +581,7 @@ 

              ev = ErrataAdvisoryStateChangedEvent(

                  "msg123", ErrataAdvisory(123, "name", state, ['rpm']))

  

-             handler = ErrataAdvisoryStateChangedHandler()

+             handler = UpdateDBOnAdvisoryChange()

              handler.handle(ev)

  

              db.session.refresh(db_event)

@@ -592,13 +592,13 @@ 

          ev = ErrataAdvisoryStateChangedEvent(

              "msg123", ErrataAdvisory(123, "name", "SHIPPED_LIVE", ["rpm"]))

  

-         handler = ErrataAdvisoryStateChangedHandler()

+         handler = UpdateDBOnAdvisoryChange()

          handler.handle(ev)

  

-     @patch('freshmaker.handlers.errata.ErrataAdvisoryStateChangedHandler'

+     @patch('freshmaker.handlers.internal.UpdateDBOnAdvisoryChange'

             '.rebuild_if_not_exists')

      @patch.object(conf, 'handler_build_whitelist', new={

-         'ErrataAdvisoryStateChangedHandler': {

+         'UpdateDBOnAdvisoryChange': {

              'image': {

                  'advisory_state': r'REL_PREP',

              }

@@ -615,15 +615,15 @@ 

          event = ErrataAdvisoryStateChangedEvent(

              'msg-id-123',

              ErrataAdvisory(123456, 'name', 'SHIPPED_LIVE', ['rpm']))

-         handler = ErrataAdvisoryStateChangedHandler()

+         handler = UpdateDBOnAdvisoryChange()

          msgs = handler.handle(event)

  

          self.assertEqual([], msgs)

  

-     @patch('freshmaker.handlers.errata.ErrataAdvisoryStateChangedHandler'

+     @patch('freshmaker.handlers.internal.UpdateDBOnAdvisoryChange'

             '.rebuild_if_not_exists')

      @patch.object(conf, 'handler_build_whitelist', new={

-         'ErrataAdvisoryStateChangedHandler': {

+         'UpdateDBOnAdvisoryChange': {

              'image': {

                  'advisory_state': r'SHIPPED_LIVE',

              }

@@ -641,14 +641,14 @@ 

              'msg-id-123',

              ErrataAdvisory(123456, "name", 'SHIPPED_LIVE', ['rpm']))

          event.manual = True

-         handler = ErrataAdvisoryStateChangedHandler()

+         handler = UpdateDBOnAdvisoryChange()

          msgs = handler.handle(event)

  

          self.assertEqual(len(msgs), 1)

  

  

  class TestRecordBatchesImages(helpers.ModelsTestCase):

-     """Test ErrataAdvisoryRPMsSignedHandler._record_batches"""

+     """Test RebuildImagesOnRPMAdvisoryChange._record_batches"""

  

      def setUp(self):

          super(TestRecordBatchesImages, self).setUp()

@@ -656,7 +656,7 @@ 

          self.mock_event = Mock(msg_id='msg-id', search_key=12345)

  

          self.patcher = helpers.Patcher(

-             'freshmaker.handlers.errata.ErrataAdvisoryRPMsSignedHandler.')

+             'freshmaker.handlers.koji.RebuildImagesOnRPMAdvisoryChange.')

  

          self.mock_prepare_pulp_repo = self.patcher.patch(

              'freshmaker.odcsclient.FreshmakerODCSClient.prepare_pulp_repo',

@@ -741,7 +741,7 @@ 

              })]

          ]

  

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler._record_batches(batches, self.mock_event)

  

          # Check parent image

@@ -788,7 +788,7 @@ 

              })]

          ]

  

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler._record_batches(batches, self.mock_event)

  

          # Check parent image

@@ -872,7 +872,7 @@ 

              })]

          ]

  

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler._record_batches(batches, self.mock_event)

  

          query = db.session.query(ArtifactBuild)

@@ -919,7 +919,7 @@ 

              })]

          ]

  

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler._record_batches(batches, self.mock_event)

  

          query = db.session.query(ArtifactBuild)

@@ -956,7 +956,7 @@ 

              })]

          ]

  

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler._record_batches(batches, self.mock_event)

  

          query = db.session.query(ArtifactBuild)

@@ -1036,7 +1036,7 @@ 

              })]

          ]

  

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler._record_batches(batches, self.mock_event)

  

          query = db.session.query(ArtifactBuild)

@@ -1077,7 +1077,7 @@ 

              })],

          ]

  

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler._record_batches(batches, self.mock_event)

  

          build = db.session.query(ArtifactBuild).filter_by(

@@ -1094,11 +1094,11 @@ 

          event = ErrataAdvisoryStateChangedEvent(

              'msg-id-1',

              ErrataAdvisory(123, 'name', 'REL_PREP', ['rpm', 'jar', 'pom']))

-         handler = ErrataAdvisoryStateChangedHandler()

+         handler = UpdateDBOnAdvisoryChange()

          self.assertTrue(handler.can_handle(event))

  

      def test_not_handle_non_rpm_advisory(self):

          event = ErrataAdvisoryStateChangedEvent(

              'msg-id-1', ErrataAdvisory(123, 'name', 'REL_PREP', ['docker']))

-         handler = ErrataAdvisoryStateChangedHandler()

+         handler = UpdateDBOnAdvisoryChange()

          self.assertFalse(handler.can_handle(event))

tests/handlers/internal/test_update_db_on_module_build.py tests/test_mbs_module_state_change_handler.py
file renamed
+18 -18

@@ -30,14 +30,14 @@ 

  

  from freshmaker import events, db, models

  from freshmaker.types import ArtifactType

- from freshmaker.handlers.mbs import MBSModuleStateChangeHandler

+ from freshmaker.handlers.internal import UpdateDBOnModuleBuild

  from freshmaker.parsers.mbs import MBSModuleStateChangeParser

  from freshmaker.config import any_

  

  

- class MBSModuleStateChangeHandlerTest(helpers.ModelsTestCase):

+ class UpdateDBOnModuleBuildTest(helpers.ModelsTestCase):

      def setUp(self):

-         super(MBSModuleStateChangeHandlerTest, self).setUp()

+         super(UpdateDBOnModuleBuildTest, self).setUp()

          events.BaseEvent.register_parser(MBSModuleStateChangeParser)

  

      def test_can_handle_module_state_change_event(self):

@@ -48,14 +48,14 @@ 

              msg = helpers.ModuleStateChangeMessage('testmodule', 'master', state=state).produce()

              event = self.get_event_from_msg(msg)

  

-             handler = MBSModuleStateChangeHandler()

+             handler = UpdateDBOnModuleBuild()

              self.assertTrue(handler.can_handle(event))

  

-     @mock.patch('freshmaker.handlers.mbs.module_state_change.PDC')

-     @mock.patch('freshmaker.handlers.mbs.module_state_change.utils')

-     @mock.patch('freshmaker.handlers.mbs.module_state_change.conf')

+     @mock.patch('freshmaker.handlers.internal.update_db_on_module_build.PDC')

+     @mock.patch('freshmaker.handlers.internal.update_db_on_module_build.utils')

+     @mock.patch('freshmaker.handlers.internal.update_db_on_module_build.conf')

      @mock.patch.object(freshmaker.conf, 'handler_build_whitelist', new={

-         'MBSModuleStateChangeHandler': {

+         'UpdateDBOnModuleBuild': {

              'module': any_({'name': r'testmodule\d*'}, {'branch': 'master'}),

          }

      })

@@ -84,7 +84,7 @@ 

              "43ec03000d249231bc7135b11b810afc96e90efb",

          ]

  

-         handler = MBSModuleStateChangeHandler()

+         handler = UpdateDBOnModuleBuild()

          handler.build_module = mock.Mock()

          handler.build_module.side_effect = [123, 456]

  

@@ -107,12 +107,12 @@ 

          self.assertEqual(builds[1].build_id, 456)

          self.assertEqual(builds[1].type, ArtifactType.MODULE.value)

  

-     @mock.patch('freshmaker.handlers.mbs.module_state_change.PDC')

-     @mock.patch('freshmaker.handlers.mbs.module_state_change.utils')

+     @mock.patch('freshmaker.handlers.internal.update_db_on_module_build.PDC')

+     @mock.patch('freshmaker.handlers.internal.update_db_on_module_build.utils')

      @mock.patch('freshmaker.handlers.conf')

      def test_module_is_not_allowed_in_whitelist(self, conf, utils, PDC):

          conf.handler_build_whitelist = {

-             "MBSModuleStateChangeHandler": {

+             "UpdateDBOnModuleBuild": {

                  "module": any_(

                      {

                          'name': 'base.*',

@@ -131,7 +131,7 @@ 

          pdc = PDC.return_value

          pdc.get_latest_modules.return_value = [mod2]

  

-         handler = MBSModuleStateChangeHandler()

+         handler = UpdateDBOnModuleBuild()

          handler.build_module = mock.Mock()

          handler.record_build = mock.Mock()

  

@@ -140,11 +140,11 @@ 

  

          handler.build_module.assert_not_called()

  

-     @mock.patch('freshmaker.handlers.mbs.module_state_change.PDC')

-     @mock.patch('freshmaker.handlers.mbs.module_state_change.utils')

-     @mock.patch('freshmaker.handlers.mbs.module_state_change.log')

+     @mock.patch('freshmaker.handlers.internal.update_db_on_module_build.PDC')

+     @mock.patch('freshmaker.handlers.internal.update_db_on_module_build.utils')

+     @mock.patch('freshmaker.handlers.internal.update_db_on_module_build.log')

      @mock.patch.object(freshmaker.conf, 'handler_build_whitelist', new={

-         'MBSModuleStateChangeHandler': {

+         'UpdateDBOnModuleBuild': {

              'module': any_({'name': r'module\d+'}, {'branch': 'master'})

          }

      })

@@ -179,7 +179,7 @@ 

          mod3 = mod3_info.produce()

  

          pdc = PDC.return_value

-         handler = MBSModuleStateChangeHandler()

+         handler = UpdateDBOnModuleBuild()

  

          # Assume we have build of module1 recorded in DB already, it doesn't has

          # any dep_on as it was initial triggered by an event which is not

tests/handlers/koji/__init__.py freshmaker/handlers/brew/__init__.py
file renamed
+3 -4

@@ -1,5 +1,5 @@ 

  # -*- coding: utf-8 -*-

- # Copyright (c) 2017  Red Hat, Inc.

+ # Copyright (c) 2016  Red Hat, Inc.

  #

  # Permission is hereby granted, free of charge, to any person obtaining a copy

  # of this software and associated documentation files (the "Software"), to deal

@@ -18,6 +18,5 @@ 

  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

  # SOFTWARE.

- 

- from .sign_rpm import BrewSignRPMHandler  # noqa

- from .container_task_state_change import BrewContainerTaskStateChangeHandler  # noqa

+ #

+ # Written by Jan Kaluza <jkaluza@redhat.com>

tests/handlers/koji/test_rebuild_images_on_git_dockerfile_change.py tests/test_git_dockerfile_change_handler.py
file renamed
+4 -4

@@ -41,14 +41,14 @@ 

          consumer.consume(msg)

  

  

- class GitDockerfileChangeHandlerTest(BaseTestCase):

+ class RebuildImagesOnGitDockerfileChangeTest(BaseTestCase):

  

      @patch('koji.read_config')

      @patch('koji.ClientSession')

      @patch("freshmaker.config.Config.krb_auth_principal",

             new_callable=PropertyMock, return_value="user@example.com")

      @patch.object(freshmaker.conf, 'handler_build_whitelist', new={

-         'GitDockerfileChangeHandler': {

+         'RebuildImagesOnGitDockerfileChange': {

              'image': any_({'name': 'testimage'}, {'branch': 'master'})

          }

      })

@@ -81,7 +81,7 @@ 

          self.assertEqual(builds[0].type, ArtifactType.IMAGE.value)

          self.assertEqual(builds[0].build_id, 123)

  

-     @patch('freshmaker.handlers.git.dockerfile_change.GitDockerfileChangeHandler.build_container')

+     @patch('freshmaker.handlers.koji.RebuildImagesOnGitDockerfileChange.build_container')

      def test_not_rebuild_if_dockerfile_not_changed(self, build_container):

          self.consume_fedmsg(get_fedmsg('git_receive_dockerfile_not_changed'))

          build_container.assert_not_called()

@@ -89,7 +89,7 @@ 

      @patch('koji.read_config')

      @patch('koji.ClientSession')

      @patch.object(freshmaker.conf, 'handler_build_whitelist', new={

-         'GitDockerfileChangeHandler': {

+         'RebuildImagesOnGitDockerfileChange': {

              'image': any_({'name': 'testimage'}, {'branch': 'master'})

          }

      })

tests/handlers/koji/test_rebuild_images_on_odcs_compose_done.py tests/test_odcs_compose_state_change.py
file renamed
+6 -6

@@ -32,16 +32,16 @@ 

      Compose

  )

  from freshmaker.events import ErrataAdvisoryRPMsSignedEvent

- from freshmaker.handlers.odcs import ComposeStateChangeHandler

+ from freshmaker.handlers.koji import RebuildImagesOnODCSComposeDone

  from freshmaker.events import ODCSComposeStateChangeEvent

  from tests import helpers

  

  

- class TestComposeStateChangeHandler(helpers.ModelsTestCase):

-     """Test ODCSComposeStateChangeHandler"""

+ class TestRebuildImagesOnODCSComposeDone(helpers.ModelsTestCase):

+     """Test ODCSRebuildImagesOnODCSComposeDone"""

  

      def setUp(self):

-         super(TestComposeStateChangeHandler, self).setUp()

+         super(TestRebuildImagesOnODCSComposeDone, self).setUp()

  

          # Test data

          # (Inner build depends on outer build)

@@ -99,7 +99,7 @@ 

          event = ODCSComposeStateChangeEvent(

              'msg-id', {'id': 1, 'state': 'generating'}

          )

-         handler = ComposeStateChangeHandler()

+         handler = RebuildImagesOnODCSComposeDone()

          can_handle = handler.can_handle(event)

          self.assertFalse(can_handle)

  

@@ -113,7 +113,7 @@ 

              'msg-id', {'id': self.compose_1.id, 'state': 'done'}

          )

  

-         handler = ComposeStateChangeHandler()

+         handler = RebuildImagesOnODCSComposeDone()

          handler.handle(event)

  

          args, kwargs = start_to_build_images.call_args

tests/handlers/koji/test_rebuild_images_on_parent_image_build.py tests/test_brew_container_task_state_change_handler.py
file renamed
+6 -6

@@ -31,15 +31,15 @@ 

  

  from freshmaker import db, events, models

  from freshmaker.parsers.brew import BrewTaskStateChangeParser

- from freshmaker.handlers.brew import BrewContainerTaskStateChangeHandler

+ from freshmaker.handlers.koji import RebuildImagesOnParentImageBuild

  from freshmaker.types import ArtifactType, ArtifactBuildState, EventState

  

  

- class TestBrewContainerTaskStateChangeHandler(helpers.ModelsTestCase):

+ class TestRebuildImagesOnParentImageBuild(helpers.ModelsTestCase):

      def setUp(self):

-         super(TestBrewContainerTaskStateChangeHandler, self).setUp()

+         super(TestRebuildImagesOnParentImageBuild, self).setUp()

          events.BaseEvent.register_parser(BrewTaskStateChangeParser)

-         self.handler = BrewContainerTaskStateChangeHandler()

+         self.handler = RebuildImagesOnParentImageBuild()

  

      def test_can_handle_brew_container_task_closed_event(self):

          """

@@ -156,7 +156,7 @@ 

              'msg-id-890', 'image-d', 'branch', 'target', 12345,

              'BUILD', 'CLOSED')

  

-         handler = BrewContainerTaskStateChangeHandler()

+         handler = RebuildImagesOnParentImageBuild()

          handler.handle(state_changed_event)

  

          self.assertEqual(EventState.COMPLETE.value,

@@ -199,7 +199,7 @@ 

              'msg-id-890', 'image-a', 'branch', 'target', 12345,

              'BUILD', 'CLOSED')

  

-         handler = BrewContainerTaskStateChangeHandler()

+         handler = RebuildImagesOnParentImageBuild()

          handler.handle(state_changed_event)

  

          # As self.image_b_build starts to be rebuilt, not all images are

tests/handlers/koji/test_rebuild_images_on_rpm_advisory_change.py tests/test_errata_advisory_rpms_signed_handler.py
file renamed
+29 -29

@@ -27,7 +27,7 @@ 

  from freshmaker.events import (

      ErrataAdvisoryRPMsSignedEvent,

      ManualRebuildWithAdvisoryEvent)

- from freshmaker.handlers.errata import ErrataAdvisoryRPMsSignedHandler

+ from freshmaker.handlers.koji import RebuildImagesOnRPMAdvisoryChange

  from freshmaker.lightblue import ContainerImage

  from freshmaker.models import Event, Compose

  from freshmaker.types import EventState

@@ -36,10 +36,10 @@ 

  from tests import helpers

  

  

- class TestErrataAdvisoryRPMsSignedHandler(helpers.ModelsTestCase):

+ class TestRebuildImagesOnRPMAdvisoryChange(helpers.ModelsTestCase):

  

      def setUp(self):

-         super(TestErrataAdvisoryRPMsSignedHandler, self).setUp()

+         super(TestRebuildImagesOnRPMAdvisoryChange, self).setUp()

  

          # Each time when recording a build into database, freshmaker has to

          # request a pulp repo from ODCS. This is not necessary for running

@@ -47,7 +47,7 @@ 

          # There are 6 images used to run tests which will be created below, so

          # there should be 6 composes created as Pulp repos.

          self.patcher = helpers.Patcher(

-             'freshmaker.handlers.errata.ErrataAdvisoryRPMsSignedHandler.')

+             'freshmaker.handlers.koji.RebuildImagesOnRPMAdvisoryChange.')

  

          # We do not want to send messages to message bus while running tests

          self.mock_messaging_publish = self.patcher.patch(

@@ -218,7 +218,7 @@ 

                             product_short_name="product"))

  

      def tearDown(self):

-         super(TestErrataAdvisoryRPMsSignedHandler, self).tearDown()

+         super(TestRebuildImagesOnRPMAdvisoryChange, self).tearDown()

          self.patcher.unpatch_all()

  

      def test_can_handle_manual_rebuild_with_advisory_event(self):

@@ -228,12 +228,12 @@ 

                             security_impact="",

                             product_short_name="product"),

              ["foo-container", "bar-container"])

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          ret = handler.can_handle(event)

          self.assertTrue(ret)

  

      @patch.object(freshmaker.conf, 'handler_build_whitelist', new={

-         'ErrataAdvisoryRPMsSignedHandler': {

+         'RebuildImagesOnRPMAdvisoryChange': {

              'image': {'product_short_name': 'foo'}

          }

      })

@@ -244,14 +244,14 @@ 

          db.session.commit()

  

          self.mock_find_images_to_rebuild.return_value = [[]]

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler.handle(self.rhba_event)

  

          db_event = Event.get(db.session, message_id='123')

          self.assertEqual(db_event.state, EventState.SKIPPED.value)

  

      @patch.object(freshmaker.conf, 'handler_build_whitelist', new={

-         'ErrataAdvisoryRPMsSignedHandler': {

+         'RebuildImagesOnRPMAdvisoryChange': {

              'image': {

                  'advisory_highest_cve_severity': ['critical', 'important']

              }

@@ -266,7 +266,7 @@ 

          for severity in ["moderate", "critical", "important"]:

              self.rhba_event.advisory.highest_cve_severity = severity

              self.mock_find_images_to_rebuild.return_value = [[]]

-             handler = ErrataAdvisoryRPMsSignedHandler()

+             handler = RebuildImagesOnRPMAdvisoryChange()

              handler.handle(self.rhba_event)

  

              db_event = Event.get(db.session, message_id='123')

@@ -280,7 +280,7 @@ 

                      "No container images to rebuild for advisory 'RHBA-2017'")

  

      @patch.object(freshmaker.conf, 'handler_build_whitelist', new={

-         'ErrataAdvisoryRPMsSignedHandler': {

+         'RebuildImagesOnRPMAdvisoryChange': {

              'image': {

                  'advisory_has_hightouch_bug': True,

              }

@@ -295,7 +295,7 @@ 

          for has_hightouch_bug in [False, True]:

              self.rhba_event.advisory.has_hightouch_bug = has_hightouch_bug

              self.mock_find_images_to_rebuild.return_value = [[]]

-             handler = ErrataAdvisoryRPMsSignedHandler()

+             handler = RebuildImagesOnRPMAdvisoryChange()

              handler.handle(self.rhba_event)

  

              db_event = Event.get(db.session, message_id='123')

@@ -309,13 +309,13 @@ 

                      "No container images to rebuild for advisory 'RHBA-2017'")

  

      @patch.object(freshmaker.conf, 'handler_build_whitelist', new={

-         'ErrataAdvisoryRPMsSignedHandler': {

+         'RebuildImagesOnRPMAdvisoryChange': {

              'image': {'advisory_name': 'RHBA-2017'}

          }

      })

      def test_event_state_updated_when_no_images_to_rebuild(self):

          self.mock_find_images_to_rebuild.return_value = [[]]

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler.handle(self.rhba_event)

  

          db_event = Event.get(db.session, message_id='123')

@@ -325,7 +325,7 @@ 

              "No container images to rebuild for advisory 'RHBA-2017'")

  

      @patch.object(freshmaker.conf, 'handler_build_whitelist', new={

-         'ErrataAdvisoryRPMsSignedHandler': {

+         'RebuildImagesOnRPMAdvisoryChange': {

              'image': {'advisory_name': 'RHBA-2017'}

          }

      })

@@ -333,7 +333,7 @@ 

          self.image_a['error'] = "foo"

          self.mock_find_images_to_rebuild.return_value = [

              [self.image_a]]

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler.handle(self.rhba_event)

  

          db_event = Event.get(db.session, message_id='123')

@@ -342,15 +342,15 @@ 

              db_event.state_reason,

              "No container images to rebuild, all are in failed state.")

  

-     @patch('freshmaker.handlers.errata.ErrataAdvisoryRPMsSignedHandler.'

+     @patch('freshmaker.handlers.koji.RebuildImagesOnRPMAdvisoryChange.'

             'allow_build', return_value=True)

      @patch('freshmaker.odcsclient.FreshmakerODCSClient.prepare_yum_repos_for_rebuilds')

-     @patch('freshmaker.handlers.errata.ErrataAdvisoryRPMsSignedHandler.'

+     @patch('freshmaker.handlers.koji.RebuildImagesOnRPMAdvisoryChange.'

             'start_to_build_images')

      def test_rebuild_if_errata_state_is_prior_to_SHIPPED_LIVE(

              self, start_to_build_images, prepare_yum_repos_for_rebuilds,

              allow_build):

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler.handle(self.rhsa_event)

  

          prepare_yum_repos_for_rebuilds.assert_called_once()

@@ -359,10 +359,10 @@ 

          db_event = Event.get(db.session, self.rhsa_event.msg_id)

          self.assertEqual(EventState.BUILDING.value, db_event.state)

  

-     @patch('freshmaker.handlers.errata.ErrataAdvisoryRPMsSignedHandler.'

+     @patch('freshmaker.handlers.koji.RebuildImagesOnRPMAdvisoryChange.'

             'allow_build', return_value=True)

      @patch('freshmaker.odcsclient.FreshmakerODCSClient.prepare_yum_repos_for_rebuilds')

-     @patch('freshmaker.handlers.errata.ErrataAdvisoryRPMsSignedHandler.'

+     @patch('freshmaker.handlers.koji.RebuildImagesOnRPMAdvisoryChange.'

             'start_to_build_images')

      @patch('freshmaker.models.Event.get_image_builds_in_first_batch')

      def test_rebuild_if_errata_state_is_SHIPPED_LIVE(

@@ -373,7 +373,7 @@ 

              ErrataAdvisory(123, "RHSA-2017", "SHIPPED_LIVE", [],

                             security_impact="",

                             product_short_name="product"))

-         handler = ErrataAdvisoryRPMsSignedHandler()

+         handler = RebuildImagesOnRPMAdvisoryChange()

          handler.handle(event)

  

          prepare_yum_repos_for_rebuilds.assert_not_called()

@@ -390,7 +390,7 @@ 

          super(TestFindImagesToRebuild, self).setUp()

  

          self.patcher = helpers.Patcher(

-             "freshmaker.handlers.errata.ErrataAdvisoryRPMsSignedHandler.")

+             "freshmaker.handlers.koji.RebuildImagesOnRPMAdvisoryChange.")

  

          self.get_content_set_by_repo_ids = self.patcher.patch(

              'freshmaker.pulp.Pulp.get_content_set_by_repo_ids',

@@ -419,7 +419,7 @@ 

                             security_impact="",

                             product_short_name="product"),

              ["foo", "bar"])

-         self.handler = ErrataAdvisoryRPMsSignedHandler()

+         self.handler = RebuildImagesOnRPMAdvisoryChange()

          self.handler.event = self.event

  

      def tearDown(self):

@@ -427,7 +427,7 @@ 

          self.patcher.unpatch_all()

  

      @patch.object(freshmaker.conf, 'handler_build_whitelist', new={

-         'ErrataAdvisoryRPMsSignedHandler': {

+         'RebuildImagesOnRPMAdvisoryChange': {

              'image': {'advisory_name': 'RHBA-*'}

          }

      })

@@ -443,7 +443,7 @@ 

              leaf_container_images=None)

  

      @patch.object(freshmaker.conf, 'handler_build_whitelist', new={

-         'ErrataAdvisoryRPMsSignedHandler': {

+         'RebuildImagesOnRPMAdvisoryChange': {

              'image': {'advisory_name': 'RHBA-*'}

          }

      })

@@ -460,7 +460,7 @@ 

              leaf_container_images=None)

  

      @patch.object(freshmaker.conf, 'handler_build_whitelist', new={

-         'ErrataAdvisoryRPMsSignedHandler': {

+         'RebuildImagesOnRPMAdvisoryChange': {

              'image': any_({'advisory_name': 'RHBA-*', 'published': True,

                             'advisory_product_short_name': 'foo'},

                            {'advisory_name': 'RHBA-*', 'published': False,

@@ -479,7 +479,7 @@ 

              leaf_container_images=None)

  

      @patch.object(freshmaker.conf, 'handler_build_whitelist', new={

-         'ErrataAdvisoryRPMsSignedHandler': {

+         'RebuildImagesOnRPMAdvisoryChange': {

              'image': {'advisory_name': 'RHBA-*',

                        'published': True}

          }

@@ -496,7 +496,7 @@ 

              leaf_container_images=None)

  

      @patch.object(freshmaker.conf, 'handler_build_whitelist', new={

-         'ErrataAdvisoryRPMsSignedHandler': {

+         'RebuildImagesOnRPMAdvisoryChange': {

              'image': {'advisory_name': 'RHBA-*',

                        'published': True}

          }

tests/handlers/koji/test_rebuild_images_on_rpm_bodhi_update.py tests/test_bodhi_update_complete_stable_handler.py
file renamed
+14 -14

@@ -32,7 +32,7 @@ 

  

  from freshmaker import events, models

  from freshmaker.types import ArtifactType

- from freshmaker.handlers.bodhi import BodhiUpdateCompleteStableHandler

+ from freshmaker.handlers.koji import RebuildImagesOnRPMBodhiUpdate

  from freshmaker.parsers.bodhi import BodhiUpdateCompleteStableParser

  

  mock_found_containers = [

@@ -90,24 +90,24 @@ 

      return mock_release_components[id]

  

  

- class BodhiUpdateCompleteStableHandlerTest(helpers.ModelsTestCase):

+ class RebuildImagesOnRPMBodhiUpdateTest(helpers.ModelsTestCase):

      def setUp(self):

-         super(BodhiUpdateCompleteStableHandlerTest, self).setUp()

+         super(RebuildImagesOnRPMBodhiUpdateTest, self).setUp()

          events.BaseEvent.register_parser(BodhiUpdateCompleteStableParser)

  

-     @mock.patch('freshmaker.handlers.bodhi.update_complete_stable.PDC')

-     @mock.patch('freshmaker.handlers.bodhi.update_complete_stable.utils')

-     @mock.patch('freshmaker.handlers.bodhi.update_complete_stable.conf')

+     @mock.patch('freshmaker.handlers.koji.rebuild_images_on_rpm_bodhi_update.PDC')

+     @mock.patch('freshmaker.handlers.koji.rebuild_images_on_rpm_bodhi_update.utils')

+     @mock.patch('freshmaker.handlers.koji.rebuild_images_on_rpm_bodhi_update.conf')

      @mock.patch.object(freshmaker.conf, 'handler_build_whitelist', new={

-         'BodhiUpdateCompleteStableHandler': {

+         'RebuildImagesOnRPMBodhiUpdate': {

              'image': {'name': r'testimage\d', 'branch': 'f25'}

          }

      })

-     def test_trigger_rebuild_container_when_receives_bodhi_update_complete_stable_message(self, conf, utils, PDC):

+     def test_trigger_rebuild_container_when_receives_bodhi_rebuild_images_on_rpm_bodhi_update_message(self, conf, utils, PDC):

  

          conf.git_base_url = 'git://pkgs.fedoraproject.org'

  

-         handler = BodhiUpdateCompleteStableHandler()

+         handler = RebuildImagesOnRPMBodhiUpdate()

          handler.get_rpms_included_in_bodhi_update = mock.Mock()

  

          handler.get_containers_including_rpms = mock.Mock()

@@ -159,9 +159,9 @@ 

          self.assertEqual(builds[1].type, ArtifactType.IMAGE.value)

          self.assertEqual(builds[1].build_id, 456)

  

-     @mock.patch('freshmaker.handlers.bodhi.update_complete_stable.PDC')

-     @mock.patch('freshmaker.handlers.bodhi.update_complete_stable.utils')

-     @mock.patch('freshmaker.handlers.bodhi.update_complete_stable.conf')

+     @mock.patch('freshmaker.handlers.koji.rebuild_images_on_rpm_bodhi_update.PDC')

+     @mock.patch('freshmaker.handlers.koji.rebuild_images_on_rpm_bodhi_update.utils')

+     @mock.patch('freshmaker.handlers.koji.rebuild_images_on_rpm_bodhi_update.conf')

      def test_get_containers_including_rpms(self, conf, utils, PDC):

          expected_found_containers = [

              {

@@ -180,7 +180,7 @@ 

          pdc = PDC(conf)

          pdc.find_containers_by_rpm_name.return_value = expected_found_containers

  

-         handler = BodhiUpdateCompleteStableHandler()

+         handler = RebuildImagesOnRPMBodhiUpdate()

          rpms = [

              {'id': 9515683,

               'name': 'community-mysql-devel',

@@ -236,7 +236,7 @@ 

                  'version': '5.7.18',

              }

          ]

-         handler = BodhiUpdateCompleteStableHandler()

+         handler = RebuildImagesOnRPMBodhiUpdate()

          rpms = list(handler.get_rpms_included_in_bodhi_update(builds))

  

          self.assertEqual(5, len(rpms))

tests/handlers/mbs/__init__.py freshmaker/handlers/errata/__init__.py
file renamed
+3 -4

@@ -1,5 +1,5 @@ 

  # -*- coding: utf-8 -*-

- # Copyright (c) 2017  Red Hat, Inc.

+ # Copyright (c) 2016  Red Hat, Inc.

  #

  # Permission is hereby granted, free of charge, to any person obtaining a copy

  # of this software and associated documentation files (the "Software"), to deal

@@ -18,6 +18,5 @@ 

  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE

  # SOFTWARE.

- 

- from .errata_advisory_rpms_signed import ErrataAdvisoryRPMsSignedHandler  # noqa

- from .errata_advisory_state_changed import ErrataAdvisoryStateChangedHandler  # noqa

+ #

+ # Written by Jan Kaluza <jkaluza@redhat.com>

tests/handlers/mbs/test_rebuild_modules_on_git_mmd_change.py tests/test_git_module_metadata_change_handler.py
file renamed
+6 -6

@@ -30,14 +30,14 @@ 

  

  from freshmaker import events, models

  from freshmaker.types import ArtifactType

- from freshmaker.handlers.git import GitModuleMetadataChangeHandler

+ from freshmaker.handlers.mbs import RebuildModulesOnGitMMDChange

  from freshmaker.parsers.git import GitReceiveParser

  from freshmaker.config import any_

  

  

- class GitModuleMetadataChangeHandlerTest(helpers.ModelsTestCase):

+ class RebuildModulesOnGitMMDChangeTest(helpers.ModelsTestCase):

      def setUp(self):

-         super(GitModuleMetadataChangeHandlerTest, self).setUp()

+         super(RebuildModulesOnGitMMDChangeTest, self).setUp()

          events.BaseEvent.register_parser(GitReceiveParser)

  

      def test_can_handle_module_metadata_change_event(self):

@@ -50,11 +50,11 @@ 

  

          event = self.get_event_from_msg(msg)

  

-         handler = GitModuleMetadataChangeHandler()

+         handler = RebuildModulesOnGitMMDChange()

          self.assertTrue(handler.can_handle(event))

  

      @mock.patch.object(freshmaker.conf, 'handler_build_whitelist', new={

-         'GitModuleMetadataChangeHandler': {

+         'RebuildModulesOnGitMMDChange': {

              'module': any_({'name': 'testmodule'}, {'branch': 'master'})

          }

      })

@@ -68,7 +68,7 @@ 

  

          event = self.get_event_from_msg(msg)