#87 Catch problems with rpmautospec in the build root
Merged 4 years ago by pingou. Opened 4 years ago by nphilipp.
fedora-infra/ nphilipp/rpmautospec master--abort-on-rpmautospec-buildroot-crash  into  master

@@ -86,12 +86,19 @@ 

      br_packages = buildroot.getPackageList()

      if not any(p["name"] == "rpmautospec" for p in br_packages):

          _log.info("Installing rpmautospec into build root")

-         buildroot.mock(["--install", "rpmautospec"])

+         status = buildroot.mock(["--install", "rpmautospec"])

+         if status:

+             raise koji.BuildError("Installing `rpmautospec` into the build root failed.")

  

      srcdir_within = shlex.quote(buildroot.path_without_to_within(srcdir))

-     buildroot.mock(

+     status = buildroot.mock(

          ["--shell", f"rpmautospec --debug process-distgit --process-specfile {srcdir_within}"]

      )

  

+     if status:

+         raise koji.BuildError(

+             f"Running `rpmautospec` inside the build root failed (status: {status})"

+         )

+ 

      # Restore log level of the buildroot logger

      buildroot.logger.level = buildroot_loglevel

@@ -1,6 +1,7 @@ 

  import shlex

  from unittest import mock

  

+ import koji

  import pytest

  

  from koji_plugins.rpmautospec_builder import process_distgit_cb
@@ -52,6 +53,8 @@ 

              "rpmautospec installed",

              "other taskinfo method",

              "skip processing",

+             "buildroot install fails",

+             "buildroot cmd fails",

          ),

      )

      @mock.patch("rpmautospec.process_distgit.needs_processing")
@@ -74,7 +77,9 @@ 

          buildroot_supplied = testcase != "no buildroot supplied"

          rpmautospec_installed = testcase == "rpmautospec installed"

          taskinfo_method_responsible = testcase != "other taskinfo method"

-         skip_processing = testcase != "skip processing"

+         skip_processing = testcase == "skip processing"

+         buildroot_install_fails = testcase == "buildroot install fails"

+         buildroot_cmd_fails = testcase == "buildroot cmd fails"

  

          # prepare test environment

          srcdir_within = "/builddir/build/BUILD/something with spaces"
@@ -89,6 +94,7 @@ 

              "taskinfo": {"method": "buildSRPMFromSCM"},

              "session": koji_session,

          }

+         mock_retvals = []

  

          if not taskinfo_method_responsible:

              kwargs["taskinfo"]["method"] = "not the method you're looking for"
@@ -105,6 +111,11 @@ 

  

          if rpmautospec_installed:

              installed_packages.append({"name": "rpmautospec", "version": "0.1", "release": "1"})

+         else:

+             if buildroot_install_fails:

+                 mock_retvals.append(1)

+             else:

+                 mock_retvals.append(0)

  

          buildroot.getPackageList.return_value = installed_packages

  
@@ -115,8 +126,20 @@ 

  

          buildroot.path_without_to_within.return_value = srcdir_within

  

+         buildroot.mock.side_effect = mock_retvals

+ 

+         if buildroot_cmd_fails:

+             mock_retvals.append(128)

+         else:

+             mock_retvals.append(0)

+ 

          # test the callback

-         process_distgit_cb(*args, **kwargs)

+         if any(retval != 0 for retval in mock_retvals):

+             with pytest.raises(koji.BuildError):

+                 process_distgit_cb(*args, **kwargs)

+             return

+         else:

+             process_distgit_cb(*args, **kwargs)

  

          # verify what the callback did

          if not taskinfo_method_responsible:

Kill the build if executing it returns a status other than 0.

Signed-off-by: Nils Philippsen nils@redhat.com

Nice and easy :thumbsup: for me

Build failed.

rebased onto e12f1624ac025e172cff7842f459dc6a78858dc8

4 years ago

rebased onto bf4f193

4 years ago

Looks good to me and zuul seems happy with pytest :)

Needed some adjustment and a bug fix in the test for process_distgit_cb().

Build succeeded.

Zuul is happy but this isn't the latest commit :(

Pull-Request has been merged by pingou

4 years ago