Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding --config-file param functionality to deployment #10724

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name here is too generic doesn't tell anything about this use_confi_file.

As it's config file for exporter script to external RHCS cluster, more reasonable sounds something like:
rhcs_external_use_config_file

Also, please document this value in:
https://github.com/red-hat-storage/ocs-ci/blob/master/conf/README.md

34 changes: 33 additions & 1 deletion ocs_ci/deployment/helpers/external_cluster_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
decode,
download_file,
wait_for_machineconfigpool_status,
create_config_ini_file,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -296,6 +297,24 @@ 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, params):
"""
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 file

"""
script_path = create_config_ini_file(params=params)
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 @@ -324,7 +343,20 @@ 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 condition is for the new feature introduced in
# 4.17 in OCSQE-2249 where this covers the test case
# with polarian id OCS-6196
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(params)
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 @@ -5256,3 +5257,38 @@ 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.
shivamdurgbuns marked this conversation as resolved.
Show resolved Hide resolved
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:
str: Path to the config.ini file.

"""
data = "[Configurations]\n"

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 file for cluster is located at {config_ini_file.name}")

return config_ini_file.name
Loading