示例#1
0
    def create_pool(user_pool=False,
                    pool_name=pool_name,
                    pool_target=pool_target):
        """
        Create libvirt pool as the output storage
        """
        if output_uri == "qemu:///session" or user_pool:
            target_path = os.path.join("/home", v2v_user, pool_target)
            cmd = su_cmd + "'mkdir -p %s'" % target_path
            process.system(cmd, verbose=True)
            # Sometimes pool_creat_as returns sucess, but the pool can
            # not be found in user session.
            virsh.pool_create_as(pool_name,
                                 'dir',
                                 target_path,
                                 unprivileged_user=v2v_user,
                                 debug=True)

            res = virsh.pool_info(pool_name,
                                  unprivileged_user=v2v_user,
                                  debug=True)
            if res.exit_status != 0:
                return False
        else:
            pvt.pre_pool(pool_name, pool_type, pool_target, emulated_img)

        return True
示例#2
0
 def get_info(self, name):
     infos = {}
     for line in virsh.pool_info(name).stdout.strip().splitlines():
         key, value = line.split(':', 1)
         infos[key.lower()] = value.strip()
     infos['inactive xml'] = virsh.pool_dumpxml(
         name, '--inactive').splitlines()
     infos['volumes'] = virsh.vol_list(name).stdout.strip().splitlines()[2:]
     return infos
def run(test, params, env):
    '''
    Test the command virsh pool-create-as

    (1) Call virsh pool-create-as
    (2) Call virsh -c remote_uri pool-create-as
    (3) Call virsh pool-create-as with an unexpected option
    '''

    # Run test case
    if not params.has_key('pool_name') or not params.has_key('pool_target'):
        logging.error("Please give a 'name' and 'target'")

    pool_options = params.get('pool_options', '')

    pool_name = params.get('pool_name')
    pool_type = params.get('pool_type')
    pool_target = params.get('pool_target')

    if not os.path.isdir(pool_target):
        if os.path.isfile(pool_target):
            logging.error('<target> must be a directory')
        else:
            os.makedirs(pool_target)

    logging.info('Creating a %s type pool %s', pool_type, pool_name)
    status = virsh.pool_create_as(pool_name,
                                  pool_type,
                                  pool_target,
                                  extra=pool_options,
                                  uri=virsh.canonical_uri())

    # Check status_error
    status_error = params.get('status_error')
    if status_error == 'yes':
        if status:
            raise error.TestFail("%d not a expected command return value" %
                                 status)
        else:
            logging.info("It's an expected error")
    elif status_error == 'no':
        result = virsh.pool_info(pool_name, uri=virsh.canonical_uri())
        if result.exit_status:
            raise error.TestFail('Failed to check pool information')
        else:
            logging.info('Pool %s is running', pool_name)
        if not status:
            raise error.TestFail('%d not a expected command return value' %
                                 status)
        else:
            logging.info('Succeed to create pool %s', pool_name)
    # Clean up
    libvirt_pool = libvirt_storage.StoragePool()
    if libvirt_pool.pool_exists(pool_name):
        libvirt_pool.delete_pool(pool_name)
def run(test, params, env):
    '''
    Test the command virsh pool-create-as

    (1) Call virsh pool-create-as
    (2) Call virsh -c remote_uri pool-create-as
    (3) Call virsh pool-create-as with an unexpected option
    '''

    # Run test case
    if not params.has_key('pool_name') or not params.has_key('pool_target'):
        logging.error("Please give a 'name' and 'target'")

    pool_options = params.get('pool_options', '')

    pool_name = params.get('pool_name')
    pool_type = params.get('pool_type')
    pool_target = params.get('pool_target')

    if not os.path.isdir(pool_target):
        if os.path.isfile(pool_target):
            logging.error('<target> must be a directory')
        else:
            os.makedirs(pool_target)

    logging.info('Creating a %s type pool %s', pool_type, pool_name)
    status = virsh.pool_create_as(pool_name, pool_type, pool_target,
                                  extra=pool_options, uri=virsh.canonical_uri())

    # Check status_error
    status_error = params.get('status_error')
    if status_error == 'yes':
        if status:
            raise error.TestFail("%d not a expected command return value"
                                 % status)
        else:
            logging.info("It's an expected error")
    elif status_error == 'no':
        result = virsh.pool_info(pool_name, uri=virsh.canonical_uri())
        if result.exit_status:
            raise error.TestFail('Failed to check pool information')
        else:
            logging.info('Pool %s is running', pool_name)
        if not status:
            raise error.TestFail('%d not a expected command return value'
                                 % status)
        else:
            logging.info('Succeed to create pool %s', pool_name)
    # Clean up
    libvirt_pool = libvirt_storage.StoragePool()
    if libvirt_pool.pool_exists(pool_name):
        libvirt_pool.delete_pool(pool_name)