#90 allow resubmit of builds + improved debugging
Closed 7 years ago by nphilipp. Opened 7 years ago by lkocman.
lkocman/fm-orchestrator enable-resubmit  into  master

file modified
-2
@@ -111,8 +111,6 @@ 

              if msg_obj:

                  return msg_obj

  

-         log.debug('Skipping unrecognized message with the topic "{0}"'

-                      .format(topic))

          return None

  

  

@@ -106,7 +106,7 @@ 

          dependencies, tag = _get_deps_and_tag()

      except ValueError:

          log.exception("Failed to get module info from PDC. Max retries reached.")

-         build.transition(config, state="build")  # Wait for the buildroot to be ready.a

+         build.transition(config, state="failed")

          session.commit()

          raise

  

file modified
+43 -24
@@ -30,11 +30,9 @@ 

  from flask import request, jsonify

  from flask.views import MethodView

  import json

- import logging

  import modulemd

  import os

  import rida.auth

- import rida.logger

  import rida.scm

  import shutil

  import tempfile
@@ -85,18 +83,22 @@ 

          try:

              r = json.loads(request.get_data().decode("utf-8"))

          except:

+             log.error('Invalid JSON submitted')

              raise ValidationError('Invalid JSON submitted')

  

          if "scmurl" not in r:

+             log.error('Missing scmurl')

              raise ValidationError('Missing scmurl')

  

          url = r["scmurl"]

          if not any(url.startswith(prefix) for prefix in conf.scmurls):

+             log.error('The submitted scmurl is not allowed')

              raise Unauthorized("The submitted scmurl is not allowed")

  

          yaml = ""

          td = None

          try:

+             log.debug('Verifying modulemd')

              td = tempfile.mkdtemp()

              scm = rida.scm.SCM(url, conf.scmurls)

              cod = scm.checkout(td)
@@ -117,23 +119,34 @@ 

          try:

              mmd.loads(yaml)

          except:

+             log.error('Invalid modulemd')

              raise UnprocessableEntity('Invalid modulemd')

  

-         if models.ModuleBuild.query.filter_by(name=mmd.name,

+         module = models.ModuleBuild.query.filter_by(name=mmd.name,

                                                version=mmd.version,

-                                               release=mmd.release).first():

-             raise Conflict('Module already exists')

- 

-         module = models.ModuleBuild.create(

-             db.session,

-             conf,

-             name=mmd.name,

-             version=mmd.version,

-             release=mmd.release,

-             modulemd=yaml,

-             scmurl=url,

-             username=username

-         )

+                                               release=mmd.release).first()

+         if module:

+             log.debug('Checking whether module build already exist.')

+              # TODO: make this configurable we might want to allow resubmit of any stucked build on DEV no matter the state

+             if module.state not in (models.BUILD_STATES['failed']):

+                 log.error('Module (state=%s) already exists. Only new or failed builds are allowed.' % module.state)

+                 raise Conflict('Module (state=%s) already exists. Only new or failed builds are allowed.' % module.state)

+             log.debug('Resuming existing module build %r' % module)

+             module.username = username

+             module.transition(conf, models.BUILD_STATES["init"])

+             log.info("Resumed existing module build in previous state %s" % module.state)

+         else:

+             log.debug('Creating new module build')

+             module = models.ModuleBuild.create(

+                 db.session,

+                 conf,

+                 name=mmd.name,

+                 version=mmd.version,

+                 release=mmd.release,

+                 modulemd=yaml,

+                 scmurl=url,

+                 username=username

+             )

  

          # List of (pkg_name, git_url) tuples to be used to check

          # the availability of git URLs paralelly later.
@@ -166,6 +179,7 @@ 

              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])
@@ -178,19 +192,24 @@ 

          for pkgname, pkg in mmd.components.rpms.packages.items():

              full_url = pkg["repository"] + "?#" + pkg["commit"]

  

-             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 build 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"])

          db.session.add(module)

          db.session.commit()

-         logging.info("%s submitted build of %s-%s-%s", username, mmd.name,

+         log.info("%s submitted build of %s-%s-%s", username, mmd.name,

                       mmd.version, mmd.release)

          return jsonify(module.json()), 201

  

Hi guys,

sorry for mixing these together but I couldn't add resubmit without this debug info.
Also I did fix transition to failed state in case that we couldn't get tag from PDC

Tested on my internal rida instance and koji-stage

lkocman@fedora:~/Workspace/modularity/modules/testmodule$ fedpkg --config /etc/rpkg/local.conf module-build
Building testmodule 4.3.47

Lubos

rebased

7 years ago

It would be nice to add rida.config resume_states where we could set any state in devel config but only failed for production. We usually get stuck in other than failed states as of now ... like something failed during building an exception ... BANG! stuck at BUILD_STATES['building']

rebased

7 years ago

LGTM, I'll sprinkle some typo- and pep8-fixing over it and merge.

Merged with the aforementioned changes in commit 0b6ef0d.

Pull-Request has been closed by nphilipp

7 years ago