mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-02-13 01:54:59 +08:00
Address CRW
- add pytest.raises - add **kwargs in PackagingUtility.run(...)
This commit is contained in:
@@ -4,42 +4,39 @@ import pytest
|
||||
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):
|
||||
"""
|
||||
Run a build with with an invalid 'build_require' module.
|
||||
I.e.: required module is picked in such a way,
|
||||
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
|
||||
(e.g.: platform: el-8.1.0 --> rhel-8.1.0-modules-build).
|
||||
Run a build with with an invalid 'build_require' module.
|
||||
I.e.: required module is picked in such a way,
|
||||
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
|
||||
(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
|
||||
and hence fail the build.
|
||||
Koji resolver is expected to not be able to satisfy this build requirement
|
||||
and hence fail the build.
|
||||
|
||||
Assert that:
|
||||
* the module build hasn't been accepted by MBS:
|
||||
rhpkg utility returns something else than 0
|
||||
* "Cannot find any module build..." found on STDERR
|
||||
Assert that:
|
||||
* the module build hasn't been accepted by MBS:
|
||||
rhpkg utility returns something else than 0
|
||||
* "Cannot find any module build..." found on STDERR
|
||||
|
||||
If assert fails:
|
||||
* cancel all triggered module builds.
|
||||
If assert fails:
|
||||
* cancel all triggered module builds.
|
||||
|
||||
"""
|
||||
"""
|
||||
|
||||
repo.bump()
|
||||
|
||||
try:
|
||||
builds = pkg_util.run("--optional", "rebuild_strategy=all")
|
||||
|
||||
for build in builds:
|
||||
print("Canceling module-build {}...".format(build.id))
|
||||
pkg_util.cancel(build)
|
||||
|
||||
pytest.fail("Invalid 'build_require' was satisfied and module build was accepted by MBS!")
|
||||
|
||||
except ErrorReturnCode as e:
|
||||
# expected outcome: build submission fails
|
||||
assert CANNOT_FIND_ANY_MODULE_BUILDS in e.stderr.decode("utf-8")
|
||||
expected_error = "Cannot find any module builds"
|
||||
with pytest.raises(ErrorReturnCode) as excinfo:
|
||||
# Override 'baked' (_err=sys.stderr) stderr redirect:
|
||||
# Here we are fine with what plain sh.Command gives us
|
||||
# (otherwise ErrorReturnCode.stderr is incomplete).
|
||||
builds = pkg_util.run("--optional", "rebuild_strategy=all", _err=None)
|
||||
try:
|
||||
for build in builds:
|
||||
print("Canceling module-build {}...".format(build.id))
|
||||
pkg_util.cancel(build)
|
||||
except:
|
||||
pass
|
||||
assert expected_error in excinfo.value.stderr.decode("utf-8")
|
||||
|
||||
@@ -167,15 +167,13 @@ class PackagingUtility:
|
||||
|
||||
def __init__(self, packaging_utility, mbs_api):
|
||||
self._packaging_utility = Command(packaging_utility).bake(
|
||||
# review: is redirect necessary?
|
||||
# In case of failure, I can't find the stderr in the resulting exception object..
|
||||
# _out=sys.stdout,
|
||||
# _err=sys.stderr,
|
||||
_out=sys.stdout,
|
||||
_err=sys.stderr,
|
||||
_tee=True
|
||||
)
|
||||
self._mbs_api = mbs_api
|
||||
|
||||
def run(self, *args, reuse=None):
|
||||
def run(self, *args, reuse=None, **kwargs):
|
||||
"""Run one or more module builds
|
||||
|
||||
:param args: Options and arguments for the build command
|
||||
@@ -195,7 +193,7 @@ class PackagingUtility:
|
||||
else:
|
||||
build_ids = [reuse]
|
||||
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)
|
||||
return [Build(self._mbs_api, int(build_id)) for build_id in build_ids]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user