def __init__(self, rhel_worker_nodes): """ Initializes the required variables, create rhelpod, upload all the helper files to pod and install required packages. Args: rhel_worker_nodes (list): list of RHEL nodes e.g:['rhel1-0.vavuthu.qe.rh-ocs.com', 'rhel1-1.vavuthu.qe.rh-ocs.com', 'rhel1-2.vavuthu.qe.rh-ocs.com'] """ self.terraform_state_file = os.path.join( config.ENV_DATA["cluster_path"], "terraform_data", "terraform.tfstate" ) self.haproxy_playbook = os.path.join( constants.CLUSTER_LAUNCHER_VSPHERE_DIR, f"aos-{get_ocp_version('_')}", "ansible_haproxy_configure", "main.yml", ) self.rhel_worker_nodes = rhel_worker_nodes self.ssh_key_pem = config.DEPLOYMENT["ssh_key_private"] self.pod_ssh_key_pem = os.path.join( constants.POD_UPLOADPATH, self.ssh_key_pem.split("/")[-1] ) self.cluster_path = config.ENV_DATA["cluster_path"] self.kubeconfig = os.path.join( config.ENV_DATA["cluster_path"], config.RUN.get("kubeconfig_location") ) self.pod_name = "rhelpod" self.pull_secret_path = os.path.join(constants.TOP_DIR, "data", "pull-secret") self.pod_pull_secret_path = os.path.join( constants.POD_UPLOADPATH, "pull-secret" ) self.pod_kubeconfig_path = os.path.join( constants.POD_UPLOADPATH, config.RUN.get("kubeconfig_location").split("/")[-1], ) self.rhelpod = create_rhelpod(constants.DEFAULT_NAMESPACE, self.pod_name, 600) self.ocp_repo = get_ocp_repo() # Upload helper files to pod for OCP installation on RHEL self.upload_helpers(self.ocp_repo) # Install packages in pod self.rhelpod.install_packages(constants.RHEL_POD_PACKAGES) # upload ocp repo to rhel pod and this repo is used for rhel worker nodes upload(self.pod_name, get_ocp_repo(), constants.YUM_REPOS_PATH)
def __init__(self, rhel_worker_nodes): """ Initializes the required variables, create rhelpod, upload all the helper files to pod and install required packages. Args: rhel_worker_nodes (list): list of RHEL nodes e.g:['rhel1-0.vavuthu.qe.rh-ocs.com', 'rhel1-1.vavuthu.qe.rh-ocs.com', 'rhel1-2.vavuthu.qe.rh-ocs.com'] """ self.rhel_worker_nodes = rhel_worker_nodes self.ssh_key_pem = config.DEPLOYMENT['ssh_key_private'] self.pod_ssh_key_pem = os.path.join( constants.POD_UPLOADPATH, self.ssh_key_pem.split("/")[-1] ) self.ops_mirror_pem = os.path.join( f"{constants.DATA_DIR}", constants.OCP_PEM ) self.cluster_path = config.ENV_DATA['cluster_path'] self.kubeconfig = os.path.join( config.ENV_DATA['cluster_path'], config.RUN.get('kubeconfig_location') ) self.pod_name = "rhelpod" self.pull_secret_path = os.path.join( constants.TOP_DIR, "data", "pull-secret" ) self.pod_pull_secret_path = os.path.join( constants.POD_UPLOADPATH, "pull-secret" ) self.pod_kubeconfig_path = os.path.join( constants.POD_UPLOADPATH, config.RUN.get('kubeconfig_location').split("/")[-1] ) self.rhelpod = create_rhelpod( constants.DEFAULT_NAMESPACE, self.pod_name, 600 ) self.ocp_repo = get_ocp_repo() # Upload helper files to pod for OCP installation on RHEL self.upload_helpers(self.ocp_repo) # Install packages in pod self.rhelpod.install_packages(constants.RHEL_POD_PACKAGES)
def upload_helpers(self, ocp_repo): """ Upload helper files to pod for OCP installation on RHEL Helper Files:: - ssh_key pem - ocp repo - ocp pem - kubeconfig - pull secret - inventory yaml Args: ocp_repo (str): OCP repo to upload """ upload(self.pod_name, self.ssh_key_pem, constants.POD_UPLOADPATH) upload( self.pod_name, get_ocp_repo(config.ENV_DATA["rhel_version_for_ansible"]), constants.YUM_REPOS_PATH, ) # prepare and copy credential files for mirror.openshift.com with prepare_mirror_openshift_credential_files() as ( mirror_user_file, mirror_password_file, ): upload(self.pod_name, mirror_user_file, constants.YUM_VARS_PATH) upload(self.pod_name, mirror_password_file, constants.YUM_VARS_PATH) upload(self.pod_name, self.kubeconfig, constants.POD_UPLOADPATH) upload(self.pod_name, self.pull_secret_path, constants.POD_UPLOADPATH) if config.ENV_DATA["folder_structure"]: inventory_yaml_haproxy = self.create_inventory_for_haproxy() upload(self.pod_name, inventory_yaml_haproxy, constants.POD_UPLOADPATH) cmd = ( f"ansible-playbook -i {inventory_yaml_haproxy} " f"{self.haproxy_playbook} --private-key={self.ssh_key_pem} -v" ) run_cmd(cmd) self.inventory_yaml = self.create_inventory() upload(self.pod_name, self.inventory_yaml, constants.POD_UPLOADPATH)
def run_ansible_playbook(self): """ Bring up a helper pod (RHEL) to run openshift-ansible playbook """ rhel_pod_name = "rhel-ansible" # TODO: This method is creating only RHEL 7 pod. Once we would like to use # different version of RHEL for running openshift ansible playbook, we need # to update this method! rhel_pod_obj = create_rhelpod(constants.DEFAULT_NAMESPACE, rhel_pod_name) timeout = 4000 # For ansible-playbook # copy openshift-dev.pem to RHEL ansible pod pem_src_path = "~/.ssh/openshift-dev.pem" pem_dst_path = "/openshift-dev.pem" pod.upload(rhel_pod_obj.name, pem_src_path, pem_dst_path) repo_dst_path = constants.YUM_REPOS_PATH # Ansible playbook and dependency is described in the documentation to run # on RHEL7 node # https://docs.openshift.com/container-platform/4.9/machine_management/adding-rhel-compute.html repo_rhel_ansible = get_ocp_repo( rhel_major_version=config.ENV_DATA["rhel_version_for_ansible"]) repo = get_ocp_repo() diff_rhel = repo != repo_rhel_ansible pod.upload(rhel_pod_obj.name, repo_rhel_ansible, repo_dst_path) if diff_rhel: repo_dst_path = constants.POD_UPLOADPATH pod.upload(rhel_pod_obj.name, repo, repo_dst_path) repo_file = os.path.basename(repo) else: repo_file = os.path.basename(repo_rhel_ansible) # prepare credential files for mirror.openshift.com with prepare_mirror_openshift_credential_files() as ( mirror_user_file, mirror_password_file, ): pod.upload(rhel_pod_obj.name, mirror_user_file, constants.YUM_VARS_PATH) pod.upload(rhel_pod_obj.name, mirror_password_file, constants.YUM_VARS_PATH) # Install scp on pod rhel_pod_obj.install_packages("openssh-clients") # distribute repo file to all RHEL workers hosts = [ inst.private_dns_name for node, inst in self.rhel_worker_list.items() ] # Check whether every host is acceptin ssh connections for host in hosts: self.check_connection(rhel_pod_obj, host, pem_dst_path) for host in hosts: disable = "sudo yum-config-manager --disable *" rhel_pod_obj.exec_cmd_on_node(host, pem_dst_path, disable, user=self.rhel_worker_user) rhel_pod_obj.copy_to_server( host, pem_dst_path, os.path.join(repo_dst_path, repo_file), os.path.join("/tmp", repo_file), user=self.rhel_worker_user, ) rhel_pod_obj.exec_cmd_on_node( host, pem_dst_path, f"sudo mv {os.path.join(constants.RHEL_TMP_PATH, repo_file)} {constants.YUM_REPOS_PATH}", user=self.rhel_worker_user, ) for file_name in ( constants.MIRROR_OPENSHIFT_USER_FILE, constants.MIRROR_OPENSHIFT_PASSWORD_FILE, ): rhel_pod_obj.copy_to_server( host, pem_dst_path, os.path.join(constants.YUM_VARS_PATH, file_name), os.path.join(constants.RHEL_TMP_PATH, file_name), user=self.rhel_worker_user, ) rhel_pod_obj.exec_cmd_on_node( host, pem_dst_path, f"sudo mv " f"{os.path.join(constants.RHEL_TMP_PATH, file_name)} " f"{constants.YUM_VARS_PATH}", user=self.rhel_worker_user, ) # copy kubeconfig to pod kubeconfig = os.path.join(self.cluster_path, config.RUN.get("kubeconfig_location")) pod.upload(rhel_pod_obj.name, kubeconfig, "/") pull_secret_path = os.path.join(constants.TOP_DIR, "data", "pull-secret") pod.upload(rhel_pod_obj.name, pull_secret_path, "/tmp/") host_file = self.build_ansible_inventory(hosts) pod.upload(rhel_pod_obj.name, host_file, "/") # install pod packages rhel_pod_obj.install_packages(constants.RHEL_POD_PACKAGES) # run ansible openshift_ansible_path = "/usr/share/ansible/openshift-ansible" cmd = ( f"ansible-playbook -i /hosts --private-key={pem_dst_path} " f"{os.path.join(openshift_ansible_path, 'playbooks/scaleup.yml')}") rhel_pod_obj.exec_cmd_on_pod(cmd, out_yaml_format=False, timeout=timeout) self.verify_nodes_added(hosts) # remove rhcos workers self.remove_rhcos_workers()