def deploy_prereq(self): """ Pre-Requisites for vSphere UPI Deployment """ super(VSPHEREUPI.OCPDeployment, self).deploy_prereq() # generate manifests self.generate_manifests() # create chrony resource add_chrony_to_ocp_deployment() # create ignitions self.create_ignitions() self.kubeconfig = os.path.join( self.cluster_path, config.RUN.get("kubeconfig_location")) self.terraform_var = os.path.join( config.ENV_DATA["cluster_path"], constants.TERRAFORM_DATA_DIR, "terraform.tfvars", ) # git clone repo from openshift installer clone_openshift_installer() # generate terraform variable file generate_terraform_vars_and_update_machine_conf() # sync guest time with host vm_file = (constants.VM_MAIN if self.folder_structure else constants.INSTALLER_MACHINE_CONF) if config.ENV_DATA.get("sync_time_with_host"): sync_time_with_host(vm_file, True)
def deploy_prereq(self): """ Pre-Requisites for Bare Metal UPI Deployment """ super(BAREMETALUPI.OCPDeployment, self).deploy_prereq() # check for BM status logger.info("Checking BM Status") status = self.check_bm_status_exist() assert status == constants.BM_STATUS_ABSENT, "BM Cluster still present" # update BM status logger.info("Updating BM Status") result = self.update_bm_status(constants.BM_STATUS_PRESENT) assert (result == constants.BM_STATUS_RESPONSE_UPDATED ), "Failed to update request" # create manifest self.create_manifest() # create chrony resource add_chrony_to_ocp_deployment() # create ignitions self.create_ignitions() self.kubeconfig = os.path.join( self.cluster_path, config.RUN.get("kubeconfig_location")) bootstrap_path = os.path.join(config.ENV_DATA.get("cluster_path"), constants.BOOTSTRAP_IGN) master_path = os.path.join(config.ENV_DATA.get("cluster_path"), constants.MASTER_IGN) worker_path = os.path.join(config.ENV_DATA.get("cluster_path"), constants.WORKER_IGN) self.host = self.helper_node_details["bm_httpd_server"] self.user = self.helper_node_details["bm_httpd_server_user"] self.private_key = os.path.expanduser( config.DEPLOYMENT["ssh_key_private"]) self.helper_node_handler = Connection(self.host, self.user, self.private_key) cmd = f"rm -rf {self.helper_node_details['bm_path_to_upload']}" logger.info(self.helper_node_handler.exec_cmd(cmd=cmd)) cmd = f"mkdir -m 755 {self.helper_node_details['bm_path_to_upload']}" assert self.helper_node_handler.exec_cmd( cmd=cmd), "Failed to create required folder" # Upload ignition to public access server upload_dict = { bootstrap_path: constants.BOOTSTRAP_IGN, master_path: constants.MASTER_IGN, worker_path: constants.WORKER_IGN, } for key, val in zip(upload_dict.keys(), upload_dict.values()): upload_file( self.host, key, os.path.join(self.helper_node_details["bm_path_to_upload"], f"{val}"), self.user, key_file=self.private_key, ) # Perform Cleanup for stale entry's cmd = f"rm -rf {self.helper_node_details['bm_tftp_base_dir']}" assert self.helper_node_handler.exec_cmd( cmd=cmd), "Failed to Delete folder" # Installing Required packages cmd = "yum install dnsmasq -y" assert self.helper_node_handler.exec_cmd( cmd=cmd), "Failed to install required package" # Enable dnsmasq service on boot cmd = "systemctl enable dnsmasq" assert self.helper_node_handler.exec_cmd( cmd=cmd), "Failed to Enable dnsmasq service" # Starting dnsmasq service cmd = "systemctl start dnsmasq" assert self.helper_node_handler.exec_cmd( cmd=cmd), "Failed to Start dnsmasq service" cmd = f"mkdir -m 755 -p {self.helper_node_details['bm_tftp_base_dir']}" assert self.helper_node_handler.exec_cmd( cmd=cmd), "Failed to create required folder" cmd = ( f"mkdir -m 755 -p {self.helper_node_details['bm_tftp_base_dir']}ocs4qe" ) assert self.helper_node_handler.exec_cmd( cmd=cmd), "Failed to create required folder" cmd = f"mkdir -m 755 -p {self.helper_node_details['bm_tftp_base_dir']}ocs4qe/baremetal" assert self.helper_node_handler.exec_cmd( cmd=cmd), "Failed to create required folder" cmd = f"rm -rf {self.helper_node_details['bm_dnsmasq_dir']}*" assert self.helper_node_handler.exec_cmd( cmd=cmd), "Failed to Delete dir" # Install syslinux cmd = "yum install syslinux -y" assert self.helper_node_handler.exec_cmd( cmd=cmd), "Failed to install required package" # Copy syslinux files to the tftp path cmd = f"cp -ar /usr/share/syslinux/* {self.helper_node_details['bm_tftp_dir']}" assert self.helper_node_handler.exec_cmd( cmd=cmd), "Failed to Copy required files" upload_dict = { constants.PXE_CONF_FILE: "dnsmasq.pxe.conf", constants.COMMON_CONF_FILE: "dnsmasq.common.conf", } for key, val in zip(upload_dict.keys(), upload_dict.values()): upload_file( self.host, key, os.path.join(self.helper_node_details["bm_dnsmasq_dir"], val), self.user, key_file=self.private_key, ) # Restarting dnsmasq service cmd = "systemctl restart dnsmasq" assert self.helper_node_handler.exec_cmd( cmd=cmd), "Failed to restart dnsmasq service" with open(constants.RHCOS_IMAGES_FILE) as file_stream: rhcos_images_file = yaml.safe_load(file_stream) ocp_version = get_ocp_version() float_ocp_version = float(ocp_version) logger.info(rhcos_images_file) image_data = rhcos_images_file[ocp_version] # Download installer_initramfs initramfs_image_path = (constants.coreos_url_prefix + image_data["installer_initramfs_url"]) if check_for_rhcos_images(initramfs_image_path): cmd = ("wget -O " f"{self.helper_node_details['bm_tftp_dir']}" "/rhcos-installer-initramfs.x86_64.img " f"{initramfs_image_path}") assert self.helper_node_handler.exec_cmd( cmd=cmd), "Failed to Download required File" else: raise RhcosImageNotFound # Download installer_kernel kernel_image_path = (constants.coreos_url_prefix + image_data["installer_kernel_url"]) if check_for_rhcos_images(kernel_image_path): cmd = ("wget -O " f"{self.helper_node_details['bm_tftp_dir']}" "/rhcos-installer-kernel-x86_64 " f"{kernel_image_path}") assert self.helper_node_handler.exec_cmd( cmd=cmd), "Failed to Download required File" else: raise RhcosImageNotFound # Download metal_bios if float_ocp_version <= 4.6: metal_image_path = (constants.coreos_url_prefix + image_data["metal_bios_url"]) if check_for_rhcos_images(metal_image_path): cmd = ("wget -O " f"{self.helper_node_details['bm_path_to_upload']}" f"/{constants.BM_METAL_IMAGE} " f"{metal_image_path}") assert self.helper_node_handler.exec_cmd( cmd=cmd), "Failed to Download required File" else: raise RhcosImageNotFound if float_ocp_version >= 4.6: # Download metal_bios rootfs_image_path = (constants.coreos_url_prefix + image_data["live_rootfs_url"]) if check_for_rhcos_images(rootfs_image_path): cmd = ("wget -O " f"{self.helper_node_details['bm_path_to_upload']}" "/rhcos-live-rootfs.x86_64.img " f"{rootfs_image_path}") assert self.helper_node_handler.exec_cmd( cmd=cmd), "Failed to Download required File" else: raise RhcosImageNotFound # Create pxelinux.cfg directory cmd = f"mkdir -m 755 {self.helper_node_details['bm_tftp_dir']}/pxelinux.cfg" assert self.helper_node_handler.exec_cmd( cmd=cmd), "Failed to create required folder"