From 575cb425442e7ec35cc73585146e62d56386bf94 Mon Sep 17 00:00:00 2001 From: Shivam Durgbuns Date: Thu, 24 Oct 2024 10:50:14 +0530 Subject: [PATCH 1/5] adding --config-file param functionality to deployment Signed-off-by: Shivam Durgbuns --- .../external_cluster_with_config_file.yaml | 3 ++ .../helpers/external_cluster_helpers.py | 28 ++++++++++++++- ocs_ci/utility/utils.py | 34 +++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 conf/ocsci/external_cluster_with_config_file.yaml diff --git a/conf/ocsci/external_cluster_with_config_file.yaml b/conf/ocsci/external_cluster_with_config_file.yaml new file mode 100644 index 00000000000..51c5c129595 --- /dev/null +++ b/conf/ocsci/external_cluster_with_config_file.yaml @@ -0,0 +1,3 @@ +--- +ENV_DATA: + use_config_file: true diff --git a/ocs_ci/deployment/helpers/external_cluster_helpers.py b/ocs_ci/deployment/helpers/external_cluster_helpers.py index 25f660dc32e..a0c2abc3e50 100644 --- a/ocs_ci/deployment/helpers/external_cluster_helpers.py +++ b/ocs_ci/deployment/helpers/external_cluster_helpers.py @@ -36,6 +36,7 @@ decode, download_file, wait_for_machineconfigpool_status, + params_to_configini_file, ) logger = logging.getLogger(__name__) @@ -296,6 +297,21 @@ def update_permission_caps(self, user=None): out = self.run_exporter_script(params=params) logger.info(f"updated permissions for the user are set as {out}") + def upload_config_ini_file(self): + """ + Upload config.ini fikle that is used for external cluster + exporter script --config-file param + + Returns: + str: absolute path to config.ini gile + + """ + script_path = params_to_configini_file() + upload_file( + self.host, script_path, script_path, self.user, self.password, self.ssh_key + ) + return script_path + def run_exporter_script(self, params): """ Runs the exporter script on RHCS cluster @@ -324,7 +340,17 @@ def run_exporter_script(self, params): python_version = "python" # run the exporter script on external RHCS cluster - cmd = f"{python_version} {script_path} {params}" + ocs_version = version.get_semantic_ocs_version_from_config() + if ( + "--upgrade" not in params + and ocs_version >= version.VERSION_4_17 + and config.ENV_DATA.get("use_config_file") + ): + # upload config.ini file to external RHCS cluster + config_ini_path = self.upload_config_ini_file() + cmd = f"{python_version} {script_path} --config-file {config_ini_path}" + else: + cmd = f"{python_version} {script_path} {params}" retcode, out, err = self.rhcs_conn.exec_cmd(cmd) if retcode != 0 or err != "": logger.error( diff --git a/ocs_ci/utility/utils.py b/ocs_ci/utility/utils.py index 624f7eebf8c..48c2db7bd04 100644 --- a/ocs_ci/utility/utils.py +++ b/ocs_ci/utility/utils.py @@ -27,6 +27,7 @@ import pexpect import pytest import unicodedata +import tempfile import hcl2 import requests @@ -5256,3 +5257,36 @@ def is_z_stream_upgrade(): return config.UPGRADE.get("pre_upgrade_ocs_version", "") == config.UPGRADE.get( "upgrade_ocs_version", "" ) +def create_config_ini_file(params): + """ + This function will create a config ini file for the params given. + Use case: + can be used in external-cluster-exporter script --config-file argument + + Args: + params (str): Parameter to pass to be converted into config.ini file. + + Returns: + config_ini_file.name (str): Path to the config.ini file. + """ + data = "[Configurations]\n" + import re + + pattern = r"--([\w-]+) ([.:\w-]+)" + matches = re.finditer(pattern, params, re.MULTILINE) + for match in matches: + arg, val = match.groups() + line = f"{arg} = {val}\n" + data += line + data = data.strip() + config_ini_file = tempfile.NamedTemporaryFile( + mode="w+", + prefix="external-cluster-config-", + suffix=".ini", + delete=False, + ) + with open(config_ini_file.name, "w") as fd: + fd.write(data) + log.info(f"config.ini fike for cluster is located at {config_ini_file.name}") + + return config_ini_file.name From 43a9133f102d3cd134956a136a6d27f8885e96b8 Mon Sep 17 00:00:00 2001 From: Shivam Durgbuns Date: Thu, 24 Oct 2024 13:37:47 +0530 Subject: [PATCH 2/5] Adding missing arguments for the function upload_config_ini_file Signed-off-by: Shivam Durgbuns --- ocs_ci/deployment/helpers/external_cluster_helpers.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ocs_ci/deployment/helpers/external_cluster_helpers.py b/ocs_ci/deployment/helpers/external_cluster_helpers.py index a0c2abc3e50..40add14e625 100644 --- a/ocs_ci/deployment/helpers/external_cluster_helpers.py +++ b/ocs_ci/deployment/helpers/external_cluster_helpers.py @@ -297,16 +297,19 @@ def update_permission_caps(self, user=None): out = self.run_exporter_script(params=params) logger.info(f"updated permissions for the user are set as {out}") - def upload_config_ini_file(self): + def upload_config_ini_file(self, params): """ - Upload config.ini fikle that is used for external cluster + Upload config.ini file that is used for external cluster exporter script --config-file param + Args: + params (str): Parameter to pass to exporter script + Returns: str: absolute path to config.ini gile """ - script_path = params_to_configini_file() + script_path = params_to_configini_file(params=params) upload_file( self.host, script_path, script_path, self.user, self.password, self.ssh_key ) @@ -347,7 +350,7 @@ def run_exporter_script(self, params): and config.ENV_DATA.get("use_config_file") ): # upload config.ini file to external RHCS cluster - config_ini_path = self.upload_config_ini_file() + config_ini_path = self.upload_config_ini_file(params) cmd = f"{python_version} {script_path} --config-file {config_ini_path}" else: cmd = f"{python_version} {script_path} {params}" From 14cbad86c914540deaec9f4b03f504dadeddc6d9 Mon Sep 17 00:00:00 2001 From: Shivam Durgbuns Date: Thu, 24 Oct 2024 16:32:42 +0530 Subject: [PATCH 3/5] Adding the comments with feature ID and polarian ID Signed-off-by: Shivam Durgbuns --- ocs_ci/deployment/helpers/external_cluster_helpers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ocs_ci/deployment/helpers/external_cluster_helpers.py b/ocs_ci/deployment/helpers/external_cluster_helpers.py index 40add14e625..1389bb82c9b 100644 --- a/ocs_ci/deployment/helpers/external_cluster_helpers.py +++ b/ocs_ci/deployment/helpers/external_cluster_helpers.py @@ -344,6 +344,9 @@ def run_exporter_script(self, params): # run the exporter script on external RHCS cluster ocs_version = version.get_semantic_ocs_version_from_config() + # if condition is for the new feature introduced in + # 4.17 in OCSQE-2249 where the this covers the test case + # with polarian id OCS-6196 if ( "--upgrade" not in params and ocs_version >= version.VERSION_4_17 From 5cb4c1d946b49b364cdc5f61a0683885f663bb66 Mon Sep 17 00:00:00 2001 From: Shivam Durgbuns Date: Wed, 20 Nov 2024 15:18:06 +0530 Subject: [PATCH 4/5] typo fixes Signed-off-by: Shivam Durgbuns --- ocs_ci/deployment/helpers/external_cluster_helpers.py | 4 ++-- ocs_ci/utility/utils.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ocs_ci/deployment/helpers/external_cluster_helpers.py b/ocs_ci/deployment/helpers/external_cluster_helpers.py index 1389bb82c9b..29b63d2c37e 100644 --- a/ocs_ci/deployment/helpers/external_cluster_helpers.py +++ b/ocs_ci/deployment/helpers/external_cluster_helpers.py @@ -306,7 +306,7 @@ def upload_config_ini_file(self, params): params (str): Parameter to pass to exporter script Returns: - str: absolute path to config.ini gile + str: absolute path to config.ini file """ script_path = params_to_configini_file(params=params) @@ -345,7 +345,7 @@ def run_exporter_script(self, params): # run the exporter script on external RHCS cluster ocs_version = version.get_semantic_ocs_version_from_config() # if condition is for the new feature introduced in - # 4.17 in OCSQE-2249 where the this covers the test case + # 4.17 in OCSQE-2249 where this covers the test case # with polarian id OCS-6196 if ( "--upgrade" not in params diff --git a/ocs_ci/utility/utils.py b/ocs_ci/utility/utils.py index 48c2db7bd04..0ca3ee79ebb 100644 --- a/ocs_ci/utility/utils.py +++ b/ocs_ci/utility/utils.py @@ -5267,10 +5267,10 @@ def create_config_ini_file(params): params (str): Parameter to pass to be converted into config.ini file. Returns: - config_ini_file.name (str): Path to the config.ini file. + str: Path to the config.ini file. + """ data = "[Configurations]\n" - import re pattern = r"--([\w-]+) ([.:\w-]+)" matches = re.finditer(pattern, params, re.MULTILINE) @@ -5287,6 +5287,6 @@ def create_config_ini_file(params): ) with open(config_ini_file.name, "w") as fd: fd.write(data) - log.info(f"config.ini fike for cluster is located at {config_ini_file.name}") + log.info(f"config.ini file for cluster is located at {config_ini_file.name}") return config_ini_file.name From 38f896592c640f734915de3a791fb0c581600e2d Mon Sep 17 00:00:00 2001 From: Shivam Durgbuns Date: Thu, 9 Jan 2025 13:00:25 +0530 Subject: [PATCH 5/5] Changing function name to create_config_ini_file Signed-off-by: Shivam Durgbuns --- ocs_ci/deployment/helpers/external_cluster_helpers.py | 4 ++-- ocs_ci/utility/utils.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ocs_ci/deployment/helpers/external_cluster_helpers.py b/ocs_ci/deployment/helpers/external_cluster_helpers.py index 29b63d2c37e..234537a0df9 100644 --- a/ocs_ci/deployment/helpers/external_cluster_helpers.py +++ b/ocs_ci/deployment/helpers/external_cluster_helpers.py @@ -36,7 +36,7 @@ decode, download_file, wait_for_machineconfigpool_status, - params_to_configini_file, + create_config_ini_file, ) logger = logging.getLogger(__name__) @@ -309,7 +309,7 @@ def upload_config_ini_file(self, params): str: absolute path to config.ini file """ - script_path = params_to_configini_file(params=params) + script_path = create_config_ini_file(params=params) upload_file( self.host, script_path, script_path, self.user, self.password, self.ssh_key ) diff --git a/ocs_ci/utility/utils.py b/ocs_ci/utility/utils.py index 0ca3ee79ebb..888a2a56d7a 100644 --- a/ocs_ci/utility/utils.py +++ b/ocs_ci/utility/utils.py @@ -5257,6 +5257,8 @@ def is_z_stream_upgrade(): return config.UPGRADE.get("pre_upgrade_ocs_version", "") == config.UPGRADE.get( "upgrade_ocs_version", "" ) + + def create_config_ini_file(params): """ This function will create a config ini file for the params given.