Skip to content

Commit 2e7d6ed

Browse files
Merge pull request #775 from NethServer/bug-7211
Specify error reason for incompatible apps Refs NethServer/dev#7211
2 parents 644441d + 473f331 commit 2e7d6ed

File tree

2 files changed

+57
-10
lines changed

2 files changed

+57
-10
lines changed

core/imageroot/usr/local/agent/pypkg/cluster/modules.py

+31-9
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def get_latest_module(module, rdb):
175175
"""Find most recent version of the given module
176176
"""
177177
for m in list_available(rdb, skip_core_modules=False):
178-
if m["id"] == module:
178+
if m["id"] == module and len(m['versions']) > 0:
179179
# We assume at index 0 we find the latest tag:
180180
return m["source"] + ':' + m['versions'][0]['tag']
181181

@@ -274,9 +274,25 @@ def list_available(rdb, skip_core_modules=False):
274274
if not _repo_has_testing_flag(rdb, omod["repository"]):
275275
# Ignore testing releases for new installations:
276276
omod["versions"] = list(filter(lambda v: _tag_is_stable(v["tag"]), omod["versions"]))
277-
omod["versions"] = list(filter(lambda v: _min_core_ok(v, leader_core_version), omod["versions"]))
278-
if not omod["versions"]:
279-
continue # Ignore modules with no versions
277+
# Check the min-core label compatibility:
278+
omod_core_compat_versions = list(filter(lambda v: _min_core_ok(v, leader_core_version), omod["versions"]))
279+
if omod_core_compat_versions:
280+
omod["versions"] = omod_core_compat_versions
281+
else:
282+
# There are no compatible versions because current core is too old
283+
try:
284+
core_min_required = str(min(list(map(lambda mv: semver.Version.parse(mv['labels']['org.nethserver.min-core']), omod['versions']))))
285+
except:
286+
core_min_required = "0.0.0"
287+
print(agent.SD_WARNING + f"Application {omod['source']} has no version suitable for the installed Core {leader_core_version}. Minimum Core requirement is {core_min_required}.", file=sys.stderr)
288+
omod["versions"] = []
289+
omod["no_version_reason"] = {
290+
"message": "core_version_too_low",
291+
"params": {
292+
"core_cur": str(leader_core_version),
293+
"core_min": str(core_min_required),
294+
},
295+
}
280296
omod["certification_level"] = _calc_certification_level(omod, bool(hsubscription))
281297
try:
282298
if skip_core_modules and 'core_module' in omod["versions"][0]['labels']['org.nethserver.flags']:
@@ -287,12 +303,18 @@ def list_available(rdb, skip_core_modules=False):
287303
package_is_rootfull = omod["versions"][0]["labels"]["org.nethserver.rootfull"] == "1"
288304
except:
289305
package_is_rootfull = False
290-
# Ignore untrusted rootfull application, if a subscription is active
306+
omod['rootfull'] = package_is_rootfull
307+
# Block untrusted rootfull application, if a subscription is active
291308
if hsubscription and package_is_rootfull and omod["certification_level"] < 3:
292-
print(agent.SD_WARNING + f"Ignoring image of rootfull application {omod['source']}: certification_level {omod['certification_level']} is too low", file=sys.stderr)
293-
continue # skip package
294-
else:
295-
omod['rootfull'] = package_is_rootfull
309+
print(agent.SD_WARNING + f"Rootfull application {omod['source']} has no valid version: certification_level {omod['certification_level']} is too low", file=sys.stderr)
310+
omod["versions"] = []
311+
omod["no_version_reason"] = {
312+
"message": "rootfull_certification_level_too_low",
313+
"params": {
314+
"certification_cur": str(omod['certification_level']),
315+
"certification_min": "3",
316+
},
317+
}
296318
modules.append(omod)
297319
return modules
298320

core/imageroot/var/lib/nethserver/cluster/actions/list-modules/validate-output.json

+26-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,10 @@
195195
"description": "Date and time of last modification to remote repodata"
196196
},
197197
"disabled_updates_reason": {
198-
"enum": ["", "ns7_migration"],
198+
"enum": [
199+
"",
200+
"ns7_migration"
201+
],
199202
"description": "A non-empty strings indicates that updates are disabled for some reason. The string value identifies the reason."
200203
},
201204
"updates": {
@@ -322,6 +325,28 @@
322325
]
323326
}
324327
},
328+
"no_version_reason": {
329+
"type": "object",
330+
"description": "If the versions array is empty, this object is present and explains why.",
331+
"required": [
332+
"message"
333+
],
334+
"properties": {
335+
"message": {
336+
"type": "string",
337+
"description": "Reason identifier"
338+
},
339+
"params": {
340+
"type": "object",
341+
"description": "Parameters for the reason explanation",
342+
"patternProperties": {
343+
".": {
344+
"type": "string"
345+
}
346+
}
347+
}
348+
}
349+
},
325350
"versions": {
326351
"type": "array",
327352
"items": {

0 commit comments

Comments
 (0)