Пример #1
0
    def test_download(self):
        """Testing SSH download() method"""
        print "Running: %s - %s" % (self.id(), self.shortDescription())

        remote_file = '/etc/hosts'
        local_file = '/tmp/download_test_file'

        # remove local test file (ignore error if not exist)
        g.run_local('rm -f %s' % local_file)

        # md5sum remote file
        command = 'md5sum %s| awk \'{print $1}\'' % remote_file
        rcode, rout, _ = g.run(self.primary_host, command)
        if rcode == 0:
            md5sum_up = rout.strip()

        # download it
        g.download(self.primary_host, '/etc/hosts', '/tmp/download_test_file')

        # md5sum local copy
        command = 'md5sum %s | awk \'{print $1}\'' % local_file
        rcode, rout, _ = g.run_local(command)
        if rcode == 0:
            md5sum_down = rout.strip()

        # compare the md5sums
        self.assertEqual(md5sum_down, md5sum_up, 'md5sums do not match')
Пример #2
0
    def test_download(self):
        """Testing SSH download() method"""
        print "Running: %s - %s" % (self.id(), self.shortDescription())

        remote_file = '/etc/hosts'
        local_file = '/tmp/download_test_file'

        # remove local test file (ignore error if not exist)
        g.run_local('rm -f %s' % local_file)

        # md5sum remote file
        command = 'md5sum %s| awk \'{print $1}\'' % remote_file
        rcode,  rout, _ = g.run(self.primary_host, command)
        if rcode == 0:
            md5sum_up = rout.strip()

        # download it
        g.download(self.primary_host,
                   '/etc/hosts', '/tmp/download_test_file')

        # md5sum local copy
        command = 'md5sum %s | awk \'{print $1}\'' % local_file
        rcode, rout, _ = g.run_local(command)
        if rcode == 0:
            md5sum_down = rout.strip()

        # compare the md5sums
        self.assertEqual(md5sum_down, md5sum_up, 'md5sums do not match')
def enable_pvc_resize(master_node):
    '''
     This function edits the /etc/origin/master/master-config.yaml
     file - to enable pv_resize feature
     and restarts atomic-openshift service on master node
     Args:
         master_node (str): hostname of masternode  on which
                           want to edit the
                           master-config.yaml file
     Returns:
         bool: True if successful,
               otherwise raise Exception
    '''
    version = get_openshift_version()
    if version < "3.9":
        msg = ("pv resize is not available in openshift "
               "version %s " % version)
        g.log.error(msg)
        raise NotSupportedException(msg)

    with tempfile.NamedTemporaryFile(delete=False) as temp:
        temp_filename = temp.name

    try:
        g.download(master_node, MASTER_CONFIG_FILEPATH, temp_filename)
    except Exception as e:
        err_msg = (
            "Failed to download '{}' from master node '{}' due to"
            "exception\n{}".format(
                MASTER_CONFIG_FILEPATH, master_node, six.text_type(e)))
        raise ExecutionError(err_msg)

    with open(temp_filename, 'r') as f:
        data = yaml.load(f, Loader=yaml.FullLoader)
        dict_add = data['admissionConfig']['pluginConfig']
        if "PersistentVolumeClaimResize" in dict_add:
            g.log.info("master-config.yaml file is already edited")
            return True
        dict_add['PersistentVolumeClaimResize'] = {
            'configuration': {
                'apiVersion': 'v1',
                'disable': 'false',
                'kind': 'DefaultAdmissionConfig'}}
        data['admissionConfig']['pluginConfig'] = dict_add
        kube_config = data['kubernetesMasterConfig']
        for key in ('apiServerArguments', 'controllerArguments'):
            kube_config[key] = (
                kube_config.get(key)
                if isinstance(kube_config.get(key), dict) else {})
            value = ['ExpandPersistentVolumes=true']
            kube_config[key]['feature-gates'] = value

    with open(temp_filename, 'w+') as f:
        yaml.dump(data, f, default_flow_style=False)

    try:
        g.upload(master_node, temp_filename, MASTER_CONFIG_FILEPATH)
    except Exception as e:
        err_msg = (
            "Failed to upload '{}' to master node '{}' due to"
            "exception\n{}".format(
                master_node, MASTER_CONFIG_FILEPATH, six.text_type(e)))
        raise ExecutionError(err_msg)
    os.unlink(temp_filename)

    if version == "3.9":
        cmd = ("systemctl restart atomic-openshift-master-api "
               "atomic-openshift-master-controllers")
    else:
        cmd = ("/usr/local/bin/master-restart api && "
               "/usr/local/bin/master-restart controllers")
    ret, out, err = g.run(master_node, cmd, "root")
    if ret != 0:
        err_msg = "Failed to execute cmd %s on %s\nout: %s\nerr: %s" % (
            cmd, master_node, out, err)
        g.log.error(err_msg)
        raise ExecutionError(err_msg)

    # Wait for API service to be ready after the restart
    for w in waiter.Waiter(timeout=120, interval=1):
        try:
            cmd_run("oc get nodes", master_node)
            return True
        except AssertionError:
            continue
    err_msg = "Exceeded 120s timeout waiting for OCP API to start responding."
    g.log.error(err_msg)
    raise ExecutionError(err_msg)
Пример #4
0
def main():
    if len(sys.argv) == 2:
        yaml_file = sys.argv[1]
    else:
        print("Kindly provide yaml file")
        sys.exit(0)

    config_dict = parser(yaml_file)
    servers = config_dict.get('servers')
    qe_repo = config_dict.get('repo')
    qe_host, qe_host_path = qe_repo[0].split(':')

    # Local path for sos-report
    dir_path = os.path.dirname(os.path.realpath(__file__)) + '/sosreport'
    try:
        os.stat(dir_path)
    except:
        os.mkdir(dir_path)

    # Create dir in qe repo
    # Using sshpass as the default repo has blocked passwordless login
    try:
        p = getpass.getpass(prompt="Enter password for host %s \n" % qe_host)
    except Exception as error:
        print('ERROR', error)

    command = 'sshpass -p %s ssh qe@%s "mkdir -p %s"' % (p, qe_host,
                                                         qe_host_path)
    ret, _, err = g.run_local(command)

    print("Starting to generate sos-report")
    for server in servers:
        # generate sos-report
        ret, output, err = g.run(server, "echo -ne '\n\n' | sosreport")
        assert (ret == 0), "Failed to generate sosreport for %s" % server
        remote_file_path = re.findall(r'/var/tmp/sosreport[^\s]+', output)[0]
        sosreport = remote_file_path.split('/tmp/')[1]
        remote_file_checksum = re.search(r'The checksum is: (\S+)',
                                         output).group(1)

        # Download sos-report to local system
        g.download(server, remote_file_path, dir_path)
        local_file_path = dir_path + '/' + sosreport

        # Upload sos-report to repo
        # Using sshpass as the default repo has blocked passwordless login
        command = 'sshpass -p %s scp -r %s qe@%s' % (p, local_file_path,
                                                     qe_repo[0])
        ret, _, err = g.run_local(command)
        # Getting md5sum of the report from remote repo
        command = ('sshpass -p %s ssh qe@%s "md5sum %s/%s"' %
                   (p, qe_host, qe_host_path, sosreport))
        ret, output, err = g.run_local(command)
        md5sum = output.split(" ")[0]

        # Match the md5sum with that of original
        if remote_file_checksum == md5sum:
            print("Sos-report %s copied successfully and checksum matches" %
                  sosreport)
        else:
            print("checksum match failed for %s" % sosreport)
            exit()


# Change permissions of qe repo

    command = ('sshpass -p %s ssh qe@%s "chmod -R 755 %s"' %
               (p, qe_host, qe_host_path))
    ret, output, err = g.run_local(command)
    assert (ret == 0), "Failed to change permission for %s" % qe_host_path
    print("Successfully changed permissions for  %s:%s" %
          (qe_host, qe_host_path))