diff --git a/setup.py b/setup.py index d3f72dd8..c46f6a3f 100644 --- a/setup.py +++ b/setup.py @@ -61,6 +61,7 @@ def get_version(rel_path): 'kubeconfig', # BSD License 'jinja2', # BSD License 'jinja2-base64-filters', # MIT License + 'semver', # BSD License 'boto3' # Apache Software License ], extras_require={ diff --git a/src/mas/devops/mas.py b/src/mas/devops/mas.py index ac207574..46419753 100644 --- a/src/mas/devops/mas.py +++ b/src/mas/devops/mas.py @@ -18,6 +18,7 @@ from openshift.dynamic import DynamicClient from openshift.dynamic.exceptions import NotFoundError, ResourceNotFoundError, UnauthorizedError from jinja2 import Environment, FileSystemLoader +import semver from .ocp import getStorageClasses from .olm import getSubscription @@ -305,3 +306,41 @@ def patchPendingPVC(dynClient: DynamicClient, namespace: str, pvcName: str, stor except NotFoundError: logger.error(f"PVC {pvcName} does not exist") return False + + +def isVersionBefore(_compare_to_version, _current_version): + """ + The method does a modified semantic version comparison, + as we want to treat any pre-release as == to the real release + but in strict semantic versioning it is < + ie. '8.6.0-pre.m1dev86' is converted to '8.6.0' + """ + if _current_version is None: + print("Version is not informed. Returning False") + return False + + strippedVersion = _current_version.split("-")[0] + if '.x' in strippedVersion: + strippedVersion = strippedVersion.replace('.x', '.0') + current_version = semver.VersionInfo.parse(strippedVersion) + compareToVersion = semver.VersionInfo.parse(_compare_to_version) + return current_version.compare(compareToVersion) < 0 + + +def isVersionEqualOrAfter(_compare_to_version, _current_version): + """ + The method does a modified semantic version comparison, + as we want to treat any pre-release as == to the real release + but in strict semantic versioning it is < + ie. '8.6.0-pre.m1dev86' is converted to '8.6.0' + """ + if _current_version is None: + print("Version is not informed. Returning False") + return False + + strippedVersion = _current_version.split("-")[0] + if '.x' in strippedVersion: + strippedVersion = strippedVersion.replace('.x', '.0') + current_version = semver.VersionInfo.parse(strippedVersion) + compareToVersion = semver.VersionInfo.parse(_compare_to_version) + return current_version.compare(compareToVersion) >= 0 diff --git a/src/mas/devops/templates/pipelinerun-install.yml.j2 b/src/mas/devops/templates/pipelinerun-install.yml.j2 index 8c956bad..242270cd 100644 --- a/src/mas/devops/templates/pipelinerun-install.yml.j2 +++ b/src/mas/devops/templates/pipelinerun-install.yml.j2 @@ -816,6 +816,68 @@ spec: value: "{{ mas_aibroker_db_secret_value }}" {%- endif %} +# TODO: Fix type for storage sizes and max conn pool size +{%- if mas_app_channel_facilities is defined and mas_app_channel_facilities != "" %} + + # Real Estate anda Facilities Application + # ------------------------------------------------------------------------- + - name: mas_app_channel_facilities + value: "{{ mas_app_channel_facilities }}" + +{%- if mas_ws_facilities_size is defined and mas_ws_facilities_size != "" %} + - name: mas_ws_facilities_size + value: "{{ mas_ws_facilities_size }}" +{%- endif %} +{%- if mas_ws_facilities_routes_timeout is defined and mas_ws_facilities_routes_timeout != "" %} + - name: mas_ws_facilities_routes_timeout + value: "{{ mas_ws_facilities_routes_timeout }}" +{%- endif %} +{%- if mas_ws_facilities_liberty_extension_XML is defined and mas_ws_facilities_liberty_extension_XML != "" %} + - name: mas_ws_facilities_liberty_extension_XML + value: "{{ mas_ws_facilities_liberty_extension_XML }}" +{%- endif %} +{%- if mas_ws_facilities_vault_secret is defined and mas_ws_facilities_vault_secret != "" %} + - name: mas_ws_facilities_vault_secret + value: "{{ mas_ws_facilities_vault_secret }}" +{%- endif %} +{%- if mas_ws_facilities_pull_policy is defined and mas_ws_facilities_pull_policy != "" %} + - name: mas_ws_facilities_pull_policy + value: "{{ mas_ws_facilities_pull_policy }}" +{%- endif %} + - name: mas_ws_facilities_storage_log_class + value: "{{ mas_ws_facilities_storage_log_class }}" +{%- if mas_ws_facilities_storage_log_mode is defined and mas_ws_facilities_storage_log_mode != "" %} + - name: mas_ws_facilities_storage_log_mode + value: "{{ mas_ws_facilities_storage_log_mode }}" +{%- endif %} +# {%- if mas_ws_facilities_storage_log_size is defined and mas_ws_facilities_storage_log_size != "" %} +# - name: mas_ws_facilities_storage_log_size +# value: "{{ mas_ws_facilities_storage_log_size }}" +# {%- endif %} + - name: mas_ws_facilities_storage_userfiles_class + value: "{{ mas_ws_facilities_storage_userfiles_class }}" +{%- if mas_ws_facilities_storage_userfiles_mode is defined and mas_ws_facilities_storage_userfiles_mode != "" %} + - name: mas_ws_facilities_storage_userfiles_mode + value: "{{ mas_ws_facilities_storage_userfiles_mode }}" +{%- endif %} +# {%- if mas_ws_facilities_storage_userfiles_size is defined and mas_ws_facilities_storage_userfiles_size != "" %} +# - name: mas_ws_facilities_storage_userfiles_size +# value: "{{ mas_ws_facilities_storage_userfiles_size }}" +# {%- endif %} +{%- if mas_ws_facilities_dwfagents is defined and mas_ws_facilities_dwfagents != "" %} + - name: mas_ws_facilities_dwfagents + value: "{{ mas_ws_facilities_dwfagents }}" +{%- endif %} +# {%- if mas_ws_facilities_db_maxconnpoolsize is defined and mas_ws_facilities_db_maxconnpoolsize != "" %} +# - name: mas_ws_facilities_db_maxconnpoolsize +# value: "{{ mas_ws_facilities_db_maxconnpoolsize }}" +# {%- endif %} + + - name: db2_action_facilities + value: "{{ db2_action_facilities}}" + +{%- endif %} + workspaces: # The generated configuration files # ------------------------------------------------------------------------- diff --git a/test/src/test_mas.py b/test/src/test_mas.py index a1d9faf8..79db0ac6 100644 --- a/test/src/test_mas.py +++ b/test/src/test_mas.py @@ -62,3 +62,17 @@ def test_is_airgap_install(): # The cluster we are using to test with does not have the MAS ICSP or IDMS installed assert mas.isAirgapInstall(dynClient) is False assert mas.isAirgapInstall(dynClient, checkICSP=False) is False + + +def test_version_before(): + assert mas.isVersionBefore('9.1.0', '9.1.x-feature') is False + assert mas.isVersionBefore('9.1.0', '9.0.0') is True + assert mas.isVersionBefore('8.11.1', '9.1.0') is False + assert mas.isVersionBefore('9.1.0', '9.1.x-stable') is False + + +def test_version_equal_of_after(): + assert mas.isVersionEqualOrAfter('9.1.0', '9.2.x-feature') is True + assert mas.isVersionEqualOrAfter('9.1.0', '9.0.0') is False + assert mas.isVersionEqualOrAfter('8.11.1', '9.1.0') is True + assert mas.isVersionEqualOrAfter('9.2.0', '9.1.x-stable') is False