From 7f60db545a43ca3669a7043b03ba2424f091514b Mon Sep 17 00:00:00 2001 From: Valerij Maljulin Date: Fri, 12 Oct 2018 16:56:38 +0200 Subject: [PATCH] renaming koji_arches to arches Signed-off-by: Valerij Maljulin --- conf/config.py | 2 +- .../builder/KojiModuleBuilder.py | 15 +++---------- module_build_service/builder/base.py | 4 ++-- module_build_service/config.py | 14 ++++++------- module_build_service/utils/general.py | 21 +++++++++++++++++++ module_build_service/utils/submit.py | 2 +- tests/test_builder/test_koji.py | 2 +- tests/test_utils/test_utils.py | 2 +- 8 files changed, 37 insertions(+), 25 deletions(-) diff --git a/conf/config.py b/conf/config.py index 6d92b73f..f1598c62 100644 --- a/conf/config.py +++ b/conf/config.py @@ -28,7 +28,7 @@ class BaseConfiguration(object): MESSAGING_TOPIC_PREFIX = ['org.fedoraproject.prod'] KOJI_CONFIG = '/etc/module-build-service/koji.conf' KOJI_PROFILE = 'koji' - KOJI_ARCHES = ['i686', 'armv7hl', 'x86_64'] + ARCHES = ['i686', 'armv7hl', 'x86_64'] KOJI_REPOSITORY_URL = 'https://kojipkgs.fedoraproject.org/repos' KOJI_TAG_PREFIXES = ['module'] KOJI_ENABLE_CONTENT_GENERATOR = True diff --git a/module_build_service/builder/KojiModuleBuilder.py b/module_build_service/builder/KojiModuleBuilder.py index cfde17a1..86418d71 100644 --- a/module_build_service/builder/KojiModuleBuilder.py +++ b/module_build_service/builder/KojiModuleBuilder.py @@ -51,7 +51,7 @@ from module_build_service.errors import ProgrammingError from module_build_service.builder.base import GenericBuilder from module_build_service.builder.KojiContentGenerator import KojiContentGenerator -from module_build_service.utils import get_reusable_components, get_reusable_module +from module_build_service.utils import get_reusable_components, get_reusable_module, get_build_arches logging.basicConfig(level=logging.DEBUG) @@ -170,19 +170,10 @@ class KojiModuleBuilder(GenericBuilder): log.debug("Using koji_config: %s" % config.koji_config) self.koji_session = self.get_session(config, owner) - self.arches = config.koji_arches - - # Handle BASE_MODULE_KOJI_ARCHES. Find out the base modules in buildrequires - # section of XMD and set the Koji tag arches according to it. - if "mbs" in self.mmd.get_xmd().keys(): - for req_name, req_data in self.mmd.get_xmd()["mbs"]["buildrequires"].items(): - ns = ":".join([req_name, req_data["stream"]]) - if ns in config.base_module_koji_arches: - self.arches = config.base_module_koji_arches[ns] - break + self.arches = get_build_arches(self.mmd, self.config) if not self.arches: - raise ValueError("No koji_arches specified in the config.") + raise ValueError("No arches specified in the config.") # These eventually get populated by calling _connect and __prep is set to True self.module_tag = None # string diff --git a/module_build_service/builder/base.py b/module_build_service/builder/base.py index f214c799..257da98e 100644 --- a/module_build_service/builder/base.py +++ b/module_build_service/builder/base.py @@ -388,12 +388,12 @@ class GenericBuilder(six.with_metaclass(ABCMeta)): :param components: List of comopnent names to compute the weight for. :param arches: List of arches to build for or None. If the value is None, - conf.koji_arches will be used instead. + conf.arches will be used instead. :rtype: dict :return: {component_name: weight_as_float, ...} """ if not arches: - arches = conf.koji_arches + arches = conf.arches weights = {} diff --git a/module_build_service/config.py b/module_build_service/config.py index dca1a0e7..99f0fb38 100644 --- a/module_build_service/config.py +++ b/module_build_service/config.py @@ -175,7 +175,7 @@ class Config(object): 'type': str, 'default': None, 'desc': 'Koji config profile.'}, - 'koji_arches': { + 'arches': { 'type': list, 'default': [], 'desc': 'Koji architectures.'}, @@ -415,7 +415,7 @@ class Config(object): 'default': ['platform'], 'desc': ("List of base module names which define the product version " "(by their stream) of modules depending on them.")}, - 'base_module_koji_arches': { + 'base_module_arches': { 'type': dict, 'default': {}, 'desc': 'Per base-module name:stream Koji arches list.'}, @@ -642,15 +642,15 @@ class Config(object): .format(strategy, ', '.join(SUPPORTED_STRATEGIES))) self._rebuild_strategy = strategy - def _setifok_base_module_koji_arches(self, data): + def _setifok_base_module_arches(self, data): if not isinstance(data, dict): - raise ValueError("BASE_MODULE_KOJI_ARCHES must be a dict") + raise ValueError("BASE_MODULE_ARCHES must be a dict") for ns, arches in data.items(): if len(ns.split(":")) != 2: - raise ValueError("BASE_MODULE_KOJI_ARCHES keys must be in 'name:stream' format") + raise ValueError("BASE_MODULE_ARCHES keys must be in 'name:stream' format") if not isinstance(arches, list): - raise ValueError("BASE_MODULE_KOJI_ARCHES values must be lists") - self._base_module_koji_arches = data + raise ValueError("BASE_MODULE_ARCHES values must be lists") + self._base_module_arches = data def _setifok_rebuild_strategies_allowed(self, strategies): if not isinstance(strategies, list): diff --git a/module_build_service/utils/general.py b/module_build_service/utils/general.py index 6402ed3f..46543d09 100644 --- a/module_build_service/utils/general.py +++ b/module_build_service/utils/general.py @@ -355,3 +355,24 @@ def get_mmd_from_scm(url): whitelist_url=False, mandatory_checks=False) return mmd + + +def get_build_arches(mmd, config): + """ + Returns the list of architectures for which the module `mmd` should be built. + + :param mmd: Module MetaData + :param config: config (module_build_service.config.Config instance) + :return list of architectures + """ + arches = config.arches + + # Handle BASE_MODULE_ARCHES. Find out the base modules in buildrequires + # section of XMD and set the Koji tag arches according to it. + if "mbs" in mmd.get_xmd().keys(): + for req_name, req_data in mmd.get_xmd()["mbs"]["buildrequires"].items(): + ns = ":".join([req_name, req_data["stream"]]) + if ns in config.base_module_arches: + arches = config.base_module_arches[ns] + break + return arches diff --git a/module_build_service/utils/submit.py b/module_build_service/utils/submit.py index e4a29f40..28bfce1a 100644 --- a/module_build_service/utils/submit.py +++ b/module_build_service/utils/submit.py @@ -175,7 +175,7 @@ def format_mmd(mmd, scmurl, session=None): pkg.set_ref('master') if pkg.get_arches().size() == 0: arches = Modulemd.SimpleSet() - arches.set(conf.koji_arches) + arches.set(conf.arches) pkg.set_arches(arches) # Add missing data in included modules components diff --git a/tests/test_builder/test_koji.py b/tests/test_builder/test_koji.py index d32db3fb..f567dcfc 100644 --- a/tests/test_builder/test_koji.py +++ b/tests/test_builder/test_koji.py @@ -412,7 +412,7 @@ class TestKojiBuilder: weights = KojiModuleBuilder.get_build_weights(["httpd", "apr"]) assert weights == {"httpd": 1.5, "apr": 1.5} - @patch.object(conf, 'base_module_koji_arches', + @patch.object(conf, 'base_module_arches', new={"platform:xx": ["x86_64", "i686"]}) @pytest.mark.parametrize('blocklist', [False, True]) @pytest.mark.parametrize('custom_whitelist', [False, True]) diff --git a/tests/test_utils/test_utils.py b/tests/test_utils/test_utils.py index b9cd36b1..3d596e53 100644 --- a/tests/test_utils/test_utils.py +++ b/tests/test_utils/test_utils.py @@ -566,7 +566,7 @@ class TestUtils: module_build_service.utils.format_mmd(mmd1, None) for pkg in mmd1.get_rpm_components().values(): - assert set(pkg.get_arches().get()) == set(conf.koji_arches) + assert set(pkg.get_arches().get()) == set(conf.arches) mmd2 = Modulemd.Module().new_from_file(testmodule_mmd_path) mmd2.upgrade()