def storage_migration(self): """ storage migration operation """ storage_migration_log = os.path.join(self.upgrade_log_path, "storage.migrate.log") print("\nRunning storage migration and logging to: {} on {}2\n".format(storage_migration_log, socket.gethostname())) storage_migration_cmd = ["/usr/local/bin/autokeys_loader", "ossh", "-l", "root", self.cluster.primary_master, "-c", "oc adm migrate storage --include='*' --confirm --loglevel=8"] with SshAgent() as agent: agent.add_autokey(AUTOKEYS_PATH, AUTOKEYS_PREFIX) # Run the command proc = CICDControl.run_cmd(storage_migration_cmd, storage_migration_log) if proc[0] == 0: os.unlink(storage_migration_log) print("\nStorage migration ran successfully; removed {}\n".format(storage_migration_log)) else: print("\nStorage migration failed...") print("Printing last 100 lines of the log for convenience.") print("To see the full log, view '{}' on bastion2.\n\n".format(storage_migration_log)) with open(storage_migration_log, 'r') as log_file: log_file_contents = log_file.readlines() for line in log_file_contents[-min(len(log_file_contents), 100):]: print(line)
def pre_check(self): """ Run a pre-upgrade check """ self.cleanup_log_dir() # get the latest openshift-ansible rpms openshift_ansible_dir = self.get_latest_openshift_ansible() # Find the version of openshift-ansible osa_rpm_versions = subprocess.check_output(['rpm', '-qp', '--queryformat', '%{VERSION}-%{RELEASE}\n', openshift_ansible_dir + '/rpms/*rpm']) osa_rpm_version = list(set(osa_rpm_versions.strip().split('\n')))[0] # Find the Openshift Version on the node with SshAgent() as agent: agent.add_autokey(AUTOKEYS_PATH, AUTOKEYS_PREFIX) _ = self.cluster.run_cmd_on_master("/usr/bin/yum clean all") _ = self.cluster.run_cmd_on_master("/usr/sbin/atomic-openshift-excluder unexclude") os_rpm_version = self.cluster.run_cmd_on_master("/usr/bin/repoquery --quiet --pkgnarrow=repos " "--queryformat='%{version}-%{release}' " "atomic-openshift") _ = self.cluster.run_cmd_on_master("/usr/sbin/atomic-openshift-excluder exclude") disk_usage = subprocess.check_output(["/usr/bin/opssh", "-c", self.cluster.name, "-t", "master", "-i", "/usr/bin/df -h / /var /var/lib/etcd | /usr/bin/uniq"]) print("\nOpenshift Ansible RPM Version: {}".format(osa_rpm_version)) print("Openshift RPM Version: {}\n".format(os_rpm_version)) print("Filesystem usage for '/' and 'var':") print("================================================================") print(disk_usage)
def smoketest(self): """ do a smoketest on a cluster """ smoketest_script = os.path.join(self.bin_dir, 'aos-cd-cluster-smoke-test.sh') with SshAgent() as agent: agent.add_autokey(AUTOKEYS_PATH, AUTOKEYS_PREFIX) proc = CICDControl.run_cmd([smoketest_script, self.cluster.name]) print(proc[1])
def status(self): """ do a cluster status """ status_script = os.path.join(self.bin_dir, 'aos-cd-cluster-status.sh') with SshAgent() as agent: agent.add_autokey(AUTOKEYS_PATH, AUTOKEYS_PREFIX) proc = CICDControl.run_cmd([status_script, self.cluster.name]) print(proc[1])
def build_ci_msg(self): """ Streams the python script to the cluster master. Script outputs a json document. """ ci_msg_cmd = ['ossh', '-l', 'root', self.cluster.primary_master, '-c', "/usr/bin/python - {}".format(self.cluster.name)] build_ci_input = open(os.path.join(self.bin_dir, 'build-ci-msg.py')) with SshAgent() as agent: agent.add_autokey(AUTOKEYS_PATH, AUTOKEYS_PREFIX) proc = CICDControl.run_cmd(ci_msg_cmd, None, build_ci_input) for line in proc[1].split('\n'): if '=' in line: print(line)
def cluster_operation(self): """ Call the cicd-operations.py script """ self.update_ops_git_repos() openshift_ansible_operations = ['install', 'upgrade', 'upgrade_control_plane', 'upgrade_nodes', 'upgrade_metrics', 'upgrade_logging', 'upgrade_nodes_aws_scalegroups'] print(self.operation) if self.operation in openshift_ansible_operations: self.get_latest_openshift_ansible() # call the cicd operations #pylint: disable=relative-import # Moving this import here. The hope is is that this will be updated via git before it's imported from ops_bin.cicd_operations import ClusterOperation operation = ClusterOperation(self.cluster.name, self.operation, self.extra_args) with SshAgent() as agent: agent.add_autokey(AUTOKEYS_PATH, AUTOKEYS_PREFIX) operation.main()