Skip to content

Commit 277abe0

Browse files
committed
improve fallback mechanism for source version matching
When searching in the upgrade paths map by the system version, we had implemented a fallback that allowed the upgrade process to find a target version even if the minor version of the system did not match exactly with the ones defined in the map. The fallback mechanism was implemented using additional definitions in the map which did not have a minor version explicitly defined and thus would be only used as a fallback when the system version did not match any minor version. This patch changes this fallback mechanism to instead search in the map by the latest minor version of the system's major version. The additional records are removed from the map as well.
1 parent 249cd3b commit 277abe0

File tree

2 files changed

+41
-28
lines changed

2 files changed

+41
-28
lines changed

commands/command_utils.py

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,30 @@ def get_major_version_from_a_valid_version(version):
8080
return version.split('.')[0]
8181

8282

83+
def _get_latest_version_with_matching_major_version(versions, major_version):
84+
"""
85+
Find the latest version from given list of available versions matching the provided major version.
86+
87+
Versioning schema: MAJOR.MINOR
88+
89+
:param list[str] versions: List of versions to choose from.
90+
:param str major_version: The major version for which to find the latest version.
91+
:rtype: str
92+
:returns: Latest version with given major version form the given versions list, or empty string when not found.
93+
"""
94+
latest_minor_version = -1
95+
for version in versions:
96+
version = version.split('.')
97+
if len(version) <= 1:
98+
continue # skip versions without a minor version
99+
if version[0] == major_version:
100+
minor_version = int(version[1])
101+
latest_minor_version = max(minor_version, latest_minor_version)
102+
if latest_minor_version == -1:
103+
return ''
104+
return f'{major_version}.{latest_minor_version}'
105+
106+
83107
def detect_sap_hana():
84108
"""
85109
Detect SAP HANA based on existence of /hana/shared/*/exe/linuxx86_64/hdb/sapcontrol
@@ -156,15 +180,6 @@ def get_upgrade_paths_config():
156180
return upgrade_paths_map
157181

158182

159-
def get_target_versions_from_config(src_version_id, distro, flavor):
160-
"""
161-
Retrieve all possible target versions from upgrade_paths_map.
162-
If no match is found returns empty list.
163-
"""
164-
upgrade_paths_map = get_upgrade_paths_config()
165-
return upgrade_paths_map.get(distro, {}).get(flavor, {}).get(src_version_id, [])
166-
167-
168183
def get_virtual_version_from_config(src_version_id, distro):
169184
"""
170185
Retrieve the virtual version for the given version from upgrade_paths_map.
@@ -179,8 +194,11 @@ def get_supported_target_versions(target_distro, flavour=get_upgrade_flavour()):
179194
"""
180195
Return a list of supported target versions for the given `flavour` of upgrade.
181196
The default value for `flavour` is `default`.
182-
"""
183197
198+
:param str flavour: One of the upgrade flavours.
199+
:rtype: list[str]
200+
:returns: List of supported target versions.
201+
"""
184202
os_release_contents = _retrieve_os_release_contents()
185203
current_version_id = os_release_contents.get('VERSION_ID', '')
186204
source_distro = os_release_contents.get('ID', '')
@@ -193,15 +211,18 @@ def get_supported_target_versions(target_distro, flavour=get_upgrade_flavour()):
193211
# when upconverting from centos, we need to lookup by virtual version
194212
current_version_id = get_virtual_version_from_config(current_version_id, source_distro)
195213

196-
target_versions = get_target_versions_from_config(current_version_id, target_distro, flavour)
214+
upgrade_paths_map = get_upgrade_paths_config()
215+
relevant_paths = upgrade_paths_map.get(source_distro, {}).get(flavour, {})
216+
target_versions = relevant_paths.get(current_version_id, [])
197217
if not target_versions:
198-
# If we cannot find a particular major.minor version in the map,
199-
# we fallback to pick a target version just based on a major version.
200-
# This can happen for example when testing not yet released versions.
201-
# But also removes the need to handle virtual versions on X->centos upgrades.
218+
# If we cannot find a particular major.minor version in the map, we treat
219+
# the system as if it was the latest minor version of its major version
220+
# defined in the upgrade paths map. This can happen for example when
221+
# testing not yet released versions.
222+
available_source_versions = relevant_paths.keys()
202223
major_version = get_major_version_from_a_valid_version(current_version_id)
203-
target_versions = get_target_versions_from_config(major_version, target_distro, flavour)
204-
224+
latest_version = _get_latest_version_with_matching_major_version(available_source_versions, major_version)
225+
target_versions = relevant_paths.get(latest_version, [])
205226
return target_versions
206227

207228

repos/system_upgrade/common/files/upgrade_paths.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,13 @@
55
"8.10": ["9.4", "9.6", "9.7", "9.8"],
66
"9.6": ["10.0"],
77
"9.7": ["10.1"],
8-
"9.8": ["10.2"],
9-
"7": ["8.10"],
10-
"8": ["9.4", "9.6"],
11-
"9": ["10.0"]
8+
"9.8": ["10.2"]
129
},
1310
"saphana": {
1411
"7.9": ["8.10"],
15-
"7": ["8.10"],
1612
"8.10": ["9.6", "9.4"],
17-
"8": ["9.6", "9.4"],
1813
"9.6": ["10.0"],
19-
"9.8": ["10.2"],
20-
"9": ["10.0"]
14+
"9.8": ["10.2"]
2115
}
2216
},
2317
"centos": {
@@ -34,9 +28,7 @@
3428
"almalinux": {
3529
"default": {
3630
"8.10": ["9.0", "9.1", "9.2", "9.3", "9.4", "9.5", "9.6", "9.7", "9.8"],
37-
"9.7": ["10.0", "10.1"],
38-
"8": ["9.0", "9.1", "9.2", "9.3", "9.4", "9.5", "9.6", "9.7", "9.8"],
39-
"9": ["10.0", "10.1"]
31+
"9.7": ["10.0", "10.1"]
4032
}
4133
}
4234
}

0 commit comments

Comments
 (0)