From ac0bd8ceb8871ae742f9b744d2f1923a0dde3c51 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Mar 04 2019 09:03:47 +0000 Subject: Set `time_completed` before calling KojiContentGenerator. The `KojiContentGenerator.finalize()` needs the `ModuleBuild.time_completed`. We currently set `time_completed` once the module build transitions into `done` state. But we have moved the `KojiContentGenerator` call to end of `build` state, so right now it is called before the `time_completed` is set. This leads to traceback. In this commit, the `time_completed` is set before the `KojiContentGenerator` call, so it is defined properly. --- diff --git a/module_build_service/scheduler/handlers/repos.py b/module_build_service/scheduler/handlers/repos.py index be9e9a2..95cb994 100644 --- a/module_build_service/scheduler/handlers/repos.py +++ b/module_build_service/scheduler/handlers/repos.py @@ -26,6 +26,7 @@ import module_build_service.builder import logging import koji +from datetime import datetime from module_build_service import models, log from module_build_service.utils import start_next_batch_build @@ -149,6 +150,7 @@ def done(config, session, msg): state_reason=state_reason) else: # Tell the external buildsystem to wrap up (CG import, createrepo, etc.) + module_build.time_completed = datetime.utcnow() builder.finalize() module_build.transition(config, state=models.BUILD_STATES['done']) diff --git a/tests/test_scheduler/test_repo_done.py b/tests/test_scheduler/test_repo_done.py index b916464..df1b1cc 100644 --- a/tests/test_scheduler/test_repo_done.py +++ b/tests/test_scheduler/test_repo_done.py @@ -101,6 +101,20 @@ class TestRepoDone: get_session.return_value = mock.Mock(), 'development' build_fn.return_value = 1234, 1, '', None + # Ensure the time_completed is None, so we can test it is set to + # some date once the build is finalized. + module_build = module_build_service.models.ModuleBuild.query.get(2) + module_build.time_completed = None + db.session.commit() + + def mocked_finalizer(): + # Check that the time_completed is set in the time when + # finalizer is called. + module_build = module_build_service.models.ModuleBuild.query.get(2) + assert module_build.time_completed is not None + + finalizer.side_effect = mocked_finalizer + msg = module_build_service.messaging.KojiRepoChange( 'some_msg_id', 'module-testmodule-master-20170109091357-7c29193d-build') module_build_service.scheduler.handlers.repos.done(