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.
This commit is contained in:
Jan Kaluza
2019-03-04 07:25:06 +01:00
parent 152419f376
commit ac0bd8ceb8
2 changed files with 16 additions and 0 deletions

View File

@@ -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'])

View File

@@ -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(