Change ModuleBuild.context to db column

1. Changed ModuleBuild's context property to db column, it's
non-nullable and default value is '00000000' to keep it consistent
with previous behaviour.

2. Changed ModuleBuild.contexts_from_mmd to return a tuple of
(ref_build_context, build_context, runtime_context, context).

3. Updated tests affected by this change.
This commit is contained in:
Qixiang Wan
2018-04-28 09:47:31 +08:00
parent 8b807a9fcd
commit d83e6897ca
16 changed files with 232 additions and 168 deletions

View File

@@ -0,0 +1,46 @@
"""Add ModuleBuild.context
Revision ID: c8e2fc555399
Revises: caeae7a4f537
Create Date: 2018-04-26 22:57:11.398121
"""
# revision identifiers, used by Alembic.
revision = 'c8e2fc555399'
down_revision = 'caeae7a4f537'
from alembic import op
import sqlalchemy as sa
import hashlib
modulebuild = sa.Table(
'module_builds',
sa.MetaData(),
sa.Column('id', sa.Integer, primary_key=True),
sa.Column('modulemd', sa.String()),
sa.Column('build_context', sa.String()),
sa.Column('runtime_context', sa.String()),
sa.Column('context', sa.String()),
)
def upgrade():
connection = op.get_bind()
op.add_column('module_builds', sa.Column('context', sa.String(), nullable=False, server_default='00000000'))
for build in connection.execute(modulebuild.select()):
if build.build_context and build.runtime_context:
combined_hashes = '{0}:{1}'.format(
build.build_context, build.runtime_context).encode('utf-8')
context = hashlib.sha1(combined_hashes).hexdigest()[:8]
connection.execute(
modulebuild.update().where(modulebuild.c.id == build.id).values(
context=context))
def downgrade():
with op.batch_alter_table('module_builds') as b:
b.drop_column('context')

View File

@@ -173,6 +173,7 @@ class ModuleBuild(MBSBase):
ref_build_context = db.Column(db.String)
build_context = db.Column(db.String)
runtime_context = db.Column(db.String)
context = db.Column(db.String, server_default='00000000')
state = db.Column(db.Integer, nullable=False)
state_reason = db.Column(db.String)
modulemd = db.Column(db.String, nullable=False)
@@ -347,14 +348,17 @@ class ModuleBuild(MBSBase):
@staticmethod
def contexts_from_mmd(mmd_str):
"""
Returns tuple (ref_build_context, build_context, runtime_context) with hashes:
Returns tuple (ref_build_context, build_context, runtime_context, context)
with hashes:
- ref_build_context - Hash of commit hashes of expanded buildrequires.
- build_context - Hash of stream names of expanded buildrequires.
- runtime_context - Hash of stream names of expanded runtime requires.
- context - Hash of combined hashes of build_context and runtime_context.
:param str mmd_str: String with Modulemd metadata.
:rtype: tuple of strings
:return: Tuple with build_context, strem_build_context and runtime_context hashes.
:return: Tuple with build_context, strem_build_context, runtime_context and
context hashes.
"""
try:
mmd = Modulemd.Module().new_from_string(mmd_str)
@@ -378,7 +382,8 @@ class ModuleBuild(MBSBase):
mmd_formatted_buildrequires = {
dep: info['stream'] for dep, info in mbs_xmd["buildrequires"].items()}
property_json = json.dumps(OrderedDict(sorted(mmd_formatted_buildrequires.items())))
rv.append(hashlib.sha1(property_json).hexdigest())
build_context = hashlib.sha1(property_json).hexdigest()
rv.append(build_context)
# Get the requires from the real "dependencies" section in MMD.
mmd_requires = {}
@@ -392,24 +397,15 @@ class ModuleBuild(MBSBase):
mmd_requires = {
dep: sorted(list(streams)) for dep, streams in mmd_requires.items()}
property_json = json.dumps(OrderedDict(sorted(mmd_requires.items())))
rv.append(hashlib.sha1(property_json.encode('utf-8')).hexdigest())
runtime_context = hashlib.sha1(property_json.encode('utf-8')).hexdigest()
rv.append(runtime_context)
combined_hashes = '{0}:{1}'.format(build_context, runtime_context).encode('utf-8')
context = hashlib.sha1(combined_hashes).hexdigest()[:8]
rv.append(context)
return tuple(rv)
@staticmethod
def context_from_contexts(build_context, runtime_context):
if build_context and runtime_context:
combined_hashes = '{0}:{1}'.format(build_context, runtime_context).encode('utf-8')
return hashlib.sha1(combined_hashes).hexdigest()[:8]
else:
# We can't compute the context because the necessary data isn't there, so return a
# default value
return '00000000'
@property
def context(self):
return ModuleBuild.context_from_contexts(self.build_context, self.runtime_context)
@property
def siblings(self):
query = self.query.filter_by(

View File

@@ -290,6 +290,7 @@ def import_mmd(session, mmd):
build.koji_tag = koji_tag
build.state = models.BUILD_STATES['ready']
build.modulemd = mmd.dumps()
build.context = context
build.owner = "mbs_import"
build.rebuild_strategy = 'all'
build.time_submitted = datetime.utcnow()

View File

@@ -359,9 +359,8 @@ def generate_expanded_mmds(session, mmd, raise_if_stream_ambigous=False, default
mmd_copy.set_xmd(glib.dict_values(xmd))
# Now we have all the info to actually compute context of this module.
ref_build_context, build_context, runtime_context = \
ref_build_context, build_context, runtime_context, context = \
models.ModuleBuild.contexts_from_mmd(mmd_copy.dumps())
context = models.ModuleBuild.context_from_contexts(build_context, runtime_context)
mmd_copy.set_context(context)
mmds.append(mmd_copy)

View File

@@ -377,8 +377,8 @@ def submit_module_build(username, url, mmd, scm, optional_params=None):
username=username,
**(optional_params or {})
)
module.ref_build_context, module.build_context, module.runtime_context = \
module.contexts_from_mmd(module.modulemd)
(module.ref_build_context, module.build_context, module.runtime_context,
module.context) = module.contexts_from_mmd(module.modulemd)
db.session.add(module)
db.session.commit()

View File

@@ -122,6 +122,8 @@ def _populate_data(session, data_size=10, contexts=False):
build_one.build_context = unique_hash
build_one.runtime_context = unique_hash
build_one.ref_build_context = unique_hash
combined_hashes = '{0}:{1}'.format(unique_hash, unique_hash)
build_one.context = hashlib.sha1(combined_hashes).hexdigest()[:8]
with open(os.path.join(base_dir, "staged_data", "nginx_mmd.yaml")) as mmd:
build_one.modulemd = mmd.read()
build_one.koji_tag = 'module-nginx-1.2'
@@ -298,6 +300,7 @@ def scheduler_init_data(tangerine_state=None):
build_one.state = BUILD_STATES['build']
build_one.build_context = 'ac4de1c346dcf09ce77d38cd4e75094ec1c08eb0'
build_one.runtime_context = 'ac4de1c346dcf09ce77d38cd4e75094ec1c08eb0'
build_one.context = '7c29193d'
build_one.koji_tag = 'module-testmodule-master-20170109091357-7c29193d'
build_one.scmurl = 'git://pkgs.stg.fedoraproject.org/modules/testmodule.git?#ff1ea79'
if tangerine_state:
@@ -403,6 +406,7 @@ def reuse_component_init_data():
build_one.ref_build_context = 'ac4de1c346dcf09ce77d38cd4e75094ec1c08eb0'
build_one.runtime_context = 'ac4de1c346dcf09ce77d38cd4e75094ec1c08eb0'
build_one.build_context = 'ac4de1c346dcf09ce77d38cd4e75094ec1c08eb1'
build_one.context = '78e4a6fd'
build_one.koji_tag = 'module-testmodule-master-20170109091357-78e4a6fd'
build_one.scmurl = 'git://pkgs.stg.fedoraproject.org/modules/testmodule.git?#ff1ea79'
build_one.batch = 3
@@ -487,7 +491,8 @@ def reuse_component_init_data():
build_two.ref_build_context = 'ac4de1c346dcf09ce77d38cd4e75094ec1c08eb0'
build_two.runtime_context = 'ac4de1c346dcf09ce77d38cd4e75094ec1c08eb0'
build_two.build_context = 'ac4de1c346dcf09ce77d38cd4e75094ec1c08eb1'
build_two.koji_tag = 'module-fe3adf73caf3e1b7'
build_two.context = 'c40c156c'
build_two.koji_tag = 'module-testmodule-master-20170219191323-c40c156c'
build_two.scmurl = 'git://pkgs.stg.fedoraproject.org/modules/testmodule.git?#55f4a0a'
build_two.batch = 1
build_two.owner = 'Tom Brady'

View File

@@ -278,15 +278,6 @@ class FakeModuleBuilder(GenericBuilder):
return msgs
original_context_from_contexts = models.ModuleBuild.context_from_contexts
def mocked_context_from_contexts(build_context, runtime_context):
if build_context == "return_runtime_context":
return runtime_context
return original_context_from_contexts(build_context, runtime_context)
def cleanup_moksha():
# Necessary to restart the twisted reactor for the next test.
import sys
@@ -773,9 +764,9 @@ class TestBuild:
# Check that components are tagged after the batch is built.
tag_groups = []
tag_groups.append(set(
['perl-Tangerine-0.23-1.module+0+a43e2001',
'perl-List-Compare-0.53-5.module+0+a43e2001',
'tangerine-0.22-3.module+0+a43e2001']))
['perl-Tangerine-0.23-1.module+0+d027b723',
'perl-List-Compare-0.53-5.module+0+d027b723',
'tangerine-0.22-3.module+0+d027b723']))
def on_tag_artifacts_cb(cls, artifacts, dest_tag=True):
if dest_tag is True:
@@ -784,9 +775,9 @@ class TestBuild:
buildtag_groups = []
buildtag_groups.append(set(
['perl-Tangerine-0.23-1.module+0+a43e2001',
'perl-List-Compare-0.53-5.module+0+a43e2001',
'tangerine-0.22-3.module+0+a43e2001']))
['perl-Tangerine-0.23-1.module+0+d027b723',
'perl-List-Compare-0.53-5.module+0+d027b723',
'tangerine-0.22-3.module+0+d027b723']))
def on_buildroot_add_artifacts_cb(cls, artifacts, install):
assert buildtag_groups.pop(0) == set(artifacts)
@@ -829,9 +820,9 @@ class TestBuild:
# Check that components are tagged after the batch is built.
tag_groups = []
tag_groups.append(set(
['perl-Tangerine-0.23-1.module+0+a43e2001',
'perl-List-Compare-0.53-5.module+0+a43e2001',
'tangerine-0.22-3.module+0+a43e2001']))
['perl-Tangerine-0.23-1.module+0+d027b723',
'perl-List-Compare-0.53-5.module+0+d027b723',
'tangerine-0.22-3.module+0+d027b723']))
def on_tag_artifacts_cb(cls, artifacts, dest_tag=True):
if dest_tag is True:
@@ -840,9 +831,9 @@ class TestBuild:
buildtag_groups = []
buildtag_groups.append(set(
['perl-Tangerine-0.23-1.module+0+a43e2001',
'perl-List-Compare-0.53-5.module+0+a43e2001',
'tangerine-0.22-3.module+0+a43e2001']))
['perl-Tangerine-0.23-1.module+0+d027b723',
'perl-List-Compare-0.53-5.module+0+d027b723',
'tangerine-0.22-3.module+0+d027b723']))
def on_buildroot_add_artifacts_cb(cls, artifacts, install):
assert buildtag_groups.pop(0) == set(artifacts)
@@ -862,15 +853,11 @@ class TestBuild:
@patch('module_build_service.auth.get_user', return_value=user)
@patch('module_build_service.scm.SCM')
@patch("module_build_service.models.ModuleBuild.context_from_contexts")
def test_submit_build_resume(self, context_from_contexts, mocked_scm, mocked_get_user,
conf_system, dbg):
def test_submit_build_resume(self, mocked_scm, mocked_get_user, conf_system, dbg):
"""
Tests that resuming the build works even when previous batches
are already built.
"""
context_from_contexts.side_effect = mocked_context_from_contexts
now = datetime.utcnow()
submitted_time = now - timedelta(minutes=3)
# Create a module in the failed state
@@ -881,13 +868,14 @@ class TestBuild:
build_one.build_context = 'return_runtime_context'
build_one.ref_build_context = 'return_runtime_context'
build_one.runtime_context = '9c690d0e'
build_one.context = '9c690d0e'
build_one.state = models.BUILD_STATES['failed']
current_dir = os.path.dirname(__file__)
formatted_testmodule_yml_path = os.path.join(
current_dir, '..', 'staged_data', 'formatted_testmodule.yaml')
with open(formatted_testmodule_yml_path, 'r') as f:
build_one.modulemd = f.read()
build_one.koji_tag = 'module-95b214a704c984be'
build_one.koji_tag = 'module-testmodule-master-20180205135154-9c690d0e'
build_one.scmurl = 'git://pkgs.stg.fedoraproject.org/modules/testmodule.git?#7fea453'
build_one.batch = 2
build_one.owner = 'Homer J. Simpson'
@@ -912,7 +900,7 @@ class TestBuild:
component_one.format = 'rpms'
component_one.scmurl = 'git://pkgs.stg.fedoraproject.org/rpms/perl-Tangerine.git?#master'
component_one.state = koji.BUILD_STATES['COMPLETE']
component_one.nvr = 'perl-Tangerine-0:0.22-2.module+0+a43e2001'
component_one.nvr = 'perl-Tangerine-0:0.22-2.module+0+d027b723'
component_one.batch = 2
component_one.module_id = 2
component_one.ref = '7e96446223f1ad84a26c7cf23d6591cd9f6326c6'
@@ -988,16 +976,12 @@ class TestBuild:
@patch('module_build_service.auth.get_user', return_value=user)
@patch('module_build_service.scm.SCM')
@patch("module_build_service.models.ModuleBuild.context_from_contexts")
def test_submit_build_resume_recover_orphaned_macros(
self, context_from_contexts, mocked_scm, mocked_get_user,
conf_system, dbg):
self, mocked_scm, mocked_get_user, conf_system, dbg):
"""
Tests that resuming the build works when module-build-macros is orphaned but marked as
failed in the database
"""
context_from_contexts.side_effect = mocked_context_from_contexts
FakeModuleBuilder.INSTANT_COMPLETE = True
now = datetime.utcnow()
submitted_time = now - timedelta(minutes=3)
@@ -1010,12 +994,15 @@ class TestBuild:
build_one.ref_build_context = 'return_runtime_context'
build_one.runtime_context = '9c690d0e'
build_one.state = models.BUILD_STATES['failed']
# this is not calculated by real but just a value to
# match the calculated context from expanded test mmd
build_one.context = '9c690d0e'
current_dir = os.path.dirname(__file__)
formatted_testmodule_yml_path = os.path.join(
current_dir, '..', 'staged_data', 'formatted_testmodule.yaml')
with open(formatted_testmodule_yml_path, 'r') as f:
build_one.modulemd = f.read()
build_one.koji_tag = 'module-95b214a704c984be'
build_one.koji_tag = 'module-testmodule-master-20180205135154-6ef9a711'
build_one.scmurl = 'git://pkgs.stg.fedoraproject.org/modules/testmodule.git?#7fea453'
build_one.batch = 2
build_one.owner = 'Homer J. Simpson'

View File

@@ -47,7 +47,7 @@ GET_USER_RV = {
class TestBuild:
def setup_method(self, test_method):
init_data(1)
init_data(1, contexts=True)
module = models.ModuleBuild.query.filter_by(id=2).one()
module.cg_build_koji_tag = "f27-module-candidate"
self.cg = KojiContentGenerator(module, conf)
@@ -173,7 +173,7 @@ class TestBuild:
self.cg._tag_cg_build()
koji_session.getTag.assert_called_once_with(self.cg.module.cg_build_koji_tag)
koji_session.tagBuild.assert_called_once_with(123, "nginx-1-2.00000000")
koji_session.tagBuild.assert_called_once_with(123, "nginx-0-2.10e50d06")
@patch("module_build_service.builder.KojiModuleBuilder.KojiModuleBuilder.get_session")
def test_tag_cg_build_fallback_to_default_tag(self, get_session):
@@ -188,7 +188,7 @@ class TestBuild:
assert koji_session.getTag.mock_calls == [
call(self.cg.module.cg_build_koji_tag),
call(conf.koji_cg_default_build_tag)]
koji_session.tagBuild.assert_called_once_with(123, "nginx-1-2.00000000")
koji_session.tagBuild.assert_called_once_with(123, "nginx-0-2.10e50d06")
@patch("module_build_service.builder.KojiModuleBuilder.KojiModuleBuilder.get_session")
def test_tag_cg_build_no_tag_set(self, get_session):

View File

@@ -638,17 +638,17 @@
],
"metadata_version": 0,
"build": {
"version": "1",
"version": "0",
"end_time": 1472901932,
"name": "nginx",
"release": "2.00000000",
"release": "2.10e50d06",
"owner": "Moe Szyslak",
"extra": {
"typeinfo": {
"module": {
"name": "nginx",
"context": "00000000",
"stream": "1",
"context": "10e50d06",
"stream": "0",
"version": "2",
"module_build_service_id": 2,
"content_koji_tag": "module-nginx-1.2",

View File

@@ -647,17 +647,17 @@
],
"metadata_version": 0,
"build": {
"version": "1",
"version": "0",
"end_time": 1472901932,
"name": "nginx",
"release": "2.00000000",
"release": "2.10e50d06",
"owner": "Moe Szyslak",
"extra": {
"typeinfo": {
"module": {
"name": "nginx",
"context": "00000000",
"stream": "1",
"context": "10e50d06",
"stream": "0",
"version": "2",
"module_build_service_id": 2,
"content_koji_tag": "module-nginx-1.2",

View File

@@ -67,8 +67,8 @@ class TestModels:
mmd = Modulemd.Module.new_from_file(yaml_path)
mmd.upgrade()
build.modulemd = mmd.dumps()
build.ref_build_context, build.build_context, build.runtime_context = \
ModuleBuild.contexts_from_mmd(build.modulemd)
(build.ref_build_context, build.build_context, build.runtime_context,
build.context) = ModuleBuild.contexts_from_mmd(build.modulemd)
assert build.ref_build_context == 'f6e2aeec7576196241b9afa0b6b22acf2b6873d7'
assert build.build_context == '089df24993c037e10174f3fa7342ab4dc191a4d4'
assert build.runtime_context == 'bbc84c7b817ab3dd54916c0bcd6c6bdf512f7f9c'

View File

@@ -59,7 +59,7 @@ class TestDBModule:
db.session.commit()
resolver = mbs_resolver.GenericResolver.create(tests.conf, backend='db')
result = resolver.get_module_build_dependencies(
'testmodule', 'master', '20170109091357', 'c40c156c').keys()
'testmodule', 'master', '20170109091357', '78e4a6fd').keys()
assert set(result) == expected
def test_get_module_build_dependencies_recursive(self):

View File

@@ -126,7 +126,8 @@ class TestPoller:
poller = MBSProducer(hub)
poller.poll()
koji_session.newRepo.assert_called_once_with("module-fe3adf73caf3e1b7-build")
koji_session.newRepo.assert_called_once_with(
"module-testmodule-master-20170219191323-c40c156c-build")
def test_trigger_new_repo_when_succeded(self, create_builder,
koji_get_session, global_consumer,
@@ -395,10 +396,10 @@ class TestPoller:
assert module_build_two.state == models.BUILD_STATES['failed']
# Make sure the builds were untagged
builder.untag_artifacts.assert_called_once_with([
'perl-Tangerine-0.23-1.module+0+a43e2001',
'perl-List-Compare-0.53-5.module+0+a43e2001',
'tangerine-0.22-3.module+0+a43e2001',
'module-build-macros-0.1-1.module+0+a43e2001'
'perl-Tangerine-0.23-1.module+0+d027b723',
'perl-List-Compare-0.53-5.module+0+d027b723',
'tangerine-0.22-3.module+0+d027b723',
'module-build-macros-0.1-1.module+0+d027b723'
])
def test_cleanup_stale_failed_builds_no_components(self, create_builder, koji_get_session,

View File

@@ -54,7 +54,9 @@ class TestTagTagged:
that we do nothing gracefully.
"""
msg = module_build_service.messaging.KojiTagChange(
'id', 'module-fe3adf73caf3e1b7-build', "artifact")
'id',
'module-testmodule-master-20170219191323-c40c156c-build',
"artifact")
module_build_service.scheduler.handlers.tags.tagged(
config=conf, session=db.session, msg=msg)
@@ -75,7 +77,8 @@ class TestTagTagged:
builder = mock.MagicMock()
builder.koji_session = koji_session
builder.buildroot_ready.return_value = False
builder.module_build_tag = {"name": "module-fe3adf73caf3e1b7-build"}
builder.module_build_tag = {
"name": "module-testmodule-master-20170219191323-c40c156c-build"}
create_builder.return_value = builder
module_build = module_build_service.models.ModuleBuild.query.filter_by(id=3).one()
@@ -94,12 +97,16 @@ class TestTagTagged:
# Tag the first component to the buildroot.
msg = module_build_service.messaging.KojiTagChange(
'id', 'module-fe3adf73caf3e1b7-build', "perl-Tangerine")
'id',
'module-testmodule-master-20170219191323-c40c156c-build',
"perl-Tangerine")
module_build_service.scheduler.handlers.tags.tagged(
config=conf, session=db.session, msg=msg)
# Tag the first component to the final tag.
msg = module_build_service.messaging.KojiTagChange(
'id', 'module-fe3adf73caf3e1b7', "perl-Tangerine")
'id',
'module-testmodule-master-20170219191323-c40c156c',
"perl-Tangerine")
module_build_service.scheduler.handlers.tags.tagged(
config=conf, session=db.session, msg=msg)
@@ -109,7 +116,9 @@ class TestTagTagged:
# Tag the second component to the buildroot.
msg = module_build_service.messaging.KojiTagChange(
'id', 'module-fe3adf73caf3e1b7-build', "perl-List-Compare")
'id',
'module-testmodule-master-20170219191323-c40c156c-build',
"perl-List-Compare")
module_build_service.scheduler.handlers.tags.tagged(
config=conf, session=db.session, msg=msg)
@@ -119,12 +128,15 @@ class TestTagTagged:
# Tag the first component to the final tag.
msg = module_build_service.messaging.KojiTagChange(
'id', 'module-fe3adf73caf3e1b7', "perl-List-Compare")
'id',
'module-testmodule-master-20170219191323-c40c156c',
"perl-List-Compare")
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-fe3adf73caf3e1b7-build")
koji_session.newRepo.assert_called_once_with(
"module-testmodule-master-20170219191323-c40c156c-build")
# Refresh our module_build object.
db.session.expunge(module_build)
@@ -151,7 +163,8 @@ class TestTagTagged:
builder = mock.MagicMock()
builder.koji_session = koji_session
builder.buildroot_ready.return_value = False
builder.module_build_tag = {"name": "module-fe3adf73caf3e1b7-build"}
builder.module_build_tag = {
"name": "module-testmodule-master-20170219191323-c40c156c-build"}
create_builder.return_value = builder
module_build = module_build_service.models.ModuleBuild.query.filter_by(id=3).one()
@@ -163,12 +176,16 @@ class TestTagTagged:
# Tag the perl-List-Compare component to the buildroot.
msg = module_build_service.messaging.KojiTagChange(
'id', 'module-fe3adf73caf3e1b7-build', "perl-Tangerine")
'id',
'module-testmodule-master-20170219191323-c40c156c-build',
"perl-Tangerine")
module_build_service.scheduler.handlers.tags.tagged(
config=conf, session=db.session, msg=msg)
# Tag the perl-List-Compare component to final tag.
msg = module_build_service.messaging.KojiTagChange(
'id', 'module-fe3adf73caf3e1b7', "perl-Tangerine")
'id',
'module-testmodule-master-20170219191323-c40c156c',
"perl-Tangerine")
module_build_service.scheduler.handlers.tags.tagged(
config=conf, session=db.session, msg=msg)
@@ -193,7 +210,8 @@ class TestTagTagged:
builder = mock.MagicMock()
builder.koji_session = koji_session
builder.buildroot_ready.return_value = False
builder.module_build_tag = {"name": "module-fe3adf73caf3e1b7-build"}
builder.module_build_tag = {
"name": "module-testmodule-master-20170219191323-c40c156c-build"}
create_builder.return_value = builder
module_build = module_build_service.models.ModuleBuild.query.filter_by(id=3).one()
@@ -216,18 +234,23 @@ class TestTagTagged:
# Tag the perl-List-Compare component to the buildroot.
msg = module_build_service.messaging.KojiTagChange(
'id', 'module-fe3adf73caf3e1b7-build', "perl-List-Compare")
'id',
'module-testmodule-master-20170219191323-c40c156c-build',
"perl-List-Compare")
module_build_service.scheduler.handlers.tags.tagged(
config=conf, session=db.session, msg=msg)
# Tag the perl-List-Compare component to final tag.
msg = module_build_service.messaging.KojiTagChange(
'id', 'module-fe3adf73caf3e1b7', "perl-List-Compare")
'id',
'module-testmodule-master-20170219191323-c40c156c',
"perl-List-Compare")
module_build_service.scheduler.handlers.tags.tagged(
config=conf, session=db.session, msg=msg)
# newRepo should be called now - all successfully built
# components have been tagged.
koji_session.newRepo.assert_called_once_with("module-fe3adf73caf3e1b7-build")
koji_session.newRepo.assert_called_once_with(
"module-testmodule-master-20170219191323-c40c156c-build")
# Refresh our module_build object.
db.session.expunge(module_build)
@@ -257,7 +280,8 @@ class TestTagTagged:
builder = mock.MagicMock()
builder.koji_session = koji_session
builder.buildroot_ready.return_value = False
builder.module_build_tag = {"name": "module-fe3adf73caf3e1b7-build"}
builder.module_build_tag = {
"name": "module-testmodule-master-20170219191323-c40c156c-build"}
create_builder.return_value = builder
module_build = module_build_service.models.ModuleBuild.query.filter_by(id=3).one()
@@ -272,12 +296,16 @@ class TestTagTagged:
# Tag the first component to the buildroot.
msg = module_build_service.messaging.KojiTagChange(
'id', 'module-fe3adf73caf3e1b7-build', "perl-Tangerine")
'id',
'module-testmodule-master-20170219191323-c40c156c-build',
"perl-Tangerine")
module_build_service.scheduler.handlers.tags.tagged(
config=conf, session=db.session, msg=msg)
# Tag the first component to the final tag.
msg = module_build_service.messaging.KojiTagChange(
'id', 'module-fe3adf73caf3e1b7', "perl-Tangerine")
'id',
'module-testmodule-master-20170219191323-c40c156c',
"perl-Tangerine")
module_build_service.scheduler.handlers.tags.tagged(
config=conf, session=db.session, msg=msg)
@@ -287,12 +315,16 @@ class TestTagTagged:
# Tag the second component to the buildroot.
msg = module_build_service.messaging.KojiTagChange(
'id', 'module-fe3adf73caf3e1b7-build', "perl-List-Compare")
'id',
'module-testmodule-master-20170219191323-c40c156c-build',
"perl-List-Compare")
module_build_service.scheduler.handlers.tags.tagged(
config=conf, session=db.session, msg=msg)
# Tag the second component to final tag.
msg = module_build_service.messaging.KojiTagChange(
'id', 'module-fe3adf73caf3e1b7', "perl-List-Compare")
'id',
'module-testmodule-master-20170219191323-c40c156c',
"perl-List-Compare")
module_build_service.scheduler.handlers.tags.tagged(
config=conf, session=db.session, msg=msg)
@@ -302,17 +334,22 @@ class TestTagTagged:
# Tag the component from first batch to final tag.
msg = module_build_service.messaging.KojiTagChange(
'id', 'module-fe3adf73caf3e1b7', "module-build-macros")
'id',
'module-testmodule-master-20170219191323-c40c156c',
"module-build-macros")
module_build_service.scheduler.handlers.tags.tagged(
config=conf, session=db.session, msg=msg)
# Tag the component from first batch to the buildroot.
msg = module_build_service.messaging.KojiTagChange(
'id', 'module-fe3adf73caf3e1b7-build', "module-build-macros")
'id',
'module-testmodule-master-20170219191323-c40c156c-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-fe3adf73caf3e1b7-build")
koji_session.newRepo.assert_called_once_with(
"module-testmodule-master-20170219191323-c40c156c-build")
# Refresh our module_build object.
db.session.expunge(module_build)
@@ -340,7 +377,8 @@ class TestTagTagged:
builder = mock.MagicMock()
builder.koji_session = koji_session
builder.buildroot_ready.return_value = False
builder.module_build_tag = {"name": "module-fe3adf73caf3e1b7-build"}
builder.module_build_tag = {
"name": "module-testmodule-master-20170219191323-c40c156c-build"}
create_builder.return_value = builder
module_build = module_build_service.models.ModuleBuild.query.filter_by(id=3).one()
@@ -366,24 +404,31 @@ class TestTagTagged:
# Tag the perl-Tangerine component to the buildroot.
msg = module_build_service.messaging.KojiTagChange(
'id', 'module-fe3adf73caf3e1b7-build', "perl-Tangerine")
'id',
'module-testmodule-master-20170219191323-c40c156c-build',
"perl-Tangerine")
module_build_service.scheduler.handlers.tags.tagged(
config=conf, session=db.session, msg=msg)
assert not koji_session.newRepo.called
# Tag the perl-List-Compare component to the buildroot.
msg = module_build_service.messaging.KojiTagChange(
'id', 'module-fe3adf73caf3e1b7-build', "perl-List-Compare")
'id',
'module-testmodule-master-20170219191323-c40c156c-build',
"perl-List-Compare")
module_build_service.scheduler.handlers.tags.tagged(
config=conf, session=db.session, msg=msg)
# Tag the perl-List-Compare component to final tag.
msg = module_build_service.messaging.KojiTagChange(
'id', 'module-fe3adf73caf3e1b7', "perl-List-Compare")
'id',
'module-testmodule-master-20170219191323-c40c156c',
"perl-List-Compare")
module_build_service.scheduler.handlers.tags.tagged(
config=conf, session=db.session, msg=msg)
# newRepo should be called now - all successfully built
# components have been tagged.
koji_session.newRepo.assert_called_once_with("module-fe3adf73caf3e1b7-build")
koji_session.newRepo.assert_called_once_with(
"module-testmodule-master-20170219191323-c40c156c-build")
# Refresh our module_build object.
db.session.expunge(module_build)

View File

@@ -21,7 +21,6 @@
from datetime import datetime
from mock import patch
import pytest
import module_build_service.utils
@@ -35,24 +34,8 @@ class TestUtilsModuleStreamExpansion:
def setup_method(self, test_method):
clean_database(False)
def mocked_context(build_context, runtime_context):
"""
Changes the ModuleBuild.context behaviour to return
ModuleBuild.build_context instead of computing new context hash.
"""
return build_context[:8]
# For these tests, we need the ModuleBuild.context to return the well-known
# context as we define it in test data. Therefore patch the ModuleBuild.context
# to return ModuleBuild.build_context, which we can control.
self.modulebuild_context_patcher = patch(
"module_build_service.models.ModuleBuild.context_from_contexts")
modulebuild_context = self.modulebuild_context_patcher.start()
modulebuild_context.side_effect = mocked_context
def teardown_method(self, test_method):
clean_database()
self.modulebuild_context_patcher.stop()
def _make_module(self, nsvc, requires_list, build_requires_list):
"""
@@ -108,6 +91,7 @@ class TestUtilsModuleStreamExpansion:
module_build.name = name
module_build.stream = stream
module_build.version = version
module_build.context = context
module_build.state = models.BUILD_STATES['ready']
module_build.scmurl = 'git://pkgs.stg.fedoraproject.org/modules/unused.git?#ff1ea79'
module_build.batch = 1
@@ -161,7 +145,7 @@ class TestUtilsModuleStreamExpansion:
mmds = module_build_service.utils.generate_expanded_mmds(
db.session, module_build.mmd())
contexts = set([mmd.get_context() for mmd in mmds])
assert set(['ea432ace', 'b613fe68']) == contexts
assert set(['e1e005fb', 'ce132a1e']) == contexts
@pytest.mark.parametrize(
'requires,build_requires,stream_ambigous,expected_xmd,expected_buildrequires', [

View File

@@ -239,72 +239,72 @@ class TestViews:
items = json.loads(rv.data)['items']
expected = [
{
"state_name": "wait",
"context": "00000000",
"id": 7,
"koji_tag": None,
"name": "testmodule",
"tasks": {
"rpms": {
"module-build-macros": {
"state": 1,
"state_reason": None,
"task_id": 47383994,
"nvr": "module-build-macros-01-1.module+7+f95651e2"
},
"rubygem-rails": {
"state": 3,
"state_reason": None,
"task_id": 2433434,
"nvr": "postgresql-9.5.3-4.module+7+f95651e2"
}
}
},
"owner": "some_other_user",
"version": "7",
"state_reason": None,
"state": 1,
"stream": "4.3.43",
"time_submitted": "2016-09-03T12:38:33Z",
"rebuild_strategy": "changed-and-after",
"scmurl": ("git://pkgs.domain.local/modules/testmodule"
"?#ca95886c7a443b36a9ce31abda1f9bef22f2f8c9"),
"id": 7,
"context": "00000000",
"time_completed": None,
"time_modified": "2016-09-03T12:38:40Z",
"rebuild_strategy": "changed-and-after",
"koji_tag": None
},
{
"state_name": "done",
"name": "postgressql",
"state": 1,
"state_name": "wait",
"state_reason": None,
"stream": "4.3.43",
"tasks": {
"rpms": {
"module-build-macros": {
"nvr": "module-build-macros-01-1.module+7+f95651e2",
"state": 1,
"state_reason": None,
"task_id": 47383994,
"nvr": "module-build-macros-01-1.module+6+fa947d31"
"task_id": 47383994
},
"postgresql": {
"state": 1,
"rubygem-rails": {
"nvr": "postgresql-9.5.3-4.module+7+f95651e2",
"state": 3,
"state_reason": None,
"task_id": 2433434,
"nvr": "postgresql-9.5.3-4.module+6+fa947d31"
"task_id": 2433434
}
}
},
"time_completed": None,
"time_modified": "2016-09-03T12:38:40Z",
"time_submitted": "2016-09-03T12:38:33Z",
"version": "7"
},
{
"context": "00000000",
"id": 6,
"koji_tag": "module-postgressql-1.2",
"name": "postgressql",
"owner": "some_user",
"version": "3",
"state_reason": None,
"state": 3,
"stream": "1",
"time_submitted": "2016-09-03T12:35:33Z",
"rebuild_strategy": "changed-and-after",
"scmurl": ("git://pkgs.domain.local/modules/postgressql"
"?#aa95886c7a443b36a9ce31abda1f9bef22f2f8c9"),
"id": 6,
"context": "00000000",
"state": 3,
"state_name": "done",
"state_reason": None,
"stream": "1",
"tasks": {
"rpms": {
"module-build-macros": {
"nvr": "module-build-macros-01-1.module+6+fa947d31",
"state": 1,
"state_reason": None,
"task_id": 47383994
},
"postgresql": {
"nvr": "postgresql-9.5.3-4.module+6+fa947d31",
"state": 1,
"state_reason": None,
"task_id": 2433434
}
}
},
"time_completed": "2016-09-03T11:37:19Z",
"time_modified": "2016-09-03T12:37:19Z",
"rebuild_strategy": "changed-and-after",
"koji_tag": "module-postgressql-1.2"
"time_submitted": "2016-09-03T12:35:33Z",
"version": "3"
}
]