PR#1715: List missing streams in exception message.

Merges #1715
https://pagure.io/fm-orchestrator/pull-request/1715

Fixes: #1574
https://pagure.io/fm-orchestrator/issue/1574
Error message improvement
This commit is contained in:
Mike McLean
2021-06-25 15:49:12 -04:00
4 changed files with 15 additions and 8 deletions

View File

@@ -134,14 +134,15 @@ def get_base_module_mmds(db_session, mmd):
old versions of the base module based on the stream version.
:param Modulemd mmd: Input modulemd metadata.
:rtype: dict with lists of Modulemd
:return: Dict with "ready" or "garbage" state name as a key and list of MMDs of base modules
buildrequired by `mmd` as a value.
:rtype: dict with lists of Modulemd and missing stream strings.
:return: Dict with "ready" or "garbage" state name as a key and list of MMDs of
base modules buildrequired by `mmd` as a value. Also includes "missing" as
a key and a list of base module streams that were not found.
"""
from module_build_service.common import models
seen = set()
ret = {"ready": [], "garbage": []}
ret = {"ready": [], "garbage": [], "missing": []}
resolver = GenericResolver.create(db_session, conf)
for deps in mmd.get_dependencies():
@@ -172,6 +173,7 @@ def get_base_module_mmds(db_session, mmd):
# zero or one module build.
mmds = resolver.get_module_modulemds(name, stream)
if not mmds:
ret["missing"] += [ns]
continue
base_mmd = mmds[0]

View File

@@ -187,9 +187,13 @@ def get_mmds_required_by_module_recursively(
base_module_mmds = get_base_module_mmds(db_session, mmd)
if not base_module_mmds["ready"]:
base_module_choices = " or ".join(conf.base_module_names)
missing = base_module_mmds["missing"]
missing_msg = ""
if missing:
missing_msg = " Missing streams are ({}).".format(", ".join(missing))
raise UnprocessableEntity(
"None of the base module ({}) streams in the buildrequires section could be found"
.format(base_module_choices)
"None of the base module ({}) streams in the buildrequires section could be found.{}"
.format(base_module_choices, missing_msg)
)
# Add base modules to `mmds`.

View File

@@ -100,6 +100,7 @@ class TestResolve:
expected = {}
expected["ready"] = {"platform:foo29", "platform:foo30"}
expected["garbage"] = {"platform:foo28"}
expected["missing"] = set()
# Verify no duplicates were returned before doing set operations
assert len(mmds) == len(expected)

View File

@@ -1035,7 +1035,7 @@ class TestSubmitBuild:
"status": 422,
"message": (
"None of the base module (platform) streams in the buildrequires section "
"could be found"
"could be found. Missing streams are (platform:Go)."
),
"error": "Unprocessable Entity",
}
@@ -2395,7 +2395,7 @@ class TestSubmitBuild:
"status": 422,
"message": (
"None of the base module (platform) streams in the buildrequires "
"section could be found"
"section could be found. Missing streams are (platform:28.0.0)."
),
}
assert rv.status_code == 422