Skip to content

Commit

Permalink
adding --config-file param functionality to deployment
Browse files Browse the repository at this point in the history
Signed-off-by: Shivam Durgbuns <[email protected]>
  • Loading branch information
shivamdurgbuns committed Oct 24, 2024
1 parent 4bbd162 commit fea5ff5
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
3 changes: 3 additions & 0 deletions conf/ocsci/external_cluster_with_config_file.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
ENV_DATA:
use_config_file: true
28 changes: 27 additions & 1 deletion ocs_ci/deployment/helpers/external_cluster_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
decode,
download_file,
wait_for_machineconfigpool_status,
params_to_configini_file,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -282,6 +283,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
Expand Down Expand Up @@ -310,7 +326,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(
Expand Down
36 changes: 36 additions & 0 deletions ocs_ci/utility/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import pexpect
import pytest
import unicodedata
import tempfile

import hcl2
import requests
Expand Down Expand Up @@ -5197,3 +5198,38 @@ def extract_image_urls(string_data):
# Find all URLs that start with 'registry.redhat.io'
image_urls = re.findall(r'registry\.redhat\.io[^\s"]+', string_data)
return image_urls


def params_to_configini_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

0 comments on commit fea5ff5

Please sign in to comment.