Example #1
0
def run_virsh_uri(test, params, env):
    """
    Test the command virsh uri

    (1) Call virsh uri
    (2) Call virsh -c remote_uri uri
    (3) Call virsh uri with an unexpected option
    (4) Call virsh uri with libvirtd service stop
    """

    connect_uri = libvirt_vm.normalize_connect_uri( params.get("connect_uri",
                                                               "default") )

    option = params.get("options")
    target_uri = params.get("target_uri")
    if target_uri:
        if target_uri.count('EXAMPLE.COM'):
            raise error.TestError('target_uri configuration set to sample value')
        logging.info("The target_uri: %s", target_uri)
        cmd = "virsh -c %s uri" % target_uri
    else:
        cmd = "virsh uri %s" % option

    # Prepare libvirtd service
    check_libvirtd = params.has_key("libvirtd")
    if check_libvirtd:
        libvirtd = params.get("libvirtd")
        if libvirtd == "off":
            libvirt_vm.service_libvirtd_control("stop")

    # Run test case
    logging.info("The command: %s", cmd)
    try:
        uri_test = virsh.canonical_uri(option, uri=connect_uri,
                             ignore_status=False,
                             debug=True)
        status = 0 # good
    except error.CmdError:
        status = 1 # bad
        uri_test = ''

    # Recover libvirtd service start
    if libvirtd == "off":
        libvirt_vm.service_libvirtd_control("start")

    # Check status_error
    status_error = params.get("status_error")
    if status_error == "yes":
        if status == 0:
            raise error.TestFail("Command: %s  succeeded "
                                 "(incorrect command)" % cmd)
        else:
            logging.info("command: %s is a expected error", cmd)
    elif status_error == "no":
        if cmp(target_uri, uri_test) != 0:
            raise error.TestFail("Virsh cmd uri %s != %s." % (uri_test,target_uri))
        if status != 0:
            raise error.TestFail("Command: %s  failed "
                                 "(correct command)" % cmd)
Example #2
0
def run_virsh_pool_create_as(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':
        if not virsh.pool_info(pool_name, uri=virsh.canonical_uri()):
            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)