mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-05 03:38:12 +08:00
Use single session object in greenwave handler and call commit() in the end.
This commit is contained in:
@@ -235,7 +235,7 @@ class MBSConsumer(fedmsg.consumers.FedmsgConsumer):
|
||||
build = models.ModuleBuild.from_module_event(session, msg)
|
||||
elif type(msg) == module_build_service.messaging.GreenwaveDecisionUpdate:
|
||||
handler = self.on_decision_update
|
||||
build = greenwave.get_corresponding_module_build(msg.subject_identifier)
|
||||
build = greenwave.get_corresponding_module_build(session, msg.subject_identifier)
|
||||
else:
|
||||
return
|
||||
|
||||
|
||||
@@ -21,14 +21,15 @@
|
||||
#
|
||||
# Written by Chenxiong Qi <cqi@redhat.com>
|
||||
|
||||
from module_build_service import conf, db, log
|
||||
from module_build_service import conf, log
|
||||
from module_build_service.builder.KojiModuleBuilder import KojiModuleBuilder
|
||||
from module_build_service.models import ModuleBuild, BUILD_STATES
|
||||
|
||||
|
||||
def get_corresponding_module_build(nvr):
|
||||
def get_corresponding_module_build(session, nvr):
|
||||
"""Find corresponding module build from database and return
|
||||
|
||||
:param session: the SQLAlchemy database session object.
|
||||
:param str nvr: module build NVR. This is the subject_identifier included
|
||||
inside ``greenwave.decision.update`` message.
|
||||
:return: the corresponding module build object. For whatever the reason,
|
||||
@@ -48,7 +49,7 @@ def get_corresponding_module_build(nvr):
|
||||
# handling Greenwave event.
|
||||
return None
|
||||
|
||||
return ModuleBuild.get_by_id(db.session, module_build_id)
|
||||
return ModuleBuild.get_by_id(session, module_build_id)
|
||||
|
||||
|
||||
def decision_update(config, session, msg):
|
||||
@@ -88,7 +89,7 @@ def decision_update(config, session, msg):
|
||||
)
|
||||
return
|
||||
|
||||
build = get_corresponding_module_build(module_build_nvr)
|
||||
build = get_corresponding_module_build(session, module_build_nvr)
|
||||
|
||||
if build is None:
|
||||
log.debug(
|
||||
@@ -110,3 +111,5 @@ def decision_update(config, session, msg):
|
||||
module_build_nvr,
|
||||
msg.decision_context,
|
||||
)
|
||||
|
||||
session.commit()
|
||||
|
||||
@@ -43,7 +43,7 @@ class TestGetCorrespondingModuleBuild:
|
||||
def test_module_build_nvr_does_not_exist_in_koji(self, ClientSession):
|
||||
ClientSession.return_value.getBuild.return_value = None
|
||||
|
||||
assert get_corresponding_module_build("n-v-r") is None
|
||||
assert get_corresponding_module_build(db.session, "n-v-r") is None
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"build_info",
|
||||
@@ -60,7 +60,7 @@ class TestGetCorrespondingModuleBuild:
|
||||
def test_cannot_find_module_build_id_from_build_info(self, ClientSession, build_info):
|
||||
ClientSession.return_value.getBuild.return_value = build_info
|
||||
|
||||
assert get_corresponding_module_build("n-v-r") is None
|
||||
assert get_corresponding_module_build(db.session, "n-v-r") is None
|
||||
|
||||
@patch("module_build_service.builder.KojiModuleBuilder.KojiClientSession")
|
||||
def test_corresponding_module_build_id_does_not_exist_in_db(self, ClientSession):
|
||||
@@ -70,7 +70,7 @@ class TestGetCorrespondingModuleBuild:
|
||||
"extra": {"typeinfo": {"module": {"module_build_service_id": fake_module_build_id + 1}}}
|
||||
}
|
||||
|
||||
assert get_corresponding_module_build("n-v-r") is None
|
||||
assert get_corresponding_module_build(db.session, "n-v-r") is None
|
||||
|
||||
@patch("module_build_service.builder.KojiModuleBuilder.KojiClientSession")
|
||||
def test_find_the_module_build(self, ClientSession):
|
||||
@@ -82,7 +82,7 @@ class TestGetCorrespondingModuleBuild:
|
||||
"extra": {"typeinfo": {"module": {"module_build_service_id": expected_module_build.id}}}
|
||||
}
|
||||
|
||||
build = get_corresponding_module_build("n-v-r")
|
||||
build = get_corresponding_module_build(db.session, "n-v-r")
|
||||
|
||||
assert expected_module_build.id == build.id
|
||||
assert expected_module_build.name == build.name
|
||||
|
||||
Reference in New Issue
Block a user