mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-11-30 08:04:33 +08:00
New: Resolver API for pluggable resolvers
This commit is contained in:
@@ -34,7 +34,8 @@ from abc import ABCMeta, abstractmethod
|
||||
from requests.exceptions import ConnectionError
|
||||
|
||||
from module_build_service import conf, log, db
|
||||
from module_build_service import pdc, models
|
||||
from module_build_service import models
|
||||
import module_build_service.resolver
|
||||
import module_build_service.scm
|
||||
import module_build_service.utils
|
||||
from module_build_service.utils import create_dogpile_key_generator_func
|
||||
@@ -117,6 +118,13 @@ class GenericBuilder(six.with_metaclass(ABCMeta)):
|
||||
Any additional arguments are optional extras which can be passed along
|
||||
and are implementation-dependent.
|
||||
"""
|
||||
# check if the backend is within allowed backends for the used resolver
|
||||
resolver = module_build_service.resolver.GenericResolver.create(config)
|
||||
if not resolver.is_builder_compatible(backend):
|
||||
raise ValueError("Builder backend '{}' is not compatible with "
|
||||
"resolver backend '{}'. Check your configuration."
|
||||
.format(backend, resolver.backend))
|
||||
|
||||
if backend in GenericBuilder.backends:
|
||||
return GenericBuilder.backends[backend](owner=owner, module=module,
|
||||
config=config, **extra)
|
||||
@@ -309,16 +317,16 @@ class GenericBuilder(six.with_metaclass(ABCMeta)):
|
||||
|
||||
try:
|
||||
mmd = module.mmd()
|
||||
pdc_session = pdc.get_pdc_client_session(conf)
|
||||
resolver = module_build_service.resolver.GenericResolver.create(conf)
|
||||
|
||||
# Resolve default buildroot groups using the PDC, but only for
|
||||
# non-local modules.
|
||||
pdc_groups = pdc.resolve_profiles(pdc_session, mmd,
|
||||
('buildroot', 'srpm-buildroot'))
|
||||
groups = resolver.resolve_profiles(
|
||||
mmd, ('buildroot', 'srpm-buildroot'))
|
||||
|
||||
groups = {
|
||||
'build': pdc_groups['buildroot'],
|
||||
'srpm-build': pdc_groups['srpm-buildroot'],
|
||||
'build': groups['buildroot'],
|
||||
'srpm-build': groups['srpm-buildroot'],
|
||||
}
|
||||
except ValueError:
|
||||
reason = "Failed to gather buildroot groups from SCM."
|
||||
|
||||
@@ -37,6 +37,11 @@ from module_build_service import logger
|
||||
# currently relies on this file, so we can't import it
|
||||
SUPPORTED_STRATEGIES = ['changed-and-after', 'only-changed', 'all']
|
||||
|
||||
SUPPORTED_RESOLVERS = {
|
||||
'pdc': {'builders': ['koji', 'mock', 'copr']},
|
||||
'copr': {'builders': ['copr', 'mock']}
|
||||
}
|
||||
|
||||
|
||||
def init_config(app):
|
||||
""" Configure MBS and the Flask app
|
||||
@@ -433,7 +438,12 @@ class Config(object):
|
||||
'type': int,
|
||||
'default': 180,
|
||||
'desc': ('Time in days when to cleanup failed module builds and transition them to '
|
||||
'the "garbage" state.')}
|
||||
'the "garbage" state.')},
|
||||
'resolver': {
|
||||
'type': str,
|
||||
'default': 'pdc',
|
||||
'desc': 'Where to look up for modules. Note that this can (and '
|
||||
'probably will) be builder-specific.'},
|
||||
}
|
||||
|
||||
def __init__(self, conf_section_obj):
|
||||
@@ -625,3 +635,9 @@ class Config(object):
|
||||
if num_days < 1:
|
||||
raise ValueError('CLEANUP_FAILED_BUILDS_TIME must be set to 1 or more days')
|
||||
self._cleanup_failed_builds_time = num_days
|
||||
|
||||
def _setifok_resolver(self, s):
|
||||
if s not in SUPPORTED_RESOLVERS.keys():
|
||||
raise ValueError('The resolver "{0}" is not supported. Choose from: {1}'
|
||||
.format(s, ', '.join(SUPPORTED_RESOLVERS.keys())))
|
||||
self._resolver = s
|
||||
|
||||
@@ -1,531 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
# Copyright (c) 2016 Red Hat, Inc.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
#
|
||||
# Written by Lubos Kocman <lkocman@redhat.com>
|
||||
|
||||
"""PDC handler functions."""
|
||||
|
||||
import modulemd
|
||||
from pdc_client import PDCClient
|
||||
from module_build_service import db
|
||||
from module_build_service import models
|
||||
from module_build_service.errors import UnprocessableEntity
|
||||
|
||||
import inspect
|
||||
import pprint
|
||||
import logging
|
||||
import six
|
||||
import copy
|
||||
import kobo.rpmlib
|
||||
log = logging.getLogger()
|
||||
|
||||
|
||||
def get_pdc_client_session(config):
|
||||
"""
|
||||
:param config: instance of module_build_service.config.Config
|
||||
:return pdc_client.PDCClient instance
|
||||
"""
|
||||
if 'ssl_verify' in inspect.getargspec(PDCClient.__init__).args:
|
||||
# New API
|
||||
return PDCClient(
|
||||
server=config.pdc_url,
|
||||
develop=config.pdc_develop,
|
||||
ssl_verify=not config.pdc_insecure,
|
||||
)
|
||||
else:
|
||||
# Old API
|
||||
return PDCClient(
|
||||
server=config.pdc_url,
|
||||
develop=config.pdc_develop,
|
||||
insecure=config.pdc_insecure,
|
||||
)
|
||||
|
||||
|
||||
def get_variant_dict(data):
|
||||
"""
|
||||
:param data: one of following
|
||||
pdc variant_dict {'variant_id': value, 'variant_version': value, }
|
||||
module dict {'name': value, 'version': value }
|
||||
modulemd
|
||||
|
||||
:return final list of module_info which pass repoclosure
|
||||
"""
|
||||
def is_module_dict(data):
|
||||
if not isinstance(data, dict):
|
||||
return False
|
||||
|
||||
for attr in ('name', 'version'):
|
||||
if attr not in data.keys():
|
||||
return False
|
||||
return True
|
||||
|
||||
def is_variant_dict(data):
|
||||
if not isinstance(data, dict):
|
||||
return False
|
||||
|
||||
if ('variant_id' not in data or
|
||||
('variant_stream' not in data and
|
||||
'variant_version' not in data)):
|
||||
return False
|
||||
return True
|
||||
|
||||
def is_modulemd(data):
|
||||
return isinstance(data, modulemd.ModuleMetadata)
|
||||
|
||||
def is_module_str(data):
|
||||
return isinstance(data, six.string_types)
|
||||
|
||||
result = None
|
||||
|
||||
if is_module_str(data):
|
||||
result = variant_dict_from_str(data)
|
||||
|
||||
elif is_modulemd(data):
|
||||
result = {'variant_id': data.name}
|
||||
# Check if this is an old modulemd that doesn't use the new nomenclature
|
||||
if hasattr(data, 'release'):
|
||||
result['variant_release'] = data.release
|
||||
result['variant_version'] = data.version
|
||||
else:
|
||||
result['variant_release'] = data.version
|
||||
result['variant_version'] = data.stream
|
||||
|
||||
elif is_variant_dict(data):
|
||||
result = data.copy()
|
||||
|
||||
# This is a transitionary thing until we've ported PDC away from the old nomenclature
|
||||
if 'variant_version' not in result and 'variant_stream' in result:
|
||||
result['variant_version'] = result['variant_stream']
|
||||
del result['variant_stream']
|
||||
|
||||
# ensure that variant_type is in result
|
||||
if 'variant_type' not in result.keys():
|
||||
result['variant_type'] = 'module'
|
||||
|
||||
elif is_module_dict(data):
|
||||
result = {'variant_id': data['name'], 'variant_version': data['version']}
|
||||
|
||||
if 'release' in data:
|
||||
result['variant_release'] = data['release']
|
||||
|
||||
if 'active' in data:
|
||||
result['active'] = data['active']
|
||||
|
||||
if not result:
|
||||
raise RuntimeError("Couldn't get variant_dict from %s" % data)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def variant_dict_from_str(module_str):
|
||||
"""
|
||||
:param module_str: a string to match in PDC
|
||||
:return module_info dict
|
||||
|
||||
Example minimal module_info:
|
||||
{
|
||||
'variant_id': module_name,
|
||||
'variant_version': module_version,
|
||||
'variant_type': 'module'
|
||||
}
|
||||
"""
|
||||
log.debug("variant_dict_from_str(%r)" % module_str)
|
||||
# best match due several filters not being provided such as variant type ...
|
||||
|
||||
module_info = {}
|
||||
|
||||
release_start = module_str.rfind('-')
|
||||
version_start = module_str.rfind('-', 0, release_start)
|
||||
module_info['variant_release'] = module_str[release_start + 1:]
|
||||
module_info['variant_version'] = module_str[version_start + 1:release_start]
|
||||
module_info['variant_id'] = module_str[:version_start]
|
||||
module_info['variant_type'] = 'module'
|
||||
|
||||
return module_info
|
||||
|
||||
|
||||
def get_module(session, module_info, strict=False):
|
||||
"""
|
||||
:param session : PDCClient instance
|
||||
:param module_info: pdc variant_dict, str, mmd or module dict
|
||||
:param strict: Normally this function returns None if no module can be
|
||||
found. If strict=True, then an UnprocessableEntity is raised.
|
||||
|
||||
:return final list of module_info which pass repoclosure
|
||||
"""
|
||||
|
||||
log.debug("get_module(%r, strict=%r)" % (module_info, strict))
|
||||
variant_dict = get_variant_dict(module_info)
|
||||
|
||||
query = dict(
|
||||
variant_id=variant_dict['variant_id'],
|
||||
variant_version=variant_dict['variant_version'],
|
||||
)
|
||||
if variant_dict.get('variant_release'):
|
||||
query['variant_release'] = variant_dict['variant_release']
|
||||
if module_info.get('active'):
|
||||
query['active'] = module_info['active']
|
||||
|
||||
# TODO: So far sorting on Fedora prod PDC instance is broken and it sorts
|
||||
# only by variant_uid by default. Once the sorting is fixed, we can start
|
||||
# using '-variant_release' ordering and just get the first variant from
|
||||
# there. But in the meantime, we have to get the first variant with
|
||||
# page_size set to 1 to find out how many variants (pages) are there in
|
||||
# results set and jump to last one in another query. The last one is always
|
||||
# the latest one (the one with the highest version).
|
||||
try:
|
||||
retval = session['unreleasedvariants/'](page_size=1, **query)
|
||||
except Exception as ex:
|
||||
log.debug("error during PDC lookup: %r" % ex)
|
||||
raise RuntimeError("Error during PDC lookup for module %s" % module_info["name"])
|
||||
|
||||
# Error handling
|
||||
if not retval or len(retval["results"]) == 0:
|
||||
if strict:
|
||||
raise UnprocessableEntity("Failed to find module in PDC %r" % query)
|
||||
else:
|
||||
return None
|
||||
|
||||
# Jump to last page to latest module release.
|
||||
if retval['count'] != 1:
|
||||
query['page'] = retval['count']
|
||||
retval = session['unreleasedvariants/'](page_size=1, **query)
|
||||
|
||||
results = retval["results"]
|
||||
assert len(results) <= 1, pprint.pformat(retval)
|
||||
return results[0]
|
||||
|
||||
|
||||
def get_module_tag(session, module_info, strict=False):
|
||||
"""
|
||||
:param session : PDCClient instance
|
||||
:param module_info: list of module_info dicts
|
||||
:param strict: Normally this function returns None if no module can be
|
||||
found. If strict=True, then an UnprocessableEntity is raised.
|
||||
:return: koji tag string
|
||||
"""
|
||||
return get_module(session, module_info, strict=strict)['koji_tag']
|
||||
|
||||
|
||||
def get_module_modulemd(session, module_info, strict=False):
|
||||
"""
|
||||
:param session : PDCClient instance
|
||||
:param module_info: list of module_info dicts
|
||||
:param strict: Normally this function returns None if no module can be
|
||||
found. If strict=True, then an UnprocessableEntity is raised.
|
||||
:return: ModuleMetadata instance
|
||||
"""
|
||||
yaml = None
|
||||
module = get_module(session, module_info, strict=strict)
|
||||
if module:
|
||||
yaml = module['modulemd']
|
||||
|
||||
if not yaml:
|
||||
if strict:
|
||||
raise UnprocessableEntity(
|
||||
"Failed to find modulemd entry in PDC for %r" % module_info)
|
||||
else:
|
||||
return None
|
||||
|
||||
return _extract_modulemd(yaml, strict=strict)
|
||||
|
||||
|
||||
def _extract_modulemd(yaml, strict=False):
|
||||
mmd = modulemd.ModuleMetadata()
|
||||
mmd.loads(yaml)
|
||||
return mmd
|
||||
|
||||
|
||||
def _get_recursively_required_modules(session, info, modules=None,
|
||||
strict=False):
|
||||
"""
|
||||
:param session: PDCClient instance
|
||||
:param info: pdc variant_dict, str, mmd or module dict
|
||||
:param modules: Used by recursion only, list of modules found by previous
|
||||
iteration of this method.
|
||||
:param strict: Normally this function returns empty list if no module can
|
||||
be found. If strict=True, then an UnprocessableEntity is raised.
|
||||
|
||||
Returns list of modules by recursively querying PDC based on a "requires"
|
||||
list of an input module represented by `info`. The returned list
|
||||
therefore contains all modules the input module "requires".
|
||||
|
||||
If there are some modules loaded by utils.load_local_builds(...), these
|
||||
local modules will be used instead of querying PDC for the particular
|
||||
module found in local module builds database.
|
||||
|
||||
The returned list contains only "modulemd" and "koji_tag" fields returned
|
||||
by PDC, because other fields are not known for local builds.
|
||||
"""
|
||||
modules = modules or []
|
||||
|
||||
variant_dict = get_variant_dict(info)
|
||||
local_modules = models.ModuleBuild.local_modules(
|
||||
db.session, variant_dict["variant_id"],
|
||||
variant_dict['variant_version'])
|
||||
if local_modules:
|
||||
local_module = local_modules[0]
|
||||
log.info("Using local module %r as a dependency.",
|
||||
local_module)
|
||||
mmd = local_module.mmd()
|
||||
module_info = {}
|
||||
module_info["modulemd"] = local_module.modulemd
|
||||
module_info["koji_tag"] = local_module.koji_tag
|
||||
else:
|
||||
module_info = get_module(session, variant_dict, strict)
|
||||
module_info = {k: v for k, v in module_info.items()
|
||||
if k in ["modulemd", "koji_tag"]}
|
||||
module_info = {
|
||||
'modulemd': module_info['modulemd'],
|
||||
'koji_tag': module_info['koji_tag']
|
||||
}
|
||||
|
||||
yaml = module_info['modulemd']
|
||||
mmd = _extract_modulemd(yaml)
|
||||
|
||||
# Check if we have examined this koji_tag already - no need to do
|
||||
# it again...
|
||||
if module_info in modules:
|
||||
return modules
|
||||
|
||||
modules.append(module_info)
|
||||
|
||||
# We want to use the same stream as the one used in the time this
|
||||
# module was built. But we still should fallback to plain mmd.requires
|
||||
# in case this module depends on some older module for which we did
|
||||
# not populate mmd.xmd['mbs']['requires'].
|
||||
if mmd.xmd.get('mbs') and mmd.xmd['mbs'].get('requires'):
|
||||
requires = mmd.xmd['mbs']['requires']
|
||||
requires = {name: data['stream'] for name, data in requires.items()}
|
||||
else:
|
||||
requires = mmd.requires
|
||||
|
||||
for name, stream in requires.items():
|
||||
modified_dep = {
|
||||
'name': name,
|
||||
'version': stream,
|
||||
# Only return details about module builds that finished
|
||||
'active': True,
|
||||
}
|
||||
modules = _get_recursively_required_modules(
|
||||
session, modified_dep, modules, strict)
|
||||
|
||||
return modules
|
||||
|
||||
|
||||
def resolve_profiles(session, mmd, keys):
|
||||
"""
|
||||
:param session : PDCClient instance
|
||||
:param mmd: ModuleMetadata instance of module
|
||||
:param keys: list of modulemd installation profiles to include in
|
||||
the result.
|
||||
:return: Dictionary with keys set according to `keys` param and values
|
||||
set to union of all components defined in all installation
|
||||
profiles matching the key using the buildrequires.
|
||||
|
||||
If there are some modules loaded by utils.load_local_builds(...), these
|
||||
local modules will be considered when returning the profiles.
|
||||
|
||||
https://pagure.io/fm-orchestrator/issue/181
|
||||
"""
|
||||
|
||||
results = {}
|
||||
for key in keys:
|
||||
results[key] = set()
|
||||
for module_name, module_info in mmd.xmd['mbs']['buildrequires'].items():
|
||||
local_modules = models.ModuleBuild.local_modules(
|
||||
db.session, module_name, module_info['stream'])
|
||||
if local_modules:
|
||||
local_module = local_modules[0]
|
||||
log.info("Using local module %r to resolve profiles.",
|
||||
local_module)
|
||||
dep_mmd = local_module.mmd()
|
||||
for key in keys:
|
||||
if key in dep_mmd.profiles:
|
||||
results[key] |= dep_mmd.profiles[key].rpms
|
||||
continue
|
||||
|
||||
# Find the dep in the built modules in PDC
|
||||
module_info = {
|
||||
'variant_id': module_name,
|
||||
'variant_stream': module_info['stream'],
|
||||
'variant_release': module_info['version']}
|
||||
modules = _get_recursively_required_modules(
|
||||
session, module_info, strict=True)
|
||||
|
||||
for module in modules:
|
||||
yaml = module['modulemd']
|
||||
dep_mmd = _extract_modulemd(yaml)
|
||||
|
||||
# Take note of what rpms are in this dep's profile.
|
||||
for key in keys:
|
||||
if key in dep_mmd.profiles:
|
||||
results[key] |= dep_mmd.profiles[key].rpms
|
||||
|
||||
# Return the union of all rpms in all profiles of the given keys.
|
||||
return results
|
||||
|
||||
|
||||
def get_module_build_dependencies(session, module_info, strict=False):
|
||||
"""
|
||||
:param session : PDCClient instance
|
||||
:param module_info : a dict containing filters for pdc or ModuleMetadata
|
||||
instance.
|
||||
:param strict: Normally this function returns None if no module can be
|
||||
found. If strict=True, then an UnprocessableEntity is raised.
|
||||
:return dict with koji_tag as a key and ModuleMetadata object as value.
|
||||
|
||||
Example minimal module_info:
|
||||
{
|
||||
'variant_id': module_name,
|
||||
'variant_version': module_version,
|
||||
'variant_type': 'module'
|
||||
}
|
||||
"""
|
||||
log.debug("get_module_build_dependencies(%r, strict=%r)" % (module_info, strict))
|
||||
# XXX get definitive list of modules
|
||||
|
||||
# This is the set we're going to build up and return.
|
||||
module_tags = {}
|
||||
|
||||
if not isinstance(module_info, modulemd.ModuleMetadata):
|
||||
queried_module = get_module(session, module_info, strict=strict)
|
||||
yaml = queried_module['modulemd']
|
||||
queried_mmd = _extract_modulemd(yaml, strict=strict)
|
||||
else:
|
||||
queried_mmd = module_info
|
||||
|
||||
if (not queried_mmd or not queried_mmd.xmd.get('mbs') or
|
||||
not queried_mmd.xmd['mbs'].get('buildrequires')):
|
||||
raise RuntimeError(
|
||||
'The module "{0!r}" did not contain its modulemd or did not have '
|
||||
'its xmd attribute filled out in PDC'.format(module_info))
|
||||
|
||||
buildrequires = queried_mmd.xmd['mbs']['buildrequires']
|
||||
# Queue up the next tier of deps that we should look at..
|
||||
for name, details in buildrequires.items():
|
||||
modified_dep = {
|
||||
'name': name,
|
||||
'version': details['stream'],
|
||||
'release': details['version'],
|
||||
# Only return details about module builds that finished
|
||||
'active': True,
|
||||
}
|
||||
modules = _get_recursively_required_modules(
|
||||
session, modified_dep, strict=strict)
|
||||
for m in modules:
|
||||
if m["koji_tag"] in module_tags:
|
||||
continue
|
||||
module_tags[m["koji_tag"]] = _extract_modulemd(m["modulemd"])
|
||||
|
||||
return module_tags
|
||||
|
||||
|
||||
def resolve_requires(session, requires):
|
||||
"""
|
||||
Takes `requires` dict with module_name as key and module_stream as value.
|
||||
Resolves the stream to particular latest version of a module and returns
|
||||
new dict in following format:
|
||||
|
||||
{
|
||||
"module_name": {
|
||||
"ref": module_commit_hash,
|
||||
"stream": original_module_stream,
|
||||
"version": module_version,
|
||||
"filtered_rpms": ["nvr", ...]
|
||||
},
|
||||
...
|
||||
}
|
||||
|
||||
If there are some modules loaded by utils.load_local_builds(...), these
|
||||
local modules will be considered when resolving the requires.
|
||||
|
||||
Raises RuntimeError on PDC lookup error.
|
||||
"""
|
||||
new_requires = copy.deepcopy(requires)
|
||||
for module_name, module_stream in requires.items():
|
||||
# Try to find out module dependency in the local module builds
|
||||
# added by utils.load_local_builds(...).
|
||||
local_modules = models.ModuleBuild.local_modules(
|
||||
db.session, module_name, module_stream)
|
||||
if local_modules:
|
||||
local_build = local_modules[0]
|
||||
new_requires[module_name] = {
|
||||
# The commit ID isn't currently saved in modules.yaml
|
||||
'ref': None,
|
||||
'stream': local_build.stream,
|
||||
'version': local_build.version,
|
||||
# No need to set filtered_rpms for local builds, because MBS
|
||||
# filters the RPMs automatically when the module build is
|
||||
# done.
|
||||
'filtered_rpms': []
|
||||
}
|
||||
continue
|
||||
|
||||
# Assumes that module_stream is the stream and not the commit hash
|
||||
module_info = {
|
||||
'name': module_name,
|
||||
'version': module_stream,
|
||||
'active': True}
|
||||
module = get_module(session, module_info)
|
||||
|
||||
commit_hash = None
|
||||
version = None
|
||||
filtered_rpms = []
|
||||
module = get_module(session, module_info, strict=True)
|
||||
if module.get('modulemd'):
|
||||
mmd = modulemd.ModuleMetadata()
|
||||
mmd.loads(module['modulemd'])
|
||||
if mmd.xmd.get('mbs') and mmd.xmd['mbs'].get('commit'):
|
||||
commit_hash = mmd.xmd['mbs']['commit']
|
||||
|
||||
# Find out the particular NVR of filtered packages
|
||||
if "rpms" in module and mmd.filter and mmd.filter.rpms:
|
||||
for rpm in module["rpms"]:
|
||||
nvr = kobo.rpmlib.parse_nvra(rpm)
|
||||
# If the package is not filtered, continue
|
||||
if not nvr["name"] in mmd.filter.rpms:
|
||||
continue
|
||||
|
||||
# If the nvr is already in filtered_rpms, continue
|
||||
nvr = kobo.rpmlib.make_nvr(nvr, force_epoch=True)
|
||||
if nvr in filtered_rpms:
|
||||
continue
|
||||
filtered_rpms.append(nvr)
|
||||
|
||||
if module.get('variant_release'):
|
||||
version = module['variant_release']
|
||||
|
||||
if version and commit_hash:
|
||||
new_requires[module_name] = {
|
||||
'ref': commit_hash,
|
||||
'stream': module_stream,
|
||||
'version': str(version),
|
||||
'filtered_rpms': filtered_rpms,
|
||||
}
|
||||
else:
|
||||
raise RuntimeError(
|
||||
'The module "{0}" didn\'t contain either a commit hash or a'
|
||||
' version in PDC'.format(module_name))
|
||||
|
||||
return new_requires
|
||||
520
module_build_service/resolver/PDCResolver.py
Normal file
520
module_build_service/resolver/PDCResolver.py
Normal file
@@ -0,0 +1,520 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
# Copyright (c) 2018 Red Hat, Inc.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
#
|
||||
# Written by Lubos Kocman <lkocman@redhat.com>
|
||||
# Filip Valder <fvalder@redhat.com>
|
||||
|
||||
"""PDC handler functions."""
|
||||
|
||||
import modulemd
|
||||
from pdc_client import PDCClient
|
||||
from module_build_service import db
|
||||
from module_build_service import models
|
||||
from module_build_service.errors import UnprocessableEntity
|
||||
from module_build_service.resolver.base import GenericResolver
|
||||
|
||||
import inspect
|
||||
import pprint
|
||||
import logging
|
||||
import six
|
||||
import copy
|
||||
import kobo.rpmlib
|
||||
log = logging.getLogger()
|
||||
|
||||
|
||||
class PDCResolver(GenericResolver):
|
||||
|
||||
backend = "pdc"
|
||||
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
self.session = self._get_client_session(self.config)
|
||||
|
||||
def _get_client_session(self, config):
|
||||
"""
|
||||
:param config: instance of module_build_service.config.Config
|
||||
:return pdc_client.PDCClient instance
|
||||
"""
|
||||
if 'ssl_verify' in inspect.getargspec(PDCClient.__init__).args:
|
||||
# New API
|
||||
return PDCClient(
|
||||
server=self.config.pdc_url,
|
||||
develop=self.config.pdc_develop,
|
||||
ssl_verify=not self.config.pdc_insecure,
|
||||
)
|
||||
else:
|
||||
# Old API
|
||||
return PDCClient(
|
||||
server=self.config.pdc_url,
|
||||
develop=self.config.pdc_develop,
|
||||
insecure=self.config.pdc_insecure,
|
||||
)
|
||||
|
||||
def _get_variant_dict(self, data):
|
||||
"""
|
||||
:param data: one of following
|
||||
pdc variant_dict {'variant_id': value, 'variant_version': value, }
|
||||
module dict {'name': value, 'version': value }
|
||||
modulemd
|
||||
|
||||
:return final list of module_info which pass repoclosure
|
||||
"""
|
||||
def is_module_dict(data):
|
||||
if not isinstance(data, dict):
|
||||
return False
|
||||
|
||||
for attr in ('name', 'version'):
|
||||
if attr not in data.keys():
|
||||
return False
|
||||
return True
|
||||
|
||||
def is_variant_dict(data):
|
||||
if not isinstance(data, dict):
|
||||
return False
|
||||
|
||||
if ('variant_id' not in data or
|
||||
('variant_stream' not in data and
|
||||
'variant_version' not in data)):
|
||||
return False
|
||||
return True
|
||||
|
||||
def is_modulemd(data):
|
||||
return isinstance(data, modulemd.ModuleMetadata)
|
||||
|
||||
def is_module_str(data):
|
||||
return isinstance(data, six.string_types)
|
||||
|
||||
result = None
|
||||
|
||||
if is_module_str(data):
|
||||
result = self._variant_dict_from_str(data)
|
||||
|
||||
elif is_modulemd(data):
|
||||
result = {'variant_id': data.name}
|
||||
# Check if this is an old modulemd that doesn't use the new nomenclature
|
||||
if hasattr(data, 'release'):
|
||||
result['variant_release'] = data.release
|
||||
result['variant_version'] = data.version
|
||||
else:
|
||||
result['variant_release'] = data.version
|
||||
result['variant_version'] = data.stream
|
||||
|
||||
elif is_variant_dict(data):
|
||||
result = data.copy()
|
||||
|
||||
# This is a transitionary thing until we've ported PDC away from the old nomenclature
|
||||
if 'variant_version' not in result and 'variant_stream' in result:
|
||||
result['variant_version'] = result['variant_stream']
|
||||
del result['variant_stream']
|
||||
|
||||
# ensure that variant_type is in result
|
||||
if 'variant_type' not in result.keys():
|
||||
result['variant_type'] = 'module'
|
||||
|
||||
elif is_module_dict(data):
|
||||
result = {'variant_id': data['name'], 'variant_version': data['version']}
|
||||
|
||||
if 'release' in data:
|
||||
result['variant_release'] = data['release']
|
||||
|
||||
if 'active' in data:
|
||||
result['active'] = data['active']
|
||||
|
||||
if not result:
|
||||
raise RuntimeError("Couldn't get variant_dict from %s" % data)
|
||||
|
||||
return result
|
||||
|
||||
def _variant_dict_from_str(self, module_str):
|
||||
"""
|
||||
:param module_str: a string to match in PDC
|
||||
:return module_info dict
|
||||
|
||||
Example minimal module_info:
|
||||
{
|
||||
'variant_id': module_name,
|
||||
'variant_version': module_version,
|
||||
'variant_type': 'module'
|
||||
}
|
||||
"""
|
||||
log.debug("variant_dict_from_str(%r)" % module_str)
|
||||
# best match due several filters not being provided such as variant type ...
|
||||
|
||||
module_info = {}
|
||||
|
||||
release_start = module_str.rfind('-')
|
||||
version_start = module_str.rfind('-', 0, release_start)
|
||||
module_info['variant_release'] = module_str[release_start + 1:]
|
||||
module_info['variant_version'] = module_str[version_start + 1:release_start]
|
||||
module_info['variant_id'] = module_str[:version_start]
|
||||
module_info['variant_type'] = 'module'
|
||||
|
||||
return module_info
|
||||
|
||||
def _get_module(self, module_info, strict=False):
|
||||
"""
|
||||
:param module_info: pdc variant_dict, str, mmd or module dict
|
||||
:param strict: Normally this function returns None if no module can be
|
||||
found. If strict=True, then an UnprocessableEntity is raised.
|
||||
|
||||
:return final list of module_info which pass repoclosure
|
||||
"""
|
||||
|
||||
log.debug("get_module(%r, strict=%r)" % (module_info, strict))
|
||||
variant_dict = self._get_variant_dict(module_info)
|
||||
|
||||
query = dict(
|
||||
variant_id=variant_dict['variant_id'],
|
||||
variant_version=variant_dict['variant_version'],
|
||||
)
|
||||
if variant_dict.get('variant_release'):
|
||||
query['variant_release'] = variant_dict['variant_release']
|
||||
if module_info.get('active'):
|
||||
query['active'] = module_info['active']
|
||||
|
||||
# TODO: So far sorting on Fedora prod PDC instance is broken and it sorts
|
||||
# only by variant_uid by default. Once the sorting is fixed, we can start
|
||||
# using '-variant_release' ordering and just get the first variant from
|
||||
# there. But in the meantime, we have to get the first variant with
|
||||
# page_size set to 1 to find out how many variants (pages) are there in
|
||||
# results set and jump to last one in another query. The last one is always
|
||||
# the latest one (the one with the highest version).
|
||||
try:
|
||||
retval = self.session['unreleasedvariants/'](page_size=1, **query)
|
||||
except Exception as ex:
|
||||
log.debug("error during PDC lookup: %r" % ex)
|
||||
raise RuntimeError("Error during PDC lookup for module %s" % module_info["name"])
|
||||
|
||||
# Error handling
|
||||
if not retval or len(retval["results"]) == 0:
|
||||
if strict:
|
||||
raise UnprocessableEntity("Failed to find module in PDC %r" % query)
|
||||
else:
|
||||
return None
|
||||
|
||||
# Jump to last page to latest module release.
|
||||
if retval['count'] != 1:
|
||||
query['page'] = retval['count']
|
||||
retval = self.session['unreleasedvariants/'](page_size=1, **query)
|
||||
|
||||
results = retval["results"]
|
||||
assert len(results) <= 1, pprint.pformat(retval)
|
||||
return results[0]
|
||||
|
||||
def get_module_tag(self, module_info, strict=False):
|
||||
"""
|
||||
:param module_info: list of module_info dicts
|
||||
:param strict: Normally this function returns None if no module can be
|
||||
found. If strict=True, then an UnprocessableEntity is raised.
|
||||
:return: koji tag string
|
||||
"""
|
||||
return self._get_module(module_info, strict=strict)['koji_tag']
|
||||
|
||||
def _get_module_modulemd(self, module_info, strict=False):
|
||||
"""
|
||||
:param module_info: list of module_info dicts
|
||||
:param strict: Normally this function returns None if no module can be
|
||||
found. If strict=True, then an UnprocessableEntity is raised.
|
||||
:return: ModuleMetadata instance
|
||||
"""
|
||||
yaml = None
|
||||
module = self._get_module(module_info, strict=strict)
|
||||
if module:
|
||||
yaml = module['modulemd']
|
||||
|
||||
if not yaml:
|
||||
if strict:
|
||||
raise UnprocessableEntity(
|
||||
"Failed to find modulemd entry in PDC for %r" % module_info)
|
||||
else:
|
||||
return None
|
||||
|
||||
return self.extract_modulemd(yaml, strict=strict)
|
||||
|
||||
def _get_recursively_required_modules(self, info, modules=None,
|
||||
strict=False):
|
||||
"""
|
||||
:param info: pdc variant_dict, str, mmd or module dict
|
||||
:param modules: Used by recursion only, list of modules found by previous
|
||||
iteration of this method.
|
||||
:param strict: Normally this function returns empty list if no module can
|
||||
be found. If strict=True, then an UnprocessableEntity is raised.
|
||||
|
||||
Returns list of modules by recursively querying PDC based on a "requires"
|
||||
list of an input module represented by `info`. The returned list
|
||||
therefore contains all modules the input module "requires".
|
||||
|
||||
If there are some modules loaded by utils.load_local_builds(...), these
|
||||
local modules will be used instead of querying PDC for the particular
|
||||
module found in local module builds database.
|
||||
|
||||
The returned list contains only "modulemd" and "koji_tag" fields returned
|
||||
by PDC, because other fields are not known for local builds.
|
||||
"""
|
||||
modules = modules or []
|
||||
|
||||
variant_dict = self._get_variant_dict(info)
|
||||
local_modules = models.ModuleBuild.local_modules(
|
||||
db.session, variant_dict["variant_id"],
|
||||
variant_dict['variant_version'])
|
||||
if local_modules:
|
||||
local_module = local_modules[0]
|
||||
log.info("Using local module %r as a dependency.",
|
||||
local_module)
|
||||
mmd = local_module.mmd()
|
||||
module_info = {}
|
||||
module_info["modulemd"] = local_module.modulemd
|
||||
module_info["koji_tag"] = local_module.koji_tag
|
||||
else:
|
||||
module_info = self._get_module(variant_dict, strict)
|
||||
module_info = {k: v for k, v in module_info.items()
|
||||
if k in ["modulemd", "koji_tag"]}
|
||||
module_info = {
|
||||
'modulemd': module_info['modulemd'],
|
||||
'koji_tag': module_info['koji_tag']
|
||||
}
|
||||
|
||||
yaml = module_info['modulemd']
|
||||
mmd = self.extract_modulemd(yaml)
|
||||
|
||||
# Check if we have examined this koji_tag already - no need to do
|
||||
# it again...
|
||||
if module_info in modules:
|
||||
return modules
|
||||
|
||||
modules.append(module_info)
|
||||
|
||||
# We want to use the same stream as the one used in the time this
|
||||
# module was built. But we still should fallback to plain mmd.requires
|
||||
# in case this module depends on some older module for which we did
|
||||
# not populate mmd.xmd['mbs']['requires'].
|
||||
if mmd.xmd.get('mbs') and mmd.xmd['mbs'].get('requires'):
|
||||
requires = mmd.xmd['mbs']['requires']
|
||||
requires = {name: data['stream'] for name, data in requires.items()}
|
||||
else:
|
||||
requires = mmd.requires
|
||||
|
||||
for name, stream in requires.items():
|
||||
modified_dep = {
|
||||
'name': name,
|
||||
'version': stream,
|
||||
# Only return details about module builds that finished
|
||||
'active': True,
|
||||
}
|
||||
modules = self._get_recursively_required_modules(
|
||||
modified_dep, modules, strict)
|
||||
|
||||
return modules
|
||||
|
||||
def resolve_profiles(self, mmd, keys):
|
||||
"""
|
||||
:param mmd: ModuleMetadata instance of module
|
||||
:param keys: list of modulemd installation profiles to include in
|
||||
the result.
|
||||
:return: Dictionary with keys set according to `keys` param and values
|
||||
set to union of all components defined in all installation
|
||||
profiles matching the key using the buildrequires.
|
||||
|
||||
If there are some modules loaded by utils.load_local_builds(...), these
|
||||
local modules will be considered when returning the profiles.
|
||||
|
||||
https://pagure.io/fm-orchestrator/issue/181
|
||||
"""
|
||||
|
||||
results = {}
|
||||
for key in keys:
|
||||
results[key] = set()
|
||||
for module_name, module_info in mmd.xmd['mbs']['buildrequires'].items():
|
||||
local_modules = models.ModuleBuild.local_modules(
|
||||
db.session, module_name, module_info['stream'])
|
||||
if local_modules:
|
||||
local_module = local_modules[0]
|
||||
log.info("Using local module %r to resolve profiles.",
|
||||
local_module)
|
||||
dep_mmd = local_module.mmd()
|
||||
for key in keys:
|
||||
if key in dep_mmd.profiles:
|
||||
results[key] |= dep_mmd.profiles[key].rpms
|
||||
continue
|
||||
|
||||
# Find the dep in the built modules in PDC
|
||||
module_info = {
|
||||
'variant_id': module_name,
|
||||
'variant_stream': module_info['stream'],
|
||||
'variant_release': module_info['version']}
|
||||
modules = self._get_recursively_required_modules(
|
||||
module_info, strict=True)
|
||||
|
||||
for module in modules:
|
||||
yaml = module['modulemd']
|
||||
dep_mmd = self.extract_modulemd(yaml)
|
||||
|
||||
# Take note of what rpms are in this dep's profile.
|
||||
for key in keys:
|
||||
if key in dep_mmd.profiles:
|
||||
results[key] |= dep_mmd.profiles[key].rpms
|
||||
|
||||
# Return the union of all rpms in all profiles of the given keys.
|
||||
return results
|
||||
|
||||
def get_module_build_dependencies(self, module_info, strict=False):
|
||||
"""
|
||||
:param module_info : a dict containing filters for pdc or ModuleMetadata
|
||||
instance.
|
||||
:param strict: Normally this function returns None if no module can be
|
||||
found. If strict=True, then an UnprocessableEntity is raised.
|
||||
:return dict with koji_tag as a key and ModuleMetadata object as value.
|
||||
|
||||
Example minimal module_info:
|
||||
{
|
||||
'variant_id': module_name,
|
||||
'variant_version': module_version,
|
||||
'variant_type': 'module'
|
||||
}
|
||||
"""
|
||||
log.debug("get_module_build_dependencies(%r, strict=%r)" % (module_info, strict))
|
||||
# XXX get definitive list of modules
|
||||
|
||||
# This is the set we're going to build up and return.
|
||||
module_tags = {}
|
||||
|
||||
if not isinstance(module_info, modulemd.ModuleMetadata):
|
||||
queried_module = self._get_module(module_info, strict=strict)
|
||||
yaml = queried_module['modulemd']
|
||||
queried_mmd = self.extract_modulemd(yaml, strict=strict)
|
||||
else:
|
||||
queried_mmd = module_info
|
||||
|
||||
if (not queried_mmd or not queried_mmd.xmd.get('mbs') or
|
||||
not queried_mmd.xmd['mbs'].get('buildrequires')):
|
||||
raise RuntimeError(
|
||||
'The module "{0!r}" did not contain its modulemd or did not have '
|
||||
'its xmd attribute filled out in PDC'.format(module_info))
|
||||
|
||||
buildrequires = queried_mmd.xmd['mbs']['buildrequires']
|
||||
# Queue up the next tier of deps that we should look at..
|
||||
for name, details in buildrequires.items():
|
||||
modified_dep = {
|
||||
'name': name,
|
||||
'version': details['stream'],
|
||||
'release': details['version'],
|
||||
# Only return details about module builds that finished
|
||||
'active': True,
|
||||
}
|
||||
modules = self._get_recursively_required_modules(
|
||||
modified_dep, strict=strict)
|
||||
for m in modules:
|
||||
if m["koji_tag"] in module_tags:
|
||||
continue
|
||||
module_tags[m["koji_tag"]] = self.extract_modulemd(m["modulemd"])
|
||||
|
||||
return module_tags
|
||||
|
||||
def resolve_requires(self, requires):
|
||||
"""
|
||||
Takes `requires` dict with module_name as key and module_stream as value.
|
||||
Resolves the stream to particular latest version of a module and returns
|
||||
new dict in following format:
|
||||
|
||||
{
|
||||
"module_name": {
|
||||
"ref": module_commit_hash,
|
||||
"stream": original_module_stream,
|
||||
"version": module_version,
|
||||
"filtered_rpms": ["nvr", ...]
|
||||
},
|
||||
...
|
||||
}
|
||||
|
||||
If there are some modules loaded by utils.load_local_builds(...), these
|
||||
local modules will be considered when resolving the requires.
|
||||
|
||||
Raises RuntimeError on PDC lookup error.
|
||||
"""
|
||||
new_requires = copy.deepcopy(requires)
|
||||
for module_name, module_stream in requires.items():
|
||||
# Try to find out module dependency in the local module builds
|
||||
# added by utils.load_local_builds(...).
|
||||
local_modules = models.ModuleBuild.local_modules(
|
||||
db.session, module_name, module_stream)
|
||||
if local_modules:
|
||||
local_build = local_modules[0]
|
||||
new_requires[module_name] = {
|
||||
# The commit ID isn't currently saved in modules.yaml
|
||||
'ref': None,
|
||||
'stream': local_build.stream,
|
||||
'version': local_build.version,
|
||||
# No need to set filtered_rpms for local builds, because MBS
|
||||
# filters the RPMs automatically when the module build is
|
||||
# done.
|
||||
'filtered_rpms': []
|
||||
}
|
||||
continue
|
||||
|
||||
# Assumes that module_stream is the stream and not the commit hash
|
||||
module_info = {
|
||||
'name': module_name,
|
||||
'version': module_stream,
|
||||
'active': True}
|
||||
module = self._get_module(module_info)
|
||||
|
||||
commit_hash = None
|
||||
version = None
|
||||
filtered_rpms = []
|
||||
module = self._get_module(module_info, strict=True)
|
||||
if module.get('modulemd'):
|
||||
mmd = modulemd.ModuleMetadata()
|
||||
mmd.loads(module['modulemd'])
|
||||
if mmd.xmd.get('mbs') and mmd.xmd['mbs'].get('commit'):
|
||||
commit_hash = mmd.xmd['mbs']['commit']
|
||||
|
||||
# Find out the particular NVR of filtered packages
|
||||
if "rpms" in module and mmd.filter and mmd.filter.rpms:
|
||||
for rpm in module["rpms"]:
|
||||
nvr = kobo.rpmlib.parse_nvra(rpm)
|
||||
# If the package is not filtered, continue
|
||||
if not nvr["name"] in mmd.filter.rpms:
|
||||
continue
|
||||
|
||||
# If the nvr is already in filtered_rpms, continue
|
||||
nvr = kobo.rpmlib.make_nvr(nvr, force_epoch=True)
|
||||
if nvr in filtered_rpms:
|
||||
continue
|
||||
filtered_rpms.append(nvr)
|
||||
|
||||
if module.get('variant_release'):
|
||||
version = module['variant_release']
|
||||
|
||||
if version and commit_hash:
|
||||
new_requires[module_name] = {
|
||||
'ref': commit_hash,
|
||||
'stream': module_stream,
|
||||
'version': str(version),
|
||||
'filtered_rpms': filtered_rpms,
|
||||
}
|
||||
else:
|
||||
raise RuntimeError(
|
||||
'The module "{0}" didn\'t contain either a commit hash or a'
|
||||
' version in PDC'.format(module_name))
|
||||
|
||||
return new_requires
|
||||
33
module_build_service/resolver/__init__.py
Normal file
33
module_build_service/resolver/__init__.py
Normal file
@@ -0,0 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2018 Red Hat, Inc.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
#
|
||||
# Written by Filip Valder <fvalder@redhat.com>
|
||||
|
||||
import pkg_resources
|
||||
|
||||
from module_build_service.resolver.base import GenericResolver
|
||||
|
||||
|
||||
for entrypoint in pkg_resources.iter_entry_points('mbs.resolver_backends'):
|
||||
GenericResolver.register_backend_class(entrypoint.load())
|
||||
|
||||
if not GenericResolver.backends:
|
||||
raise ValueError("No resolver plugins are installed or available.")
|
||||
109
module_build_service/resolver/base.py
Normal file
109
module_build_service/resolver/base.py
Normal file
@@ -0,0 +1,109 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2018 Red Hat, Inc.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
#
|
||||
# Written by Filip Valder <fvalder@redhat.com>
|
||||
|
||||
"""Generic resolver functions."""
|
||||
|
||||
|
||||
import six
|
||||
from abc import ABCMeta, abstractmethod
|
||||
|
||||
import modulemd
|
||||
import module_build_service.config as cfg
|
||||
from module_build_service import conf
|
||||
|
||||
|
||||
class GenericResolver(six.with_metaclass(ABCMeta)):
|
||||
"""
|
||||
External Api for resolvers
|
||||
"""
|
||||
|
||||
_resolvers = cfg.SUPPORTED_RESOLVERS
|
||||
backend = "generic"
|
||||
backends = {}
|
||||
|
||||
@classmethod
|
||||
def register_backend_class(cls, backend_class):
|
||||
GenericResolver.backends[backend_class.backend] = backend_class
|
||||
|
||||
@classmethod
|
||||
def create(cls, config, backend=None, **extra):
|
||||
"""
|
||||
:param backend: a string representing resolver e.g. 'pdc'
|
||||
|
||||
Any additional arguments are optional extras which can be passed along
|
||||
and are implementation-dependent.
|
||||
"""
|
||||
|
||||
# get the appropriate resolver backend via configuration
|
||||
if not backend:
|
||||
backend = conf.resolver
|
||||
|
||||
if backend in GenericResolver.backends:
|
||||
return GenericResolver.backends[backend](config, **extra)
|
||||
else:
|
||||
raise ValueError("Resolver backend='%s' not recognized" % backend)
|
||||
|
||||
@classmethod
|
||||
def supported_builders(cls):
|
||||
if cls is GenericResolver:
|
||||
return {k: v['builders'] for k, v in cls._resolvers.items()}
|
||||
else:
|
||||
try:
|
||||
return cls._resolvers[cls.backend]['builders']
|
||||
except KeyError:
|
||||
raise RuntimeError("No configuration of builder backends found "
|
||||
"for resolver {}".format(cls))
|
||||
|
||||
@classmethod
|
||||
def is_builder_compatible(cls, builder):
|
||||
"""
|
||||
:param backend: a string representing builder e.g. 'koji'
|
||||
|
||||
Get supported builder backend(s) via configuration
|
||||
"""
|
||||
if cls is not GenericResolver:
|
||||
return builder in cls.supported_builders()
|
||||
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def extract_modulemd(yaml, strict=False):
|
||||
mmd = modulemd.ModuleMetadata()
|
||||
mmd.loads(yaml)
|
||||
return mmd
|
||||
|
||||
@abstractmethod
|
||||
def get_module_tag(self, module_info, strict=False):
|
||||
raise NotImplementedError()
|
||||
|
||||
@abstractmethod
|
||||
def resolve_profiles(self, mmd, keys):
|
||||
raise NotImplementedError()
|
||||
|
||||
@abstractmethod
|
||||
def get_module_build_dependencies(self, module_info, strict=False):
|
||||
raise NotImplementedError()
|
||||
|
||||
@abstractmethod
|
||||
def resolve_requires(self, requires):
|
||||
raise NotImplementedError()
|
||||
@@ -26,7 +26,6 @@
|
||||
import logging
|
||||
|
||||
import module_build_service.builder
|
||||
import module_build_service.pdc
|
||||
|
||||
import koji
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
from module_build_service import conf, models, log, build_logs
|
||||
import module_build_service.builder
|
||||
import module_build_service.pdc
|
||||
import module_build_service.resolver
|
||||
import module_build_service.utils
|
||||
import module_build_service.messaging
|
||||
from module_build_service.utils import (
|
||||
@@ -201,7 +201,7 @@ def wait(config, session, msg):
|
||||
tag = None
|
||||
dependencies = []
|
||||
|
||||
pdc_session = module_build_service.pdc.get_pdc_client_session(config)
|
||||
resolver = module_build_service.resolver.GenericResolver.create(config)
|
||||
|
||||
@module_build_service.utils.retry(
|
||||
interval=10, timeout=120,
|
||||
@@ -218,9 +218,9 @@ def wait(config, session, msg):
|
||||
# In case of non-koji backend, we want to get the dependencies
|
||||
# of the local module build based on ModuleMetadata, because the
|
||||
# local build is not stored in PDC and therefore we cannot query
|
||||
# it using the `pdc_query` as for Koji below.
|
||||
dependencies = module_build_service.pdc.get_module_build_dependencies(
|
||||
pdc_session, build.mmd(), strict=True).keys()
|
||||
# it using the `query` as for Koji below.
|
||||
dependencies = resolver.get_module_build_dependencies(
|
||||
build.mmd(), strict=True).keys()
|
||||
|
||||
# We also don't want to get the tag name from the PDC, but just
|
||||
# generate it locally instead.
|
||||
@@ -228,16 +228,16 @@ def wait(config, session, msg):
|
||||
module_info['name'],
|
||||
str(module_info['stream']), str(module_info['version'])])
|
||||
else:
|
||||
# For Koji backend, query the PDC for the module we are going to
|
||||
# For Koji backend, query for the module we are going to
|
||||
# build to get the koji_tag and deps from it.
|
||||
pdc_query = {
|
||||
query = {
|
||||
'name': module_info['name'],
|
||||
'version': module_info['stream'],
|
||||
'release': module_info['version'],
|
||||
}
|
||||
log.info("Getting %s deps from pdc (query %r)" % (module_info['name'], pdc_query))
|
||||
deps_dict = module_build_service.pdc.get_module_build_dependencies(
|
||||
pdc_session, pdc_query, strict=True)
|
||||
log.info("Getting %s deps (query %r)" % (module_info['name'], query))
|
||||
deps_dict = resolver.get_module_build_dependencies(
|
||||
query, strict=True)
|
||||
dependencies = set(deps_dict.keys())
|
||||
|
||||
# Find out the name of Koji tag to which the module's Content
|
||||
@@ -250,9 +250,9 @@ def wait(config, session, msg):
|
||||
module_names_streams[base_module_name])
|
||||
break
|
||||
|
||||
log.info("Getting %s tag from pdc (query %r)" % (module_info['name'], pdc_query))
|
||||
tag = module_build_service.pdc.get_module_tag(
|
||||
pdc_session, pdc_query, strict=True)
|
||||
log.info("Getting %s tag (query %r)" % (module_info['name'], query))
|
||||
tag = resolver.get_module_tag(
|
||||
query, strict=True)
|
||||
|
||||
return dependencies, tag, cg_build_koji_tag
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
""" Handlers for repo change events on the message bus. """
|
||||
|
||||
import module_build_service.builder
|
||||
import module_build_service.pdc
|
||||
import logging
|
||||
import koji
|
||||
from module_build_service import models, log
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
""" Handlers for repo change events on the message bus. """
|
||||
|
||||
import module_build_service.builder
|
||||
import module_build_service.pdc
|
||||
import logging
|
||||
import koji
|
||||
from module_build_service import models, log, messaging
|
||||
|
||||
@@ -48,8 +48,7 @@ from module_build_service import conf, db
|
||||
from module_build_service.errors import (Forbidden, Conflict)
|
||||
import module_build_service.messaging
|
||||
from multiprocessing.dummy import Pool as ThreadPool
|
||||
import module_build_service.pdc
|
||||
from module_build_service.pdc import resolve_requires
|
||||
import module_build_service.resolver
|
||||
|
||||
import concurrent.futures
|
||||
|
||||
@@ -773,18 +772,18 @@ def format_mmd(mmd, scmurl, session=None):
|
||||
else:
|
||||
mmd.xmd['mbs']['commit'] = scm.get_latest()
|
||||
|
||||
pdc = module_build_service.pdc.get_pdc_client_session(conf)
|
||||
resolver = module_build_service.resolver.GenericResolver.create(conf)
|
||||
|
||||
# Resolve Build-requires.
|
||||
if mmd.buildrequires:
|
||||
mmd.xmd['mbs']['buildrequires'] = resolve_requires(
|
||||
pdc, mmd.buildrequires)
|
||||
mmd.xmd['mbs']['buildrequires'] = resolver.resolve_requires(
|
||||
mmd.buildrequires)
|
||||
else:
|
||||
mmd.xmd['mbs']['buildrequires'] = {}
|
||||
|
||||
# Resolve Requires.
|
||||
if mmd.requires:
|
||||
mmd.xmd['mbs']['requires'] = resolve_requires(pdc, mmd.requires)
|
||||
mmd.xmd['mbs']['requires'] = resolver.resolve_requires(mmd.requires)
|
||||
else:
|
||||
mmd.xmd['mbs']['requires'] = {}
|
||||
|
||||
|
||||
3
setup.py
3
setup.py
@@ -57,6 +57,9 @@ setup(name='module-build-service',
|
||||
# iterate without us blocking him.
|
||||
'copr = module_build_service.builder.CoprModuleBuilder:CoprModuleBuilder',
|
||||
],
|
||||
'mbs.resolver_backends': [
|
||||
'pdc = module_build_service.resolver.PDCResolver:PDCResolver',
|
||||
],
|
||||
},
|
||||
scripts=["contrib/mbs-build"],
|
||||
data_files=[('/etc/module-build-service/', ['conf/cacert.pem',
|
||||
|
||||
@@ -23,11 +23,10 @@
|
||||
import os
|
||||
import tarfile
|
||||
from datetime import datetime, timedelta
|
||||
from mock import patch
|
||||
|
||||
import modulemd
|
||||
|
||||
import module_build_service
|
||||
import module_build_service.pdc
|
||||
from module_build_service import db
|
||||
from module_build_service.utils import get_rpm_release
|
||||
from module_build_service.config import init_config
|
||||
@@ -39,6 +38,18 @@ app = module_build_service.app
|
||||
conf = init_config(app)
|
||||
|
||||
|
||||
def patch_config():
|
||||
# add test builders for all resolvers
|
||||
with_test_builders = dict()
|
||||
for k, v in module_build_service.config.SUPPORTED_RESOLVERS.items():
|
||||
v['builders'].extend(['test', 'testlocal'])
|
||||
with_test_builders[k] = v
|
||||
patch("module_build_service.config.SUPPORTED_RESOLVERS", with_test_builders)
|
||||
|
||||
|
||||
patch_config()
|
||||
|
||||
|
||||
def uncompress_vcrpy_cassette():
|
||||
cassette_dir = base_dir + '/vcr-request-data/'
|
||||
if not os.path.exists(cassette_dir):
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#
|
||||
# Written by Jan Kaluza <jkaluza@redhat.com>
|
||||
|
||||
import mock
|
||||
import unittest
|
||||
|
||||
import module_build_service.models
|
||||
@@ -37,13 +38,18 @@ class TestGenericBuilder(unittest.TestCase):
|
||||
init_data()
|
||||
self.module = module_build_service.models.ModuleBuild.query.filter_by(id=1).one()
|
||||
|
||||
@patch('module_build_service.pdc.resolve_profiles')
|
||||
def test_default_buildroot_groups_cache(self, resolve_profiles):
|
||||
@patch('module_build_service.resolver.PDCResolver')
|
||||
@patch('module_build_service.resolver.GenericResolver')
|
||||
def test_default_buildroot_groups_cache(self, generic_resolver, resolver):
|
||||
pdc_groups = {
|
||||
"buildroot": [],
|
||||
"srpm-buildroot": []
|
||||
}
|
||||
resolve_profiles.return_value = pdc_groups
|
||||
|
||||
resolver = mock.MagicMock()
|
||||
resolver.backend = 'pdc'
|
||||
resolver.resolve_profiles.return_value = pdc_groups
|
||||
generic_resolver.create.return_value = resolver
|
||||
|
||||
expected_groups = {
|
||||
"build": [],
|
||||
@@ -53,21 +59,21 @@ class TestGenericBuilder(unittest.TestCase):
|
||||
# Call default_buildroot_groups, the result should be cached.
|
||||
ret = GenericBuilder.default_buildroot_groups(db.session, self.module)
|
||||
self.assertEqual(ret, expected_groups)
|
||||
resolve_profiles.assert_called_once()
|
||||
resolve_profiles.reset_mock()
|
||||
resolver.resolve_profiles.assert_called_once()
|
||||
resolver.resolve_profiles.reset_mock()
|
||||
|
||||
# Now try calling it again to verify resolve_profiles is not called,
|
||||
# because it is cached.
|
||||
ret = GenericBuilder.default_buildroot_groups(db.session, self.module)
|
||||
self.assertEqual(ret, expected_groups)
|
||||
resolve_profiles.assert_not_called()
|
||||
resolve_profiles.reset_mock()
|
||||
resolver.resolve_profiles.assert_not_called()
|
||||
resolver.resolve_profiles.reset_mock()
|
||||
|
||||
# And now try clearing the cache and call it again.
|
||||
GenericBuilder.clear_cache(self.module)
|
||||
ret = GenericBuilder.default_buildroot_groups(db.session, self.module)
|
||||
self.assertEqual(ret, expected_groups)
|
||||
resolve_profiles.assert_called_once()
|
||||
resolver.resolve_profiles.assert_called_once()
|
||||
|
||||
def test_get_build_weights(self):
|
||||
weights = GenericBuilder.get_build_weights(["httpd", "apr"])
|
||||
|
||||
0
tests/test_resolver/__init__.py
Normal file
0
tests/test_resolver/__init__.py
Normal file
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2017 Red Hat, Inc.
|
||||
# Copyright (c) 2018 Red Hat, Inc.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -26,7 +26,7 @@ import unittest
|
||||
from mock import patch, PropertyMock
|
||||
|
||||
import vcr
|
||||
import module_build_service.pdc as mbs_pdc
|
||||
import module_build_service.resolver as mbs_resolver
|
||||
import module_build_service.utils
|
||||
import module_build_service.models
|
||||
from module_build_service import app, db
|
||||
@@ -35,7 +35,7 @@ import tests
|
||||
import modulemd
|
||||
|
||||
|
||||
base_dir = os.path.dirname(__file__)
|
||||
base_dir = os.path.join(os.path.dirname(__file__), "..")
|
||||
cassette_dir = base_dir + '/vcr-request-data/'
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class TestPDCModule(unittest.TestCase):
|
||||
self.vcr = vcr.use_cassette(filename)
|
||||
self.vcr.__enter__()
|
||||
|
||||
self.pdc = mbs_pdc.get_pdc_client_session(tests.conf)
|
||||
self.resolver = mbs_resolver.GenericResolver.create(tests.conf, backend='pdc')
|
||||
|
||||
def tearDown(self):
|
||||
self.vcr.__exit__()
|
||||
@@ -66,12 +66,12 @@ class TestPDCModule(unittest.TestCase):
|
||||
'variant_version': 'master'
|
||||
}
|
||||
|
||||
variant_dict = mbs_pdc.get_variant_dict(dep)
|
||||
variant_dict = self.resolver._get_variant_dict(dep)
|
||||
self.assertEqual(variant_dict, expected)
|
||||
|
||||
def test_get_module_simple_as_dict(self):
|
||||
query = {'name': 'testmodule', 'version': 'master'}
|
||||
result = mbs_pdc.get_module(self.pdc, query)
|
||||
result = self.resolver._get_module(query)
|
||||
assert result['variant_name'] == 'testmodule'
|
||||
assert result['variant_version'] == 'master'
|
||||
assert 'build_deps' in result
|
||||
@@ -86,7 +86,7 @@ class TestPDCModule(unittest.TestCase):
|
||||
'version': 'master',
|
||||
'release': '20170315134803',
|
||||
}
|
||||
result = mbs_pdc.get_module_build_dependencies(self.pdc, query).keys()
|
||||
result = self.resolver.get_module_build_dependencies(query).keys()
|
||||
expected = [
|
||||
u'module-bootstrap-rawhide',
|
||||
]
|
||||
@@ -103,7 +103,7 @@ class TestPDCModule(unittest.TestCase):
|
||||
'version': 'master',
|
||||
'release': '20170322155247'
|
||||
}
|
||||
result = mbs_pdc.get_module_build_dependencies(self.pdc, query).keys()
|
||||
result = self.resolver.get_module_build_dependencies(query).keys()
|
||||
expected = [
|
||||
u'module-base-runtime-master-20170315134803',
|
||||
]
|
||||
@@ -126,7 +126,7 @@ class TestPDCModule(unittest.TestCase):
|
||||
|
||||
build = module_build_service.models.ModuleBuild.local_modules(
|
||||
db.session, "child", "master")
|
||||
result = mbs_pdc.get_module_build_dependencies(self.pdc, build[0].mmd()).keys()
|
||||
result = self.resolver.get_module_build_dependencies(build[0].mmd()).keys()
|
||||
|
||||
local_path = os.path.join(base_dir, 'staged_data', "local_builds")
|
||||
|
||||
@@ -141,13 +141,11 @@ class TestPDCModule(unittest.TestCase):
|
||||
self.assertEqual(set(result), set(expected))
|
||||
|
||||
def test_resolve_profiles(self):
|
||||
current_dir = os.path.dirname(__file__)
|
||||
yaml_path = os.path.join(
|
||||
current_dir, 'staged_data', 'formatted_testmodule.yaml')
|
||||
base_dir, 'staged_data', 'formatted_testmodule.yaml')
|
||||
mmd = modulemd.ModuleMetadata()
|
||||
mmd.load(yaml_path)
|
||||
result = mbs_pdc.resolve_profiles(self.pdc, mmd,
|
||||
('buildroot', 'srpm-buildroot'))
|
||||
result = self.resolver.resolve_profiles(mmd, ('buildroot', 'srpm-buildroot'))
|
||||
expected = {
|
||||
'buildroot':
|
||||
set(['unzip', 'tar', 'cpio', 'gawk', 'gcc', 'xz', 'sed',
|
||||
@@ -171,12 +169,11 @@ class TestPDCModule(unittest.TestCase):
|
||||
with app.app_context():
|
||||
module_build_service.utils.load_local_builds(["base-runtime"])
|
||||
|
||||
current_dir = os.path.dirname(__file__)
|
||||
yaml_path = os.path.join(
|
||||
current_dir, 'staged_data', 'formatted_testmodule.yaml')
|
||||
base_dir, 'staged_data', 'formatted_testmodule.yaml')
|
||||
mmd = modulemd.ModuleMetadata()
|
||||
mmd.load(yaml_path)
|
||||
result = mbs_pdc.resolve_profiles(self.pdc, mmd, ('buildroot', 'srpm-buildroot'))
|
||||
result = self.resolver.resolve_profiles(mmd, ('buildroot', 'srpm-buildroot'))
|
||||
expected = {
|
||||
'buildroot':
|
||||
set(['foo']),
|
||||
@@ -56,10 +56,10 @@ class TestModuleWait(unittest.TestCase):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@mock.patch('module_build_service.builder.GenericBuilder.create_from_module')
|
||||
@mock.patch('module_build_service.models.ModuleBuild.from_module_event')
|
||||
@mock.patch('module_build_service.pdc')
|
||||
def test_init_basic(self, pdc, from_module_event, create_builder):
|
||||
@patch('module_build_service.builder.GenericBuilder.create_from_module')
|
||||
@patch('module_build_service.models.ModuleBuild.from_module_event')
|
||||
@patch('module_build_service.resolver.GenericResolver')
|
||||
def test_init_basic(self, resolver, from_module_event, create_builder):
|
||||
builder = mock.Mock()
|
||||
builder.get_disttag_srpm.return_value = 'some srpm disttag'
|
||||
builder.build.return_value = 1234, 1, "", None
|
||||
@@ -95,14 +95,14 @@ class TestModuleWait(unittest.TestCase):
|
||||
return_value={'build': [], 'srpm-build': []})
|
||||
@patch("module_build_service.builder.KojiModuleBuilder.KojiModuleBuilder.get_session")
|
||||
@patch("module_build_service.builder.GenericBuilder.create_from_module")
|
||||
@patch('module_build_service.pdc')
|
||||
@patch('module_build_service.resolver.PDCResolver')
|
||||
@patch('module_build_service.resolver.GenericResolver')
|
||||
def test_new_repo_called_when_macros_reused(
|
||||
self, pdc, create_builder, koji_get_session, dbg):
|
||||
self, generic_resolver, resolver, create_builder, koji_get_session, dbg):
|
||||
"""
|
||||
Test that newRepo is called when module-build-macros build is reused.
|
||||
"""
|
||||
with app.app_context():
|
||||
pdc.get_module_tag.return_value = "module-testmodule-master-20170109091357"
|
||||
scheduler_init_data()
|
||||
koji_session = mock.MagicMock()
|
||||
koji_session.newRepo.return_value = 123456
|
||||
@@ -116,6 +116,11 @@ class TestModuleWait(unittest.TestCase):
|
||||
"module-build-macros-1-1")
|
||||
create_builder.return_value = builder
|
||||
|
||||
resolver = mock.MagicMock()
|
||||
resolver.backend = 'pdc'
|
||||
resolver.get_module_tag.return_value = "module-testmodule-master-20170109091357"
|
||||
generic_resolver.create.return_value = resolver
|
||||
|
||||
msg = module_build_service.messaging.MBSModule(msg_id=None, module_build_id=1,
|
||||
module_build_state='some state')
|
||||
module_build_service.scheduler.handlers.modules.wait(
|
||||
@@ -132,14 +137,14 @@ class TestModuleWait(unittest.TestCase):
|
||||
return_value={'build': [], 'srpm-build': []})
|
||||
@patch("module_build_service.builder.KojiModuleBuilder.KojiModuleBuilder.get_session")
|
||||
@patch("module_build_service.builder.GenericBuilder.create_from_module")
|
||||
@patch('module_build_service.pdc')
|
||||
@patch('module_build_service.resolver.PDCResolver')
|
||||
@patch('module_build_service.resolver.GenericResolver')
|
||||
def test_new_repo_not_called_when_macros_not_reused(
|
||||
self, pdc, create_builder, koji_get_session, dbg):
|
||||
self, generic_resolver, resolver, create_builder, koji_get_session, dbg):
|
||||
"""
|
||||
Test that newRepo is called everytime for module-build-macros
|
||||
"""
|
||||
with app.app_context():
|
||||
pdc.get_module_tag.return_value = "module-testmodule-master-20170109091357"
|
||||
scheduler_init_data()
|
||||
koji_session = mock.MagicMock()
|
||||
koji_session.newRepo.return_value = 123456
|
||||
@@ -153,6 +158,11 @@ class TestModuleWait(unittest.TestCase):
|
||||
"module-build-macros-1-1")
|
||||
create_builder.return_value = builder
|
||||
|
||||
resolver = mock.MagicMock()
|
||||
resolver.backend = 'pdc'
|
||||
resolver.get_module_tag.return_value = "module-testmodule-master-20170109091357"
|
||||
generic_resolver.create.return_value = resolver
|
||||
|
||||
msg = module_build_service.messaging.MBSModule(msg_id=None, module_build_id=1,
|
||||
module_build_state='some state')
|
||||
module_build_service.scheduler.handlers.modules.wait(
|
||||
@@ -163,19 +173,17 @@ class TestModuleWait(unittest.TestCase):
|
||||
return_value={'build': [], 'srpm-build': []})
|
||||
@patch("module_build_service.builder.KojiModuleBuilder.KojiModuleBuilder.get_session")
|
||||
@patch("module_build_service.builder.GenericBuilder.create_from_module")
|
||||
@patch('module_build_service.pdc')
|
||||
@patch('module_build_service.resolver.PDCResolver')
|
||||
@patch('module_build_service.resolver.GenericResolver')
|
||||
def test_set_cg_build_koji_tag_fallback_to_default(
|
||||
self, pdc, create_builder, koji_get_session, dbg):
|
||||
self, generic_resolver, resolver, create_builder, koji_get_session, dbg):
|
||||
"""
|
||||
Test that build.cg_build_koji_tag fallbacks to default tag.
|
||||
"""
|
||||
with app.app_context():
|
||||
pdc.get_module_tag.return_value = "module-testmodule-master-20170109091357"
|
||||
base_mmd = _modulemd.ModuleMetadata()
|
||||
base_mmd.name = "base-runtime"
|
||||
base_mmd.stream = "f27"
|
||||
pdc.get_module_build_dependencies.return_value = {
|
||||
"module-bootstrap-tag": base_mmd}
|
||||
|
||||
scheduler_init_data()
|
||||
koji_session = mock.MagicMock()
|
||||
@@ -190,6 +198,13 @@ class TestModuleWait(unittest.TestCase):
|
||||
"module-build-macros-1-1")
|
||||
create_builder.return_value = builder
|
||||
|
||||
resolver = mock.MagicMock()
|
||||
resolver.backend = 'pdc'
|
||||
resolver.get_module_tag.return_value = "module-testmodule-master-20170109091357"
|
||||
resolver.get_module_build_dependencies.return_value = {
|
||||
"module-bootstrap-tag": base_mmd}
|
||||
generic_resolver.create.return_value = resolver
|
||||
|
||||
msg = module_build_service.messaging.MBSModule(msg_id=None, module_build_id=1,
|
||||
module_build_state='some state')
|
||||
module_build_service.scheduler.handlers.modules.wait(
|
||||
@@ -201,21 +216,19 @@ class TestModuleWait(unittest.TestCase):
|
||||
return_value={'build': [], 'srpm-build': []})
|
||||
@patch("module_build_service.builder.KojiModuleBuilder.KojiModuleBuilder.get_session")
|
||||
@patch("module_build_service.builder.GenericBuilder.create_from_module")
|
||||
@patch('module_build_service.pdc')
|
||||
@patch('module_build_service.resolver.PDCResolver')
|
||||
@patch('module_build_service.resolver.GenericResolver')
|
||||
@patch("module_build_service.config.Config.base_module_names",
|
||||
new_callable=mock.PropertyMock, return_value=set(["base-runtime"]))
|
||||
def test_set_cg_build_koji_tag(
|
||||
self, cfg, pdc, create_builder, koji_get_session, dbg):
|
||||
self, cfg, generic_resolver, resolver, create_builder, koji_get_session, dbg):
|
||||
"""
|
||||
Test that build.cg_build_koji_tag is set.
|
||||
"""
|
||||
with app.app_context():
|
||||
pdc.get_module_tag.return_value = "module-testmodule-master-20170109091357"
|
||||
base_mmd = _modulemd.ModuleMetadata()
|
||||
base_mmd.name = "base-runtime"
|
||||
base_mmd.stream = "f27"
|
||||
pdc.get_module_build_dependencies.return_value = {
|
||||
"module-bootstrap-tag": base_mmd}
|
||||
|
||||
scheduler_init_data()
|
||||
koji_session = mock.MagicMock()
|
||||
@@ -230,6 +243,13 @@ class TestModuleWait(unittest.TestCase):
|
||||
"module-build-macros-1-1")
|
||||
create_builder.return_value = builder
|
||||
|
||||
resolver = mock.MagicMock()
|
||||
resolver.backend = 'pdc'
|
||||
resolver.get_module_tag.return_value = "module-testmodule-master-20170109091357"
|
||||
resolver.get_module_build_dependencies.return_value = {
|
||||
"module-bootstrap-tag": base_mmd}
|
||||
generic_resolver.create.return_value = resolver
|
||||
|
||||
msg = module_build_service.messaging.MBSModule(msg_id=None, module_build_id=1,
|
||||
module_build_state='some state')
|
||||
module_build_service.scheduler.handlers.modules.wait(
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user