From: Michael Tremer Date: Fri, 8 Sep 2023 14:48:35 +0000 (+0000) Subject: monitoring: Catch errors when we cannot create a build X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=003656a3534847acdc41d3c39b1419335e69579b;p=pbs.git monitoring: Catch errors when we cannot create a build Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/releasemonitoring.py b/src/buildservice/releasemonitoring.py index 7ba6308b..8dd824b3 100644 --- a/src/buildservice/releasemonitoring.py +++ b/src/buildservice/releasemonitoring.py @@ -29,6 +29,7 @@ import shutil import urllib.parse from . import base +from . import config from . import database from .decorators import * @@ -718,27 +719,28 @@ class Release(base.DataObject): log.info("Creating build for %s from %s" % (self, build)) try: - # Create a new repository - repo = await self.backend.repos.create( - self.monitoring.distro, "Test Build for %s" % self, owner=owner) - # Create a new temporary space for the async with self.backend.tempdir() as target: # Create a new source package file = await self._update_source_package(build.pkg, target) - # Upload the file - upload = await self.backend.uploads.create_from_local(file) + if file: + # Create a new repository + repo = await self.backend.repos.create( + self.monitoring.distro, "Test Build for %s" % self, owner=owner) - try: - # Create a package - package = await self.backend.packages.create(upload) + # Upload the file + upload = await self.backend.uploads.create_from_local(file) + + try: + # Create a package + package = await self.backend.packages.create(upload) - # Create the build - build = await self.backend.builds.create(repo, package, owner=owner) + # Create the build + build = await self.backend.builds.create(repo, package, owner=owner) - finally: - await upload.delete() + finally: + await upload.delete() # If anything went wrong, then remove the repository except Exception as e: @@ -762,39 +764,54 @@ class Release(base.DataObject): if not package.is_source(): raise RuntimeError("%s is not a source package" % package) + # Capture Pakfire's log + logger = config.PakfireLogger() + # Create temporary directory to extract the package to - async with self.backend.tempdir() as tmp: - # Path to downloaded files - files = os.path.join(tmp, "files") + try: + async with self.backend.tempdir() as tmp: + # Path to downloaded files + files = os.path.join(tmp, "files") - # Path to the makefile - makefile = os.path.join(tmp, "%s.nm" % package.name) + # Path to the makefile + makefile = os.path.join(tmp, "%s.nm" % package.name) - # Create a Pakfire instance from this distribution - async with self.monitoring.distro.pakfire() as p: - # Open the archive - archive = await asyncio.to_thread(p.open, package.path) + # Create a Pakfire instance from this distribution + async with self.monitoring.distro.pakfire(logger=logger) as p: + # Open the archive + archive = await asyncio.to_thread(p.open, package.path) - # Extract the archive into the temporary space - await asyncio.to_thread(archive.extract, path=tmp) + # Extract the archive into the temporary space + await asyncio.to_thread(archive.extract, path=tmp) - # XXX directories are being created with the wrong permissions - os.system("chmod a+x -R %s" % tmp) + # XXX directories are being created with the wrong permissions + os.system("chmod a+x -R %s" % tmp) - # Remove any downloaded files - await asyncio.to_thread(shutil.rmtree, files) + # Remove any downloaded files + await asyncio.to_thread(shutil.rmtree, files) - # Update the makefile - diff = await self._update_makefile(makefile) + # Update the makefile + diff = await self._update_makefile(makefile) - # Log the diff - log.info("Generated diff:\n%s" % diff) + # Log the diff + log.info("Generated diff:\n%s" % diff) + + # Store the diff + self._set_attribute("diff", diff) + + # Generate a new source package + return await asyncio.to_thread(p.dist, makefile, target) + + # If we could not create a new source package, this is okay and we will continue + # without. However, we will log the exception... + except Exception as e: + log.error("Could not create source package for %s" % self, exc_info=True) - # Store the diff - self._set_attribute("diff", diff) + return None - # Generate a new source package - return await asyncio.to_thread(p.dist, makefile, target) + # Store the Pakfire log + finally: + self._set_attribute("log", "%s" % logger) async def _update_makefile(self, path): """ diff --git a/src/database.sql b/src/database.sql index 959c1bf3..ce155aa6 100644 --- a/src/database.sql +++ b/src/database.sql @@ -699,7 +699,8 @@ CREATE TABLE public.release_monitoring_releases ( bug_id integer, build_id integer, diff text, - repo_id integer + repo_id integer, + log text );