Remove config argument from event handlers

For the purpose of migrating to Celery to run event handler inside a
worker, Config object is not serializable. And from the usage of config
argument, every event handler can just access module_build_service.conf
directly. This removal would make the migration easier.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
This commit is contained in:
Chenxiong Qi
2019-10-29 16:19:50 +08:00
committed by mprahl
parent 5a883f6cc6
commit 55612d7baf
12 changed files with 92 additions and 125 deletions

View File

@@ -75,7 +75,7 @@ class TestDecisionUpdateHandler:
@patch("module_build_service.scheduler.handlers.greenwave.log")
def test_decision_context_is_not_match(self, log):
msg = Mock(msg_id="msg-id-1", decision_context="bodhi_update_push_testing")
decision_update(conf, msg)
decision_update(msg)
log.debug.assert_called_once_with(
'Skip Greenwave message %s as MBS only handles messages with the decision context "%s"',
"msg-id-1",
@@ -90,7 +90,7 @@ class TestDecisionUpdateHandler:
policies_satisfied=False,
subject_identifier="pkg-0.1-1.c1",
)
decision_update(conf, msg)
decision_update(msg)
log.debug.assert_called_once_with(
"Skip to handle module build %s because it has not satisfied Greenwave policies.",
msg.subject_identifier,

View File

@@ -72,7 +72,7 @@ class TestModuleInit:
db_session.commit()
msg = MBSModule(msg_id=None, module_build_id=2, module_build_state="init")
self.fn(config=conf, msg=msg)
self.fn(msg=msg)
build = ModuleBuild.get_by_id(db_session, 2)
# Make sure the module entered the wait state
@@ -113,7 +113,7 @@ class TestModuleInit:
)
msg = MBSModule(msg_id=None, module_build_id=2, module_build_state="init")
self.fn(config=conf, msg=msg)
self.fn(msg=msg)
build = ModuleBuild.get_by_id(db_session, 2)
# Make sure the module entered the failed state
@@ -139,7 +139,7 @@ class TestModuleInit:
ModuleBuild.create(
db_session, conf, "includemodule", "1", 3, mmd_to_str(mmd), scmurl, "mprahl")
msg = MBSModule(msg_id=None, module_build_id=3, module_build_state="init")
self.fn(config=conf, msg=msg)
self.fn(msg=msg)
build = ModuleBuild.get_by_id(db_session, 3)
assert build.state == 1
assert build.name == "includemodule"
@@ -177,7 +177,7 @@ class TestModuleInit:
build = ModuleBuild.get_by_id(db_session, 2)
mocked_from_module_event.return_value = build
self.fn(config=conf, msg=msg)
self.fn(msg=msg)
# Query the database again to make sure the build object is updated
db_session.refresh(build)

View File

@@ -46,7 +46,7 @@ class TestModuleWait:
module_build_id=module_build_id,
module_build_state="some state")
with patch("module_build_service.resolver.GenericResolver.create"):
self.fn(config=self.config, msg=msg)
self.fn(msg=msg)
@patch(
"module_build_service.builder.GenericBuilder.default_buildroot_groups",
@@ -83,8 +83,7 @@ class TestModuleWait:
generic_resolver.create.return_value = resolver
msg = MBSModule(msg_id=None, module_build_id=2, module_build_state="some state")
module_build_service.scheduler.handlers.modules.wait(
config=conf, msg=msg)
module_build_service.scheduler.handlers.modules.wait(msg=msg)
koji_session.newRepo.assert_called_once_with("module-123-build")
@@ -129,8 +128,7 @@ class TestModuleWait:
generic_resolver.create.return_value = resolver
msg = MBSModule(msg_id=None, module_build_id=2, module_build_state="some state")
module_build_service.scheduler.handlers.modules.wait(
config=conf, msg=msg)
module_build_service.scheduler.handlers.modules.wait(msg=msg)
assert koji_session.newRepo.called
@@ -174,8 +172,7 @@ class TestModuleWait:
generic_resolver.create.return_value = resolver
msg = MBSModule(msg_id=None, module_build_id=2, module_build_state="some state")
module_build_service.scheduler.handlers.modules.wait(
config=conf, msg=msg)
module_build_service.scheduler.handlers.modules.wait(msg=msg)
module_build = ModuleBuild.get_by_id(db_session, 2)
assert module_build.cg_build_koji_tag == "modular-updates-candidate"
@@ -243,8 +240,6 @@ class TestModuleWait:
):
generic_resolver.create.return_value = resolver
msg = MBSModule(msg_id=None, module_build_id=2, module_build_state="some state")
module_build_service.scheduler.handlers.modules.wait(
config=conf, msg=msg
)
module_build_service.scheduler.handlers.modules.wait(msg=msg)
module_build = ModuleBuild.get_by_id(db_session, 2)
assert module_build.cg_build_koji_tag == expected_cg_koji_build_tag

View File

@@ -8,7 +8,7 @@ import module_build_service.models
from module_build_service.db_session import db_session
from module_build_service.models import ComponentBuild
from module_build_service.scheduler.events import KojiRepoChange
from tests import conf, scheduler_init_data
from tests import scheduler_init_data
class TestRepoDone:
@@ -22,7 +22,7 @@ class TestRepoDone:
from_repo_done_event.return_value = None
msg = KojiRepoChange(
"no matches for this...", "2016-some-nonexistent-build")
module_build_service.scheduler.handlers.repos.done(config=conf, msg=msg)
module_build_service.scheduler.handlers.repos.done(msg=msg)
@mock.patch(
"module_build_service.builder.KojiModuleBuilder."
@@ -59,7 +59,7 @@ class TestRepoDone:
msg = KojiRepoChange(
"some_msg_id", "module-testmodule-master-20170109091357-7c29193d-build")
module_build_service.scheduler.handlers.repos.done(config=conf, msg=msg)
module_build_service.scheduler.handlers.repos.done(msg=msg)
build_fn.assert_called_once_with(
artifact_name="tangerine",
source=(
@@ -119,7 +119,7 @@ class TestRepoDone:
msg = KojiRepoChange(
"some_msg_id", "module-testmodule-master-20170109091357-7c29193d-build")
module_build_service.scheduler.handlers.repos.done(config=conf, msg=msg)
module_build_service.scheduler.handlers.repos.done(msg=msg)
finalizer.assert_called_once()
@@ -159,7 +159,7 @@ class TestRepoDone:
msg = KojiRepoChange(
"some_msg_id", "module-testmodule-master-20170109091357-7c29193d-build")
module_build_service.scheduler.handlers.repos.done(config=conf, msg=msg)
module_build_service.scheduler.handlers.repos.done(msg=msg)
build_fn.assert_called_once_with(
artifact_name="tangerine",
source=(
@@ -186,7 +186,7 @@ class TestRepoDone:
msg = KojiRepoChange(
"some_msg_id", "module-testmodule-master-20170109091357-7c29193d-build")
module_build_service.scheduler.handlers.repos.done(config=conf, msg=msg)
module_build_service.scheduler.handlers.repos.done(msg=msg)
mock_log_info.assert_called_with(
"Ignoring repo regen, because not all components are tagged."
@@ -225,7 +225,7 @@ class TestRepoDone:
msg = KojiRepoChange(
"some_msg_id", "module-testmodule-master-20170109091357-7c29193d-build")
module_build_service.scheduler.handlers.repos.done(config=conf, msg=msg)
module_build_service.scheduler.handlers.repos.done(msg=msg)
module_build = module_build_service.models.ModuleBuild.get_by_id(db_session, 2)
assert module_build.state == module_build_service.models.BUILD_STATES["failed"]

View File

@@ -11,7 +11,6 @@ import module_build_service.scheduler.handlers.tags
import module_build_service.models
from module_build_service.scheduler.events import KojiTagChange
from tests import conf
from module_build_service.db_session import db_session
import koji
@@ -28,8 +27,7 @@ class TestTagTagged:
from_tag_change_event.return_value = None
msg = KojiTagChange(
"no matches for this...", "2016-some-nonexistent-build", "artifact", "artifact-1.2-1")
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
def test_no_matching_artifact(self):
""" Test that when a tag msg hits us and we have no match,
@@ -41,8 +39,7 @@ class TestTagTagged:
"artifact",
"artifact-1.2-1",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
@patch(
"module_build_service.builder.GenericBuilder.default_buildroot_groups",
@@ -94,9 +91,7 @@ class TestTagTagged:
"perl-Tangerine",
"perl-Tangerine-0.23-1.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg
)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# Tag the first component to the final tag.
msg = KojiTagChange(
"id",
@@ -104,9 +99,7 @@ class TestTagTagged:
"perl-Tangerine",
"perl-Tangerine-0.23-1.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg
)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# newRepo should not be called, because there are still components
# to tag.
@@ -119,9 +112,7 @@ class TestTagTagged:
"perl-List-Compare",
"perl-List-Compare-0.53-5.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg
)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# newRepo should not be called, because the component has not been
# tagged to final tag so far.
@@ -134,8 +125,7 @@ class TestTagTagged:
"perl-List-Compare",
"perl-List-Compare-0.53-5.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# newRepo should be called now - all components have been tagged.
koji_session.newRepo.assert_called_once_with(
@@ -190,8 +180,7 @@ class TestTagTagged:
"perl-Tangerine",
"perl-Tangerine-0.23-1.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# Tag the perl-List-Compare component to final tag.
msg = KojiTagChange(
"id",
@@ -199,8 +188,7 @@ class TestTagTagged:
"perl-Tangerine",
"perl-Tangerine-0.23-1.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# newRepo should not be called, because perl-List-Compare has not been
# built yet.
@@ -260,9 +248,7 @@ class TestTagTagged:
"perl-List-Compare",
"perl-List-Compare-0.53-5.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg
)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# Tag the perl-List-Compare component to final tag.
msg = KojiTagChange(
"id",
@@ -270,8 +256,7 @@ class TestTagTagged:
"perl-List-Compare",
"perl-List-Compare-0.53-5.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# newRepo should be called now - all successfully built
# components have been tagged.
@@ -336,8 +321,7 @@ class TestTagTagged:
"perl-Tangerine",
"perl-Tangerine-0.23-1.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# Tag the first component to the final tag.
msg = KojiTagChange(
"id",
@@ -345,8 +329,7 @@ class TestTagTagged:
"perl-Tangerine",
"perl-Tangerine-0.23-1.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# newRepo should not be called, because there are still components
# to tag.
@@ -359,8 +342,7 @@ class TestTagTagged:
"perl-List-Compare",
"perl-List-Compare-0.53-5.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# Tag the second component to final tag.
msg = KojiTagChange(
"id",
@@ -368,8 +350,7 @@ class TestTagTagged:
"perl-List-Compare",
"perl-List-Compare-0.53-5.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# newRepo should not be called, because there are still components
# to tag.
@@ -382,8 +363,7 @@ class TestTagTagged:
"module-build-macros",
"module-build-macros-0.1-1.module+0+b0a1d1f7",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# Tag the component from first batch to the buildroot.
msg = KojiTagChange(
"id",
@@ -391,8 +371,7 @@ class TestTagTagged:
"module-build-macros",
"module-build-macros-0.1-1.module+0+b0a1d1f7",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# newRepo should be called now - all components have been tagged.
koji_session.newRepo.assert_called_once_with(
@@ -463,8 +442,7 @@ class TestTagTagged:
"perl-Tangerine",
"perl-Tangerine-0.23-1.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
assert not koji_session.newRepo.called
# Tag the perl-List-Compare component to the buildroot.
msg = KojiTagChange(
@@ -473,8 +451,7 @@ class TestTagTagged:
"perl-List-Compare",
"perl-List-Compare-0.53-5.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# Tag the perl-List-Compare component to final tag.
msg = KojiTagChange(
"id",
@@ -482,8 +459,7 @@ class TestTagTagged:
"perl-List-Compare",
"perl-List-Compare-0.53-5.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# newRepo should be called now - all successfully built
# components have been tagged.
@@ -562,8 +538,7 @@ class TestTagTagged:
"perl-Tangerine",
"perl-Tangerine-0.23-1.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# Tag the first component to the final tag.
msg = KojiTagChange(
"id",
@@ -571,8 +546,7 @@ class TestTagTagged:
"perl-Tangerine",
"perl-Tangerine-0.23-1.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# Tag the second component to the buildroot.
msg = KojiTagChange(
"id",
@@ -580,8 +554,7 @@ class TestTagTagged:
"perl-List-Compare",
"perl-List-Compare-0.53-5.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# Tag the second component to the final tag.
msg = KojiTagChange(
"id",
@@ -589,8 +562,7 @@ class TestTagTagged:
"perl-List-Compare",
"perl-List-Compare-0.53-5.module+0+d027b723",
)
module_build_service.scheduler.handlers.tags.tagged(
config=conf, msg=msg)
module_build_service.scheduler.handlers.tags.tagged(msg=msg)
# All components are tagged, newRepo should be called if there are no active tasks.
if expect_new_repo:

View File

@@ -1238,7 +1238,7 @@ class TestBatches:
# the components just once.
for msg in further_work:
if type(msg) == KojiBuildChange:
module_build_service.scheduler.handlers.components.complete(conf, msg)
module_build_service.scheduler.handlers.components.complete(msg)
# Since we have reused all the components in the batch, there should
# be fake KojiRepoChange message.