mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-12-01 00:37:08 +08:00
Do not build module-build-macros when all the components will be reused from previous module build.
This commit is contained in:
@@ -36,13 +36,14 @@ from module_build_service import db, models, conf
|
||||
|
||||
from mock import patch, PropertyMock
|
||||
|
||||
from tests import app, init_data
|
||||
from tests import app, init_data, test_reuse_component_init_data
|
||||
import os
|
||||
import json
|
||||
import itertools
|
||||
|
||||
from module_build_service.builder import KojiModuleBuilder, GenericBuilder
|
||||
import module_build_service.scheduler.consumer
|
||||
from module_build_service.messaging import MBSModule
|
||||
|
||||
base_dir = dirname(dirname(__file__))
|
||||
cassette_dir = base_dir + '/vcr-request-data/'
|
||||
@@ -628,3 +629,107 @@ class TestBuild(unittest.TestCase):
|
||||
# We should end up with batch 2 and never start batch 3, because
|
||||
# there were failed components in batch 2.
|
||||
self.assertEqual(c.module_build.batch, 2)
|
||||
|
||||
@timed(30)
|
||||
@patch('module_build_service.auth.get_user', return_value=user)
|
||||
@patch('module_build_service.scm.SCM')
|
||||
def test_submit_build_reuse_all(self, mocked_scm, mocked_get_user,
|
||||
conf_system, dbg):
|
||||
"""
|
||||
Tests that we do not try building module-build-macros when reusing all
|
||||
components in a module build.
|
||||
"""
|
||||
test_reuse_component_init_data()
|
||||
|
||||
def on_build_cb(cls, artifact_name, source):
|
||||
raise ValueError("All components should be reused, not build.")
|
||||
TestModuleBuilder.on_build_cb = on_build_cb
|
||||
|
||||
# Check that components are tagged after the batch is built.
|
||||
tag_groups = []
|
||||
tag_groups.append(set(
|
||||
['perl-Tangerine-0.23-1.module_testmodule_master_20170109091357',
|
||||
'perl-List-Compare-0.53-5.module_testmodule_master_20170109091357',
|
||||
'tangerine-0.22-3.module_testmodule_master_20170109091357']))
|
||||
|
||||
def on_tag_artifacts_cb(cls, artifacts):
|
||||
self.assertEqual(tag_groups.pop(0), set(artifacts))
|
||||
TestModuleBuilder.on_tag_artifacts_cb = on_tag_artifacts_cb
|
||||
|
||||
buildtag_groups = []
|
||||
buildtag_groups.append(set(
|
||||
['perl-Tangerine-0.23-1.module_testmodule_master_20170109091357',
|
||||
'perl-List-Compare-0.53-5.module_testmodule_master_20170109091357',
|
||||
'tangerine-0.22-3.module_testmodule_master_20170109091357']))
|
||||
def on_buildroot_add_artifacts_cb(cls, artifacts, install):
|
||||
self.assertEqual(buildtag_groups.pop(0), set(artifacts))
|
||||
TestModuleBuilder.on_buildroot_add_artifacts_cb = on_buildroot_add_artifacts_cb
|
||||
|
||||
msgs = [MBSModule("local module build", 2, 1)]
|
||||
stop = module_build_service.scheduler.make_simple_stop_condition(db.session)
|
||||
module_build_service.scheduler.main(msgs, stop)
|
||||
|
||||
reused_component_ids = {"module-build-macros": None, "tangerine": 3,
|
||||
"perl-Tangerine": 1, "perl-List-Compare": 2}
|
||||
|
||||
# All components should be built and module itself should be in "done"
|
||||
# or "ready" state.
|
||||
for build in models.ComponentBuild.query.filter_by(module_id=2).all():
|
||||
self.assertEqual(build.state, koji.BUILD_STATES['COMPLETE'])
|
||||
self.assertTrue(build.module_build.state in [models.BUILD_STATES["done"], models.BUILD_STATES["ready"]])
|
||||
|
||||
self.assertEqual(build.reused_component_id,
|
||||
reused_component_ids[build.package])
|
||||
|
||||
@timed(30)
|
||||
@patch('module_build_service.auth.get_user', return_value=user)
|
||||
@patch('module_build_service.scm.SCM')
|
||||
def test_submit_build_reuse_all_without_build_macros(self, mocked_scm, mocked_get_user,
|
||||
conf_system, dbg):
|
||||
"""
|
||||
Tests that we can reuse components even when the reused module does
|
||||
not have module-build-macros component.
|
||||
"""
|
||||
test_reuse_component_init_data()
|
||||
|
||||
models.ComponentBuild.query.filter_by(package="module-build-macros").delete()
|
||||
self.assertEqual(len(models.ComponentBuild.query.filter_by(
|
||||
package="module-build-macros").all()), 0)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
def on_build_cb(cls, artifact_name, source):
|
||||
raise ValueError("All components should be reused, not build.")
|
||||
TestModuleBuilder.on_build_cb = on_build_cb
|
||||
|
||||
# Check that components are tagged after the batch is built.
|
||||
tag_groups = []
|
||||
tag_groups.append(set(
|
||||
['perl-Tangerine-0.23-1.module_testmodule_master_20170109091357',
|
||||
'perl-List-Compare-0.53-5.module_testmodule_master_20170109091357',
|
||||
'tangerine-0.22-3.module_testmodule_master_20170109091357']))
|
||||
|
||||
def on_tag_artifacts_cb(cls, artifacts):
|
||||
self.assertEqual(tag_groups.pop(0), set(artifacts))
|
||||
TestModuleBuilder.on_tag_artifacts_cb = on_tag_artifacts_cb
|
||||
|
||||
buildtag_groups = []
|
||||
buildtag_groups.append(set(
|
||||
['perl-Tangerine-0.23-1.module_testmodule_master_20170109091357',
|
||||
'perl-List-Compare-0.53-5.module_testmodule_master_20170109091357',
|
||||
'tangerine-0.22-3.module_testmodule_master_20170109091357']))
|
||||
def on_buildroot_add_artifacts_cb(cls, artifacts, install):
|
||||
self.assertEqual(buildtag_groups.pop(0), set(artifacts))
|
||||
TestModuleBuilder.on_buildroot_add_artifacts_cb = on_buildroot_add_artifacts_cb
|
||||
|
||||
msgs = [MBSModule("local module build", 2, 1)]
|
||||
stop = module_build_service.scheduler.make_simple_stop_condition(db.session)
|
||||
module_build_service.scheduler.main(msgs, stop)
|
||||
|
||||
# All components should be built and module itself should be in "done"
|
||||
# or "ready" state.
|
||||
for build in models.ComponentBuild.query.filter_by(module_id=2).all():
|
||||
self.assertEqual(build.state, koji.BUILD_STATES['COMPLETE'])
|
||||
self.assertTrue(build.module_build.state in [models.BUILD_STATES["done"], models.BUILD_STATES["ready"]] )
|
||||
self.assertNotEqual(build.package, "module-build-macros")
|
||||
|
||||
|
||||
@@ -84,6 +84,13 @@ class TestTagTagged(unittest.TestCase):
|
||||
create_builder.return_value = builder
|
||||
|
||||
module_build = module_build_service.models.ModuleBuild.query.filter_by(id=2).one()
|
||||
|
||||
# Set previous components as COMPLETE and tagged.
|
||||
module_build.batch = 1
|
||||
for c in module_build.up_to_current_batch():
|
||||
c.state = koji.BUILD_STATES["COMPLETE"]
|
||||
c.tagged = True
|
||||
|
||||
module_build.batch = 2
|
||||
for c in module_build.current_batch():
|
||||
c.state = koji.BUILD_STATES["COMPLETE"]
|
||||
@@ -173,6 +180,13 @@ class TestTagTagged(unittest.TestCase):
|
||||
create_builder.return_value = builder
|
||||
|
||||
module_build = module_build_service.models.ModuleBuild.query.filter_by(id=2).one()
|
||||
|
||||
# Set previous components as COMPLETE and tagged.
|
||||
module_build.batch = 1
|
||||
for c in module_build.up_to_current_batch():
|
||||
c.state = koji.BUILD_STATES["COMPLETE"]
|
||||
c.tagged = True
|
||||
|
||||
module_build.batch = 2
|
||||
component = module_build_service.models.ComponentBuild.query\
|
||||
.filter_by(package='perl-Tangerine', module_id=module_build.id).one()
|
||||
@@ -199,3 +213,68 @@ class TestTagTagged(unittest.TestCase):
|
||||
# newRepo task_id should be stored in database, so we can check its
|
||||
# status later in poller.
|
||||
self.assertEqual(module_build.new_repo_task_id, 123456)
|
||||
|
||||
@patch("module_build_service.builder.GenericBuilder.default_buildroot_groups",
|
||||
return_value = {'build': [], 'srpm-build': []})
|
||||
@patch("module_build_service.builder.KojiModuleBuilder.get_session")
|
||||
@patch("module_build_service.builder.GenericBuilder.create_from_module")
|
||||
def test_newrepo_multiple_batches_tagged(
|
||||
self, create_builder, koji_get_session, dbg):
|
||||
"""
|
||||
Test that newRepo is called just once and only when all components
|
||||
are tagged even if we tag components from the multiple batches in the
|
||||
same time.
|
||||
"""
|
||||
koji_session = mock.MagicMock()
|
||||
koji_session.getTag = lambda tag_name: {'name': tag_name}
|
||||
koji_session.getTaskInfo.return_value = {'state': koji.TASK_STATES['CLOSED']}
|
||||
koji_session.newRepo.return_value = 123456
|
||||
koji_get_session.return_value = koji_session
|
||||
|
||||
builder = mock.MagicMock()
|
||||
builder.koji_session = koji_session
|
||||
builder.buildroot_ready.return_value = False
|
||||
create_builder.return_value = builder
|
||||
|
||||
module_build = module_build_service.models.ModuleBuild.query.filter_by(id=2).one()
|
||||
module_build.batch = 2
|
||||
for c in module_build.current_batch():
|
||||
c.state = koji.BUILD_STATES["COMPLETE"]
|
||||
db.session.commit()
|
||||
|
||||
# Tag the first component to the buildroot.
|
||||
msg = module_build_service.messaging.KojiTagChange(
|
||||
'id', 'module-testmodule-build', "perl-Tangerine")
|
||||
module_build_service.scheduler.handlers.tags.tagged(
|
||||
config=conf, session=db.session, msg=msg)
|
||||
|
||||
# newRepo should not be called, because there are still components
|
||||
# to tag.
|
||||
self.assertTrue(not koji_session.newRepo.called)
|
||||
|
||||
# Tag the second component to the buildroot.
|
||||
msg = module_build_service.messaging.KojiTagChange(
|
||||
'id', 'module-testmodule-build', "perl-List-Compare")
|
||||
module_build_service.scheduler.handlers.tags.tagged(
|
||||
config=conf, session=db.session, msg=msg)
|
||||
|
||||
# newRepo should not be called, because there are still components
|
||||
# to tag.
|
||||
self.assertTrue(not koji_session.newRepo.called)
|
||||
|
||||
# Tag the component from first batch to the buildroot.
|
||||
msg = module_build_service.messaging.KojiTagChange(
|
||||
'id', 'module-testmodule-build', "module-build-macros")
|
||||
module_build_service.scheduler.handlers.tags.tagged(
|
||||
config=conf, session=db.session, msg=msg)
|
||||
|
||||
# newRepo should be called now - all components have been tagged.
|
||||
koji_session.newRepo.assert_called_once_with("module-testmodule-build")
|
||||
|
||||
# Refresh our module_build object.
|
||||
db.session.expunge(module_build)
|
||||
module_build = module_build_service.models.ModuleBuild.query.filter_by(id=2).one()
|
||||
|
||||
# newRepo task_id should be stored in database, so we can check its
|
||||
# status later in poller.
|
||||
self.assertEqual(module_build.new_repo_task_id, 123456)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user