diff --git a/ocs_ci/deployment/helpers/vsphere_helpers.py b/ocs_ci/deployment/helpers/vsphere_helpers.py index 7c385ed59ab..c0750e304bd 100644 --- a/ocs_ci/deployment/helpers/vsphere_helpers.py +++ b/ocs_ci/deployment/helpers/vsphere_helpers.py @@ -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): @@ -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, ) @@ -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): """ @@ -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 diff --git a/ocs_ci/deployment/vmware.py b/ocs_ci/deployment/vmware.py index c08d65adcff..e6e4f98b7cf 100644 --- a/ocs_ci/deployment/vmware.py +++ b/ocs_ci/deployment/vmware.py @@ -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) @@ -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( @@ -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, diff --git a/ocs_ci/ocs/constants.py b/ocs_ci/ocs/constants.py index 713fefaaa18..ebee81e0402 100644 --- a/ocs_ci/ocs/constants.py +++ b/ocs_ci/ocs/constants.py @@ -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" @@ -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"