mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-05 03:38:12 +08:00
Change the names of these classmethods to be a little more generic.
This commit is contained in:
@@ -146,10 +146,10 @@ class ModuleBuild(Base):
|
||||
raise ValueError("%s: %s, not in %r" % (key, field, BUILD_STATES))
|
||||
|
||||
@classmethod
|
||||
def from_fedmsg(cls, session, msg):
|
||||
if '.module.' not in msg['topic']:
|
||||
raise ValueError("%r is not a module message." % msg['topic'])
|
||||
return session.query(cls).filter(cls.id==msg['msg']['id']).first()
|
||||
def from_module_event(cls, session, event):
|
||||
if '.module.' not in event['topic']:
|
||||
raise ValueError("%r is not a module message." % event['topic'])
|
||||
return session.query(cls).filter(cls.id==event['msg']['id']).first()
|
||||
|
||||
@classmethod
|
||||
def create(cls, session, conf, name, version, release, modulemd):
|
||||
@@ -188,19 +188,20 @@ class ModuleBuild(Base):
|
||||
.filter_by(state=BUILD_STATES[state]).all()
|
||||
|
||||
@classmethod
|
||||
def get_active_by_koji_tag(cls, session, koji_tag):
|
||||
def from_repo_done_event(cls, session, event):
|
||||
""" Find the ModuleBuilds in our database that should be in-flight...
|
||||
... for a given koji tag.
|
||||
|
||||
There should be at most one.
|
||||
"""
|
||||
query = session.query(rida.database.ModuleBuild)\
|
||||
.filter_by(koji_tag=koji_tag)\
|
||||
.filter_by(state=BUILD_STATES["build"])
|
||||
tag = event['msg']['tag'].strip('-build')
|
||||
query = session.query(cls)\
|
||||
.filter(cls.koji_tag==tag)\
|
||||
.filter(cls.state==BUILD_STATES["build"])
|
||||
|
||||
count = query.count()
|
||||
if count > 1:
|
||||
raise RuntimeError("%r module builds in flight for %r" % (count, koji_tag))
|
||||
raise RuntimeError("%r module builds in flight for %r" % (count, tag))
|
||||
|
||||
return query.first()
|
||||
|
||||
@@ -240,10 +241,10 @@ class ComponentBuild(Base):
|
||||
module_build = relationship('ModuleBuild', backref='component_builds', lazy=False)
|
||||
|
||||
@classmethod
|
||||
def from_fedmsg(cls, session, msg):
|
||||
if 'component.state.change' not in msg['topic'] and '.buildsys.build.state.change' not in msg['topic']:
|
||||
raise ValueError("%r is not a koji message." % msg['topic'])
|
||||
return session.query(cls).filter(cls.task_id==msg['msg']['task_id']).first()
|
||||
def from_component_event(cls, session, event):
|
||||
if 'component.state.change' not in event['topic'] and '.buildsys.build.state.change' not in event['topic']:
|
||||
raise ValueError("%r is not a koji message." % event['topic'])
|
||||
return session.query(cls).filter(cls.task_id==event['msg']['task_id']).first()
|
||||
|
||||
def json(self):
|
||||
return {
|
||||
|
||||
@@ -38,7 +38,7 @@ def _finalize(config, session, msg, state):
|
||||
""" Called whenever a koji build completes or fails. """
|
||||
|
||||
# First, find our ModuleBuild associated with this repo, if any.
|
||||
component_build = rida.database.ComponentBuild.from_fedmsg(session, msg)
|
||||
component_build = rida.database.ComponentBuild.from_component_event(session, msg)
|
||||
if not component_build:
|
||||
template = "We have no record of {name}-{version}-{release}"
|
||||
log.debug(template.format(**msg['msg']))
|
||||
|
||||
@@ -48,7 +48,7 @@ def wait(config, session, msg):
|
||||
The kicking off of individual component builds is handled elsewhere,
|
||||
in rida.schedulers.handlers.repos.
|
||||
"""
|
||||
build = rida.database.ModuleBuild.from_fedmsg(session, msg)
|
||||
build = rida.database.ModuleBuild.from_module_event(session, msg)
|
||||
module_info = build.json()
|
||||
if module_info['state'] != rida.BUILD_STATES["wait"]:
|
||||
# XXX: not sure why did we get here from state == 2 (building) FIXTHIS
|
||||
|
||||
@@ -38,8 +38,7 @@ def done(config, session, msg):
|
||||
|
||||
# First, find our ModuleBuild associated with this repo, if any.
|
||||
tag = msg['msg']['tag'].strip('-build')
|
||||
module_build = rida.database.ModuleBuild.get_active_by_koji_tag(
|
||||
session, koji_tag=tag)
|
||||
module_build = rida.database.ModuleBuild.from_repo_done_event(session, msg)
|
||||
if not module_build:
|
||||
log.info("No module build found associated with koji tag %r" % tag)
|
||||
return
|
||||
|
||||
@@ -34,9 +34,9 @@ class TestModuleWait(unittest.TestCase):
|
||||
self.fn = rida.scheduler.handlers.modules.wait
|
||||
|
||||
@mock.patch('rida.builder.KojiModuleBuilder')
|
||||
@mock.patch('rida.database.ModuleBuild.from_fedmsg')
|
||||
@mock.patch('rida.database.ModuleBuild.from_module_event')
|
||||
@mock.patch('rida.pdc.get_pdc_client_session')
|
||||
def test_wait_basic(self, pdc, from_fedmsg, KojiModuleBuilder):
|
||||
def test_wait_basic(self, pdc, from_module_event, KojiModuleBuilder):
|
||||
builder = mock.Mock()
|
||||
KojiModuleBuilder.return_value = builder
|
||||
mocked_module_build = mock.Mock()
|
||||
@@ -45,7 +45,7 @@ class TestModuleWait(unittest.TestCase):
|
||||
'version': 1,
|
||||
'release': 1,
|
||||
}
|
||||
from_fedmsg.return_value = mocked_module_build
|
||||
from_module_event.return_value = mocked_module_build
|
||||
|
||||
msg = {
|
||||
'topic': 'org.fedoraproject.prod.rida.module.state.change',
|
||||
|
||||
Reference in New Issue
Block a user