示例#1
0
文件: qcow.py 项目: j5boot/isard
def verify_output_cmds2(cmds_done, path_domain_disk, path_template_disk,
                        id_domain):
    error = None
    d = [a for a in cmds_done
         if a['title'] == 'test_if_disk_template_exists'][0]
    if len(d['err']) > 0:
        log.error(
            'template disk {} doesn\'t exist??. Something was wrong. Error: {}'
            .format(path_template_disk, d['err']))
        log.debug('cmd: {}, out: {}, err: {}'.format(d['cmd'], d['out'],
                                                     d['err']))
        new_template_disk_created = False

        error = 'Hard'
    else:
        new_template_disk_created = True
        file_size_template_disk = int(d['out'])

    d = [a for a in cmds_done if a['title'] == 'test_if_disk_domain_exists'][0]
    if len(d['err']) > 0:
        # domain disk has dissapeared
        if (new_template_disk_created == True):
            log.debug('Domain disk {} has been moved to {}. Ok.'.format(
                path_domain_disk, path_template_disk))
        else:
            log.error(
                'Where is Domain disk {}? The disk would have moved to {} but it is nowhere!!'
                .format(path_domain_disk, path_template_disk))
            error = 'Crashed'
    else:
        # domain disk remain in place
        file_size_domain_disk = int(d['out'])
        if (new_template_disk_created == True):
            log.error(
                'Domain disk {} would have to be moved, but it is in place. Template disk {} have beeen created, but with all the data??'
                .format(path_domain_disk, path_template_disk))
            log.error('Domain disk {} Size: {} ({})'.format(
                path_domain_disk, file_size_domain_disk,
                size_format(file_size_domain_disk)))
            log.error('Template disk {} Size: {} ({})'.format(
                path_template_disk, file_size_template_disk,
                size_format(file_size_template_disk)))
            error = 'Crashed'
        else:
            log.error(
                'Domain disk {} would have to be moved, but it is in place. Template disk {} not created, but domain disk with all the data??'
                .format(path_domain_disk, path_template_disk))
            log.error('Domain disk {} Size: {} ({})'.format(
                path_domain_disk, file_size_domain_disk,
                size_format(file_size_domain_disk)))
            error = 'Hard'

    return error
示例#2
0
文件: qcow.py 项目: isard-vdi/isard
def verify_output_cmds2(cmds_done, path_domain_disk, path_template_disk, id_domain):
    error = None
    d = [a for a in cmds_done if a['title'] == 'test_if_disk_template_exists'][0]
    if len(d['err']) > 0:
        log.error(
            'template disk {} doesn\'t exist??. Something was wrong. Error: {}'.format(path_template_disk, d['err']))
        log.debug('cmd: {}, out: {}, err: {}'.format(d['cmd'], d['out'], d['err']))
        new_template_disk_created = False

        error = 'Hard'
    else:
        new_template_disk_created = True
        file_size_template_disk = int(d['out'])

    d = [a for a in cmds_done if a['title'] == 'test_if_disk_domain_exists'][0]
    if len(d['err']) > 0:
        # domain disk has dissapeared
        if (new_template_disk_created == True):
            log.debug('Domain disk {} has been moved to {}. Ok.'.format(path_domain_disk, path_template_disk))
        else:
            log.error(
                'Where is Domain disk {}? The disk would have moved to {} but it is nowhere!!'.format(path_domain_disk,
                                                                                                      path_template_disk))
            error = 'Crashed'
    else:
        # domain disk remain in place
        file_size_domain_disk = int(d['out'])
        if (new_template_disk_created == True):
            log.error(
                'Domain disk {} would have to be moved, but it is in place. Template disk {} have beeen created, but with all the data??'.format(
                    path_domain_disk, path_template_disk))
            log.error('Domain disk {} Size: {} ({})'.format(path_domain_disk, file_size_domain_disk,
                                                            size_format(file_size_domain_disk)))
            log.error('Template disk {} Size: {} ({})'.format(path_template_disk, file_size_template_disk,
                                                              size_format(file_size_template_disk)))
            error = 'Crashed'
        else:
            log.error(
                'Domain disk {} would have to be moved, but it is in place. Template disk {} not created, but domain disk with all the data??'.format(
                    path_domain_disk, path_template_disk))
            log.error('Domain disk {} Size: {} ({})'.format(path_domain_disk, file_size_domain_disk,
                                                            size_format(file_size_domain_disk)))
            error = 'Hard'

    return error
示例#3
0
文件: qcow.py 项目: j5boot/isard
def verify_output_cmds1_template_from_domain(cmds_done, path_domain_disk,
                                             path_template_disk, id_domain):
    move_tool = None
    cmd_to_move = None
    path_dir_template = extract_dir_path(path_template_disk)
    error_severity = None

    d = [a for a in cmds_done if a['title'] == 'filesystem_domain'][0]
    if len(d['err']) > 0:
        log.error(
            'domain disk {} doesn\'t exist or permissions access error. Domain:{}. Error: {}'
            .format(path_domain_disk, id_domain, d['err']))
        log.debug('cmd: {}, out: {}, err: {}'.format(d['cmd'], d['out'],
                                                     d['err']))
        error_severity = 'Hard'
    else:
        fs_domain_code = int(d['out'])

    d = [a for a in cmds_done if a['title'] == 'filesystem_template'][0]
    if len(d['err']) > 0 and error_severity != 'Hard':
        log.error(
            'directory for template disk {} can not be created or permissions access error. Domain:{}. Error: {}'
            .format(path_template_disk, id_domain, d['err']))
        log.debug('cmd: {}, out: {}, err: {}'.format(d['cmd'], d['out'],
                                                     d['err']))
        error_severity = 'Hard'
    elif error_severity != 'Hard':
        fs_template_code = int(d['out'])
        if fs_template_code == fs_domain_code:
            move_tool = 'mv'
        else:
            move_tool = 'rsync'

    d = [a for a in cmds_done if a['title'] == 'touch'][0]
    if len(d['err']) > 0 and error_severity != 'Hard':
        log.error(
            'When try to write in directory {} fail with error: {} '.format(
                path_dir_template, d['err']))
        log.debug('cmd: {}, out: {}, err: {}'.format(d['cmd'], d['out'],
                                                     d['err']))
        error_severity = 'Hard'

    d = [a for a in cmds_done if a['title'] == 'df_template_mountpoint'][0]
    if len(d['err']) > 0 and error_severity != 'Hard':
        log.error(
            'When try to know disk free space previous to create template in template directory, command fail'
        )
        log.debug('cmd: {}, out: {}, err: {}'.format(d['cmd'], d['out'],
                                                     d['err']))
        error_severity = 'Hard'
    elif error_severity != 'Hard':
        df_bytes = int(d['out'].splitlines()[-1].split()[3]) * 1024
        log.debug('disk free for create template from domain {}: {}'.format(
            id_domain, size_format(df_bytes)))

    d = [a for a in cmds_done if a['title'] == 'size_template_disk'][0]
    if len(d['err']) > 0 and error_severity != 'Hard':
        log.error(
            'When try to access domain file disk {} fail with error: {} '.
            format(path_domain_disk, d['err']))
        log.debug('cmd: {}, out: {}, err: {}'.format(d['cmd'], d['out'],
                                                     d['err']))
        error_severity = 'Hard'
    elif error_severity != 'Hard':
        disk_size_bytes = int(d['out'])
        log.debug('disk {} size: {} , template filesystem df: {}'.format(
            path_domain_disk, size_format(disk_size_bytes),
            size_format(df_bytes)))
        if disk_size_bytes >= df_bytes:
            log.error(
                'Not enough free space to create template from {}'.format(
                    id_domain))
            log.debug('cmd: {}, out: {}, err: {}'.format(
                d['cmd'], d['out'], d['err']))
            error_severity = 'Hard'

    d = [a for a in cmds_done if a['title'] == 'test_if_template_exists'][0]
    if len(d['err']) == 0:
        log.error(
            'File template that must be created and it exists!! File path: {}'.
            format(path_template_disk))
        log.debug('cmd: {}, out: {}, err: {}'.format(d['cmd'], d['out'],
                                                     d['err']))
        error_severity = 'Hard'

    d = [a for a in cmds_done if a['title'] == 'verify_touch'][0]
    if len(d['err']) > 0 and error_severity != 'Hard':
        if d['out'].find('rights:-r--r--r--') > 0:
            log.debug(
                'change rights readonly test passed for create template from domain {}'
                .format(id_domain))
            log.debug('cmd: {}, out: {}, err: {}'.format(
                d['cmd'], d['out'], d['err']))
        else:
            log.error(
                'PROBLEM change rights readonly test passed for create template from domain {}'
                .format(id_domain))
            log.error('cmd: {}, out: {}, err: {}'.format(
                d['cmd'], d['out'], d['err']))
            error_severity = 'Soft'
            # INFO TO DEVELOPER, DE MOMENTO NO MIRAMOS SI EL PROPIETARIO Y GRUPO ES qemu, si se cree importante aquí habría que implementarlo

    if error_severity == None and move_tool != None:
        if move_tool == 'mv':
            cmd_to_move = 'mv {} {}'.format(path_domain_disk,
                                            path_template_disk)
        if move_tool == 'rsync':
            # cmd_to_move = 'rsync -aP --remove-source-files "{}" "{}"'.format(path_domain_disk,path_template_disk)
            cmd_to_move = 'rsync -aP --inplace --bwlimit=30000 --remove-source-files "{}" "{}"'.format(
                path_domain_disk, path_template_disk)

    return error_severity, move_tool, cmd_to_move
示例#4
0
文件: qcow.py 项目: isard-vdi/isard
def verify_output_cmds1_template_from_domain(cmds_done, path_domain_disk, path_template_disk, id_domain):
    move_tool = None
    cmd_to_move = None
    path_dir_template = extract_dir_path(path_template_disk)
    error_severity = None

    d = [a for a in cmds_done if a['title'] == 'filesystem_domain'][0]
    if len(d['err']) > 0:
        log.error(
            'domain disk {} doesn\'t exist or permissions access error. Domain:{}. Error: {}'.format(path_domain_disk,
                                                                                                     id_domain,
                                                                                                     d['err']))
        log.debug('cmd: {}, out: {}, err: {}'.format(d['cmd'], d['out'], d['err']))
        error_severity = 'Hard'
    else:
        fs_domain_code = int(d['out'])

    d = [a for a in cmds_done if a['title'] == 'filesystem_template'][0]
    if len(d['err']) > 0 and error_severity != 'Hard':
        log.error(
            'directory for template disk {} can not be created or permissions access error. Domain:{}. Error: {}'.format(
                path_template_disk, id_domain, d['err']))
        log.debug('cmd: {}, out: {}, err: {}'.format(d['cmd'], d['out'], d['err']))
        error_severity = 'Hard'
    elif error_severity != 'Hard':
        fs_template_code = int(d['out'])
        if fs_template_code == fs_domain_code:
            move_tool = 'mv'
        else:
            move_tool = 'rsync'

    d = [a for a in cmds_done if a['title'] == 'touch'][0]
    if len(d['err']) > 0 and error_severity != 'Hard':
        log.error('When try to write in directory {} fail with error: {} '.format(path_dir_template, d['err']))
        log.debug('cmd: {}, out: {}, err: {}'.format(d['cmd'], d['out'], d['err']))
        error_severity = 'Hard'

    d = [a for a in cmds_done if a['title'] == 'df_template_mountpoint'][0]
    if len(d['err']) > 0 and error_severity != 'Hard':
        log.error('When try to know disk free space previous to create template in template directory, command fail')
        log.debug('cmd: {}, out: {}, err: {}'.format(d['cmd'], d['out'], d['err']))
        error_severity = 'Hard'
    elif error_severity != 'Hard':
        try:
            df_bytes = int(d['out'].splitlines()[-1].split()[3]) * 1024
        except:
            #if mount point is too large df split output in two lines
            try:
                df_bytes = int(d['out'].splitlines()[-1].split()[2]) * 1024
            except:
                log.info('When try to know disk free space previous to create template output is not standard')
                log.debug('cmd: {}, out: {}, err: {}'.format(d['cmd'], d['out'], d['err']))
                df_bytes = 999999999
        log.debug('disk free for create template from domain {}: {}'.format(id_domain, size_format(df_bytes)))

    d = [a for a in cmds_done if a['title'] == 'size_template_disk'][0]
    if len(d['err']) > 0 and error_severity != 'Hard':
        log.error('When try to access domain file disk {} fail with error: {} '.format(path_domain_disk, d['err']))
        log.debug('cmd: {}, out: {}, err: {}'.format(d['cmd'], d['out'], d['err']))
        error_severity = 'Hard'
    elif error_severity != 'Hard':
        disk_size_bytes = int(d['out'])
        log.debug('disk {} size: {} , template filesystem df: {}'.format(path_domain_disk, size_format(disk_size_bytes),
                                                                         size_format(df_bytes)))
        if disk_size_bytes >= df_bytes:
            log.error('Not enough free space to create template from {}'.format(id_domain))
            log.debug('cmd: {}, out: {}, err: {}'.format(d['cmd'], d['out'], d['err']))
            error_severity = 'Hard'

    d = [a for a in cmds_done if a['title'] == 'test_if_template_exists'][0]
    if len(d['err']) == 0:
        log.error('File template that must be created and it exists!! File path: {}'.format(path_template_disk))
        log.debug('cmd: {}, out: {}, err: {}'.format(d['cmd'], d['out'], d['err']))
        error_severity = 'Hard'

    d = [a for a in cmds_done if a['title'] == 'verify_touch'][0]
    if len(d['err']) > 0 and error_severity != 'Hard':
        if d['out'].find('rights:-r--r--r--') > 0:
            log.debug('change rights readonly test passed for create template from domain {}'.format(id_domain))
            log.debug('cmd: {}, out: {}, err: {}'.format(d['cmd'], d['out'], d['err']))
        else:
            log.error('PROBLEM change rights readonly test passed for create template from domain {}'.format(id_domain))
            log.error('cmd: {}, out: {}, err: {}'.format(d['cmd'], d['out'], d['err']))
            error_severity = 'Soft'
            # INFO TO DEVELOPER, DE MOMENTO NO MIRAMOS SI EL PROPIETARIO Y GRUPO ES qemu, si se cree importante aquí habría que implementarlo

    if error_severity == None and move_tool != None:
        if move_tool == 'mv':
            cmd_to_move = 'mv {} {}'.format(path_domain_disk, path_template_disk)
        if move_tool == 'rsync':
            # cmd_to_move = 'rsync -aP --remove-source-files "{}" "{}"'.format(path_domain_disk,path_template_disk)
            cmd_to_move = 'rsync -aP --inplace --bwlimit=30000 --remove-source-files "{}" "{}"'.format(path_domain_disk,
                                                                                                       path_template_disk)

    return error_severity, move_tool, cmd_to_move