Skip to content

Commit

Permalink
Merge pull request #775 from NethServer/bug-7211
Browse files Browse the repository at this point in the history
Specify error reason for incompatible apps

Refs NethServer/dev#7211
  • Loading branch information
DavidePrincipi authored Dec 18, 2024
2 parents 644441d + 473f331 commit 2e7d6ed
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
40 changes: 31 additions & 9 deletions core/imageroot/usr/local/agent/pypkg/cluster/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def get_latest_module(module, rdb):
"""Find most recent version of the given module
"""
for m in list_available(rdb, skip_core_modules=False):
if m["id"] == module:
if m["id"] == module and len(m['versions']) > 0:
# We assume at index 0 we find the latest tag:
return m["source"] + ':' + m['versions'][0]['tag']

Expand Down Expand Up @@ -274,9 +274,25 @@ def list_available(rdb, skip_core_modules=False):
if not _repo_has_testing_flag(rdb, omod["repository"]):
# Ignore testing releases for new installations:
omod["versions"] = list(filter(lambda v: _tag_is_stable(v["tag"]), omod["versions"]))
omod["versions"] = list(filter(lambda v: _min_core_ok(v, leader_core_version), omod["versions"]))
if not omod["versions"]:
continue # Ignore modules with no versions
# Check the min-core label compatibility:
omod_core_compat_versions = list(filter(lambda v: _min_core_ok(v, leader_core_version), omod["versions"]))
if omod_core_compat_versions:
omod["versions"] = omod_core_compat_versions
else:
# There are no compatible versions because current core is too old
try:
core_min_required = str(min(list(map(lambda mv: semver.Version.parse(mv['labels']['org.nethserver.min-core']), omod['versions']))))
except:
core_min_required = "0.0.0"
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)
omod["versions"] = []
omod["no_version_reason"] = {
"message": "core_version_too_low",
"params": {
"core_cur": str(leader_core_version),
"core_min": str(core_min_required),
},
}
omod["certification_level"] = _calc_certification_level(omod, bool(hsubscription))
try:
if skip_core_modules and 'core_module' in omod["versions"][0]['labels']['org.nethserver.flags']:
Expand All @@ -287,12 +303,18 @@ def list_available(rdb, skip_core_modules=False):
package_is_rootfull = omod["versions"][0]["labels"]["org.nethserver.rootfull"] == "1"
except:
package_is_rootfull = False
# Ignore untrusted rootfull application, if a subscription is active
omod['rootfull'] = package_is_rootfull
# Block untrusted rootfull application, if a subscription is active
if hsubscription and package_is_rootfull and omod["certification_level"] < 3:
print(agent.SD_WARNING + f"Ignoring image of rootfull application {omod['source']}: certification_level {omod['certification_level']} is too low", file=sys.stderr)
continue # skip package
else:
omod['rootfull'] = package_is_rootfull
print(agent.SD_WARNING + f"Rootfull application {omod['source']} has no valid version: certification_level {omod['certification_level']} is too low", file=sys.stderr)
omod["versions"] = []
omod["no_version_reason"] = {
"message": "rootfull_certification_level_too_low",
"params": {
"certification_cur": str(omod['certification_level']),
"certification_min": "3",
},
}
modules.append(omod)
return modules

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@
"description": "Date and time of last modification to remote repodata"
},
"disabled_updates_reason": {
"enum": ["", "ns7_migration"],
"enum": [
"",
"ns7_migration"
],
"description": "A non-empty strings indicates that updates are disabled for some reason. The string value identifies the reason."
},
"updates": {
Expand Down Expand Up @@ -322,6 +325,28 @@
]
}
},
"no_version_reason": {
"type": "object",
"description": "If the versions array is empty, this object is present and explains why.",
"required": [
"message"
],
"properties": {
"message": {
"type": "string",
"description": "Reason identifier"
},
"params": {
"type": "object",
"description": "Parameters for the reason explanation",
"patternProperties": {
".": {
"type": "string"
}
}
}
}
},
"versions": {
"type": "array",
"items": {
Expand Down

0 comments on commit 2e7d6ed

Please sign in to comment.