|
18 | 18 | from openshift.dynamic import DynamicClient
|
19 | 19 | from openshift.dynamic.exceptions import NotFoundError, ResourceNotFoundError, UnauthorizedError
|
20 | 20 | from jinja2 import Environment, FileSystemLoader
|
| 21 | +import semver |
21 | 22 |
|
22 | 23 | from .ocp import getStorageClasses
|
23 | 24 | from .olm import getSubscription
|
@@ -305,3 +306,41 @@ def patchPendingPVC(dynClient: DynamicClient, namespace: str, pvcName: str, stor
|
305 | 306 | except NotFoundError:
|
306 | 307 | logger.error(f"PVC {pvcName} does not exist")
|
307 | 308 | return False
|
| 309 | + |
| 310 | + |
| 311 | +def isVersionBefore(_compare_to_version, _current_version): |
| 312 | + """ |
| 313 | + The method does a modified semantic version comparison, |
| 314 | + as we want to treat any pre-release as == to the real release |
| 315 | + but in strict semantic versioning it is < |
| 316 | + ie. '8.6.0-pre.m1dev86' is converted to '8.6.0' |
| 317 | + """ |
| 318 | + if _current_version is None: |
| 319 | + print("Version is not informed. Returning False") |
| 320 | + return False |
| 321 | + |
| 322 | + strippedVersion = _current_version.split("-")[0] |
| 323 | + if '.x' in strippedVersion: |
| 324 | + strippedVersion = strippedVersion.replace('.x', '.0') |
| 325 | + current_version = semver.VersionInfo.parse(strippedVersion) |
| 326 | + compareToVersion = semver.VersionInfo.parse(_compare_to_version) |
| 327 | + return current_version.compare(compareToVersion) < 0 |
| 328 | + |
| 329 | + |
| 330 | +def isVersionAfter(_compare_to_version, _current_version): |
| 331 | + """ |
| 332 | + The method does a modified semantic version comparison, |
| 333 | + as we want to treat any pre-release as == to the real release |
| 334 | + but in strict semantic versioning it is < |
| 335 | + ie. '8.6.0-pre.m1dev86' is converted to '8.6.0' |
| 336 | + """ |
| 337 | + if _current_version is None: |
| 338 | + print("Version is not informed. Returning False") |
| 339 | + return False |
| 340 | + |
| 341 | + strippedVersion = _current_version.split("-")[0] |
| 342 | + if '.x' in strippedVersion: |
| 343 | + strippedVersion = strippedVersion.replace('.x', '.0') |
| 344 | + current_version = semver.VersionInfo.parse(strippedVersion) |
| 345 | + compareToVersion = semver.VersionInfo.parse(_compare_to_version) |
| 346 | + return current_version.compare(compareToVersion) >= 0 |
0 commit comments