Address CRW

- add pytest.raises
 - add **kwargs in PackagingUtility.run(...)
This commit is contained in:
jobrauer
2020-02-24 11:09:36 +01:00
parent 938c243450
commit a40f87e7d1
2 changed files with 31 additions and 36 deletions

View File

@@ -4,42 +4,39 @@ import pytest
from sh import ErrorReturnCode from sh import ErrorReturnCode
# expected error message
CANNOT_FIND_ANY_MODULE_BUILDS = "Cannot find any module builds" # ...
def test_buildrequire_invalid_module(pkg_util, scenario, repo, koji): def test_buildrequire_invalid_module(pkg_util, scenario, repo, koji):
""" """
Run a build with with an invalid 'build_require' module. Run a build with with an invalid 'build_require' module.
I.e.: required module is picked in such a way, I.e.: required module is picked in such a way,
that it is not tagged according to the the base module (platform) requirements, that it is not tagged according to the the base module (platform) requirements,
see platform's modulemd file and its 'koji_tag_with_modules' attribute see platform's modulemd file and its 'koji_tag_with_modules' attribute
(e.g.: platform: el-8.1.0 --> rhel-8.1.0-modules-build). (e.g.: platform: el-8.1.0 --> rhel-8.1.0-modules-build).
Koji resolver is expected to not be able to satisfy this build requirement Koji resolver is expected to not be able to satisfy this build requirement
and hence fail the build. and hence fail the build.
Assert that: Assert that:
* the module build hasn't been accepted by MBS: * the module build hasn't been accepted by MBS:
rhpkg utility returns something else than 0 rhpkg utility returns something else than 0
* "Cannot find any module build..." found on STDERR * "Cannot find any module build..." found on STDERR
If assert fails: If assert fails:
* cancel all triggered module builds. * cancel all triggered module builds.
""" """
repo.bump() repo.bump()
try: expected_error = "Cannot find any module builds"
builds = pkg_util.run("--optional", "rebuild_strategy=all") with pytest.raises(ErrorReturnCode) as excinfo:
# Override 'baked' (_err=sys.stderr) stderr redirect:
for build in builds: # Here we are fine with what plain sh.Command gives us
print("Canceling module-build {}...".format(build.id)) # (otherwise ErrorReturnCode.stderr is incomplete).
pkg_util.cancel(build) builds = pkg_util.run("--optional", "rebuild_strategy=all", _err=None)
try:
pytest.fail("Invalid 'build_require' was satisfied and module build was accepted by MBS!") for build in builds:
print("Canceling module-build {}...".format(build.id))
except ErrorReturnCode as e: pkg_util.cancel(build)
# expected outcome: build submission fails except:
assert CANNOT_FIND_ANY_MODULE_BUILDS in e.stderr.decode("utf-8") pass
assert expected_error in excinfo.value.stderr.decode("utf-8")

View File

@@ -167,15 +167,13 @@ class PackagingUtility:
def __init__(self, packaging_utility, mbs_api): def __init__(self, packaging_utility, mbs_api):
self._packaging_utility = Command(packaging_utility).bake( self._packaging_utility = Command(packaging_utility).bake(
# review: is redirect necessary? _out=sys.stdout,
# In case of failure, I can't find the stderr in the resulting exception object.. _err=sys.stderr,
# _out=sys.stdout,
# _err=sys.stderr,
_tee=True _tee=True
) )
self._mbs_api = mbs_api self._mbs_api = mbs_api
def run(self, *args, reuse=None): def run(self, *args, reuse=None, **kwargs):
"""Run one or more module builds """Run one or more module builds
:param args: Options and arguments for the build command :param args: Options and arguments for the build command
@@ -195,7 +193,7 @@ class PackagingUtility:
else: else:
build_ids = [reuse] build_ids = [reuse]
else: else:
stdout = self._packaging_utility("module-build", *args).stdout.decode("utf-8") stdout = self._packaging_utility("module-build", *args, **kwargs).stdout.decode("utf-8")
build_ids = re.findall(self._mbs_api + r"module-builds/(\d+)", stdout) build_ids = re.findall(self._mbs_api + r"module-builds/(\d+)", stdout)
return [Build(self._mbs_api, int(build_id)) for build_id in build_ids] return [Build(self._mbs_api, int(build_id)) for build_id in build_ids]