Skip to content

Commit

Permalink
Merge pull request #9491 from vavuthu/remove_logic_from_constants
Browse files Browse the repository at this point in the history
remove dynamic logic from constants
  • Loading branch information
vavuthu authored Mar 20, 2024
2 parents 77528db + cbd8c48 commit 6784842
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 44 deletions.
66 changes: 48 additions & 18 deletions ocs_ci/deployment/helpers/vsphere_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@ def __init__(self):
)
self.folder_structure = config.ENV_DATA.get("folder_structure")
self.ocp_version = get_ocp_version(seperator="_")
self.SCALEUP_VSPHERE_DIR = os.path.join(
constants.EXTERNAL_DIR,
f"v4-scaleup/ocp4-rhel-scaleup/aos-{self.ocp_version}/vsphere",
)
self.SCALEUP_VSPHERE_MAIN = os.path.join(self.SCALEUP_VSPHERE_DIR, "main.tf")
self.SCALEUP_VSPHERE_VARIABLES = os.path.join(
self.SCALEUP_VSPHERE_DIR, "variables.tf"
)
self.SCALEUP_VSPHERE_ROUTE53 = os.path.join(
self.SCALEUP_VSPHERE_DIR, "route53/vsphere-rhel-dns.tf"
)
self.SCALEUP_VSPHERE_ROUTE53_VARIABLES = os.path.join(
self.SCALEUP_VSPHERE_DIR, "route53/variables.tf"
)
self.SCALEUP_VSPHERE_MACHINE_CONF = os.path.join(
self.SCALEUP_VSPHERE_DIR, "machines/vsphere-rhel-machine.tf"
)
self._templating = Templating()

def generate_terraform_vars_for_scaleup(self, rhcos_ips):
Expand Down Expand Up @@ -161,7 +178,7 @@ def modify_scaleup_repo(self):
cred_file_var_to_modify = "shared_credentials_file"
target_cred_file_var = "shared_credentials_files"
replace_content_in_file(
constants.SCALEUP_VSPHERE_ROUTE53,
self.SCALEUP_VSPHERE_ROUTE53,
cred_file_var_to_modify,
target_cred_file_var,
)
Expand All @@ -172,62 +189,58 @@ def modify_scaleup_repo(self):
)

replace_content_in_file(
constants.SCALEUP_VSPHERE_ROUTE53,
self.SCALEUP_VSPHERE_ROUTE53,
str_to_modify,
target_str,
)

replace_content_in_file(
constants.SCALEUP_VSPHERE_ROUTE53,
self.SCALEUP_VSPHERE_ROUTE53,
str_to_modify,
f'["{os.path.expanduser(config.DEPLOYMENT["aws_cred_path"])}"]',
)

replace_content_in_file(
constants.SCALEUP_VSPHERE_ROUTE53,
self.SCALEUP_VSPHERE_ROUTE53,
"us-east-1",
f"{config.ENV_DATA.get('region')}",
)

else:
# remove access and secret key from constants.SCALEUP_VSPHERE_MAIN
# remove access and secret key from SCALEUP_VSPHERE_MAIN
access_key = 'access_key = "${var.aws_access_key}"'
secret_key = 'secret_key = "${var.aws_secret_key}"'
replace_content_in_file(
constants.SCALEUP_VSPHERE_MAIN, f"{access_key}", " "
)
replace_content_in_file(
constants.SCALEUP_VSPHERE_MAIN, f"{secret_key}", " "
)
replace_content_in_file(self.SCALEUP_VSPHERE_MAIN, f"{access_key}", " ")
replace_content_in_file(self.SCALEUP_VSPHERE_MAIN, f"{secret_key}", " ")

# remove access and secret key from constants.SCALEUP_VSPHERE_ROUTE53
# remove access and secret key from SCALEUP_VSPHERE_ROUTE53
route53_access_key = 'access_key = "${var.access_key}"'
route53_secret_key = 'secret_key = "${var.secret_key}"'
replace_content_in_file(
constants.SCALEUP_VSPHERE_ROUTE53, f"{route53_access_key}", " "
self.SCALEUP_VSPHERE_ROUTE53, f"{route53_access_key}", " "
)
replace_content_in_file(
constants.SCALEUP_VSPHERE_ROUTE53, f"{route53_secret_key}", " "
self.SCALEUP_VSPHERE_ROUTE53, f"{route53_secret_key}", " "
)

replace_content_in_file(
constants.SCALEUP_VSPHERE_ROUTE53,
self.SCALEUP_VSPHERE_ROUTE53,
"us-east-1",
f"{config.ENV_DATA.get('region')}",
)

# remove access and secret variables from scale-up repo
remove_keys_from_tf_variable_file(
constants.SCALEUP_VSPHERE_VARIABLES,
self.SCALEUP_VSPHERE_VARIABLES,
["aws_access_key", "aws_secret_key"],
)
remove_keys_from_tf_variable_file(
constants.SCALEUP_VSPHERE_ROUTE53_VARIABLES,
self.SCALEUP_VSPHERE_ROUTE53_VARIABLES,
["access_key", "secret_key"],
)

# change root disk size
change_vm_root_disk_size(constants.SCALEUP_VSPHERE_MACHINE_CONF)
change_vm_root_disk_size(self.SCALEUP_VSPHERE_MACHINE_CONF)

def generate_cluster_info(self):
"""
Expand Down Expand Up @@ -336,3 +349,20 @@ def generate_config_yaml(self):
f.write(scale_up_config_str)

logger.debug(f"scaleup config yaml file : {scale_config_var_yaml}")

def get_host_file_for_time_sync(self):
"""
Fetches the host file for time sync
Returns:
str: host file
"""
sync_time_with_host_file = self.SCALEUP_VSPHERE_MACHINE_CONF
if config.ENV_DATA["folder_structure"]:
sync_time_with_host_file = os.path.join(
constants.CLUSTER_LAUNCHER_VSPHERE_DIR,
f"aos-{self.ocp_version}",
constants.CLUSTER_LAUNCHER_MACHINE_CONF,
)
return sync_time_with_host_file
18 changes: 9 additions & 9 deletions ocs_ci/deployment/vmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,7 @@ def add_nodes(self):
config.ENV_DATA["vsphere_resource_pool"] = config.ENV_DATA.get("cluster_name")

# sync guest time with host
sync_time_with_host_file = constants.SCALEUP_VSPHERE_MACHINE_CONF
if config.ENV_DATA["folder_structure"]:
sync_time_with_host_file = os.path.join(
constants.CLUSTER_LAUNCHER_VSPHERE_DIR,
f"aos-{get_ocp_version(seperator='_')}",
constants.CLUSTER_LAUNCHER_MACHINE_CONF,
)
sync_time_with_host_file = helpers.get_host_file_for_time_sync()
if config.ENV_DATA.get("sync_time_with_host"):
sync_time_with_host(sync_time_with_host_file, True)

Expand All @@ -213,7 +207,10 @@ def add_nodes(self):
# choose the vsphere_dir based on OCP version
# generate cluster_info and config yaml files
# for OCP version greater than 4.4
vsphere_dir = constants.SCALEUP_VSPHERE_DIR
vsphere_dir = os.path.join(
constants.EXTERNAL_DIR,
f"v4-scaleup/ocp4-rhel-scaleup/aos-{get_ocp_version(seperator='_')}/vsphere",
)
rhel_module = "rhel-worker"
if Version.coerce(self.ocp_version) >= Version.coerce("4.5"):
vsphere_dir = os.path.join(
Expand Down Expand Up @@ -1424,7 +1421,10 @@ def destroy_scaleup_nodes(
helpers = VSPHEREHELPERS()
helpers.modify_scaleup_repo()

vsphere_dir = constants.SCALEUP_VSPHERE_DIR
vsphere_dir = os.path.join(
constants.EXTERNAL_DIR,
f"v4-scaleup/ocp4-rhel-scaleup/aos-{get_ocp_version(seperator='_')}/vsphere",
)
if Version.coerce(self.ocp_version) >= Version.coerce("4.5"):
vsphere_dir = os.path.join(
constants.CLUSTER_LAUNCHER_VSPHERE_DIR,
Expand Down
17 changes: 0 additions & 17 deletions ocs_ci/ocs/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,8 +1137,6 @@
MIN_STORAGE_FOR_DATASTORE = 1.1 * 1024**4

# vSphere related constants
# importing here due to circular dependency
from ocs_ci.utility.utils import get_ocp_version

VSPHERE_NODE_USER = "core"
VSPHERE_INSTALLER_BRANCH = "release-4.3"
Expand All @@ -1160,21 +1158,6 @@
TERRAFORM_DATA_DIR = "terraform_data"
TERRAFORM_PLUGINS_DIR = ".terraform"
SCALEUP_TERRAFORM_DATA_DIR = "scaleup_terraform_data"
SCALEUP_VSPHERE_DIR = os.path.join(
EXTERNAL_DIR,
f"v4-scaleup/ocp4-rhel-scaleup/aos-{get_ocp_version(seperator='_')}/vsphere",
)
SCALEUP_VSPHERE_MAIN = os.path.join(SCALEUP_VSPHERE_DIR, "main.tf")
SCALEUP_VSPHERE_VARIABLES = os.path.join(SCALEUP_VSPHERE_DIR, "variables.tf")
SCALEUP_VSPHERE_ROUTE53 = os.path.join(
SCALEUP_VSPHERE_DIR, "route53/vsphere-rhel-dns.tf"
)
SCALEUP_VSPHERE_ROUTE53_VARIABLES = os.path.join(
SCALEUP_VSPHERE_DIR, "route53/variables.tf"
)
SCALEUP_VSPHERE_MACHINE_CONF = os.path.join(
SCALEUP_VSPHERE_DIR, "machines/vsphere-rhel-machine.tf"
)
RUST_URL = "https://sh.rustup.rs"
COREOS_INSTALLER_REPO = "https://github.com/coreos/coreos-installer.git"

Expand Down

0 comments on commit 6784842

Please sign in to comment.