From dbe26fcfb5bb94c55308b7d8d396ada16d04f7d4 Mon Sep 17 00:00:00 2001 From: Courtney Pacheco Date: Tue, 25 Oct 2016 03:29:58 -0400 Subject: [PATCH] Adding code to handle componentless builds --- .../scheduler/handlers/components.py | 7 ++ module_build_service/views.py | 110 +++++++++--------- 2 files changed, 61 insertions(+), 56 deletions(-) diff --git a/module_build_service/scheduler/handlers/components.py b/module_build_service/scheduler/handlers/components.py index c058c329..602476fc 100644 --- a/module_build_service/scheduler/handlers/components.py +++ b/module_build_service/scheduler/handlers/components.py @@ -90,6 +90,13 @@ def _finalize(config, session, msg, state): # Find all of the sibling builds of this particular build. current_batch = parent.current_batch() + # If there are no components, transition module build state to 'done' + if not current_batch: + log.info("Batch is empty. Moving module state to DONE.") + parent.transition(config, module.BUILD_STATES['done']) + session.commit() + return + # Otherwise, check to see if all failed. If so, then we cannot continue on # to a next batch. This module build is doomed. if all([c.state != koji.BUILD_STATES['COMPLETE'] for c in current_batch]): diff --git a/module_build_service/views.py b/module_build_service/views.py index 6d4cb37f..ef10bccf 100644 --- a/module_build_service/views.py +++ b/module_build_service/views.py @@ -166,66 +166,64 @@ class ModuleBuildAPI(MethodView): # the availability of git URLs paralelly later. full_urls = [] - # List of (pkg_name, git_url) tuples to be used to check - # the availability of git URLs paralelly later. - full_urls = [] + # If the modulemd yaml specifies components, then submit them for build + if mmd.components: + for pkgname, pkg in mmd.components.rpms.packages.items(): + try: + if pkg.get("repository") and not conf.rpms_allow_repository: + raise Unauthorized( + "Custom component repositories aren't allowed") + if pkg.get("cache") and not conf.rpms_allow_cache: + raise Unauthorized("Custom component caches aren't allowed") + if not pkg.get("repository"): + pkg["repository"] = conf.rpms_default_repository + pkgname + if not pkg.get("cache"): + pkg["cache"] = conf.rpms_default_cache + pkgname + if not pkg.get("commit"): + try: + pkg["commit"] = module_build_service.scm.SCM( + pkg["repository"]).get_latest() + except Exception as e: + raise UnprocessableEntity( + "Failed to get the latest commit: %s" % pkgname) + except Exception: + module.transition(conf, models.BUILD_STATES["failed"]) + db.session.add(module) + db.session.commit() + raise - for pkgname, pkg in mmd.components.rpms.packages.items(): - try: - if pkg.get("repository") and not conf.rpms_allow_repository: - raise Unauthorized( - "Custom component repositories aren't allowed") - if pkg.get("cache") and not conf.rpms_allow_cache: - raise Unauthorized("Custom component caches aren't allowed") - if not pkg.get("repository"): - pkg["repository"] = conf.rpms_default_repository + pkgname - if not pkg.get("cache"): - pkg["cache"] = conf.rpms_default_cache + pkgname - if not pkg.get("commit"): - try: - pkg["commit"] = module_build_service.scm.SCM( - pkg["repository"]).get_latest() - except Exception as e: - raise UnprocessableEntity( - "Failed to get the latest commit: %s" % pkgname) - except Exception: - module.transition(conf, models.BUILD_STATES["failed"]) - db.session.add(module) - db.session.commit() - raise + full_url = pkg["repository"] + "?#" + pkg["commit"] + full_urls.append((pkgname, full_url)) - full_url = pkg["repository"] + "?#" + pkg["commit"] - full_urls.append((pkgname, full_url)) + log.debug("Checking scm urls") + # Checks the availability of SCM urls. + pool = ThreadPool(10) + err_msgs = pool.map(lambda data: "Cannot checkout {}".format(data[0]) + if not module_build_service.scm.SCM(data[1]).is_available() + else None, full_urls) + for err_msg in err_msgs: + if err_msg: + raise UnprocessableEntity(err_msg) - log.debug("Checking scm urls") - # Checks the availability of SCM urls. - pool = ThreadPool(10) - err_msgs = pool.map(lambda data: "Cannot checkout {}".format(data[0]) - if not module_build_service.scm.SCM(data[1]).is_available() - else None, full_urls) - for err_msg in err_msgs: - if err_msg: - raise UnprocessableEntity(err_msg) + for pkgname, pkg in mmd.components.rpms.packages.items(): + full_url = pkg["repository"] + "?#" + pkg["commit"] - for pkgname, pkg in mmd.components.rpms.packages.items(): - full_url = pkg["repository"] + "?#" + pkg["commit"] - - existing_build = models.ComponentBuild.query.filter_by( - module_id=module.id, package=pkgname).first() - if (existing_build - and existing_build.state != models.BUILD_STATES['done']): - existing_build.state = models.BUILD_STATES['init'] - db.session.add(existing_build) - else: - # XXX: what about components that were present in previous - # builds but are gone now (component reduction)? - build = models.ComponentBuild( - module_id=module.id, - package=pkgname, - format="rpms", - scmurl=full_url, - ) - db.session.add(build) + existing_build = models.ComponentBuild.query.filter_by( + module_id=module.id, package=pkgname).first() + if (existing_build + and existing_build.state != models.BUILD_STATES['done']): + existing_build.state = models.BUILD_STATES['init'] + db.session.add(existing_build) + else: + # XXX: what about components that were present in previous + # builds but are gone now (component reduction)? + build = models.ComponentBuild( + module_id=module.id, + package=pkgname, + format="rpms", + scmurl=full_url, + ) + db.session.add(build) module.modulemd = mmd.dumps() module.transition(conf, models.BUILD_STATES["wait"])