On 07/12/2012 11:39 AM, Yu Mingfei wrote:
> This patch adds testcases to file 
> client/tests/libvirt/tests/virsh_list.py.
>
> Signed-off-by: Yu Mingfei <yuming...@cn.fujitsu.com>
> ---
>  client/tests/libvirt/tests/virsh_list.py |  100 
> ++++++++++++++++++++++++++++++
>  1 files changed, 100 insertions(+), 0 deletions(-)
>  create mode 100644 client/tests/libvirt/tests/virsh_list.py
>
> diff --git a/client/tests/libvirt/tests/virsh_list.py 
> b/client/tests/libvirt/tests/virsh_list.py
> new file mode 100644
> index 0000000..4489e7c
> --- /dev/null
> +++ b/client/tests/libvirt/tests/virsh_list.py
> @@ -0,0 +1,100 @@
> +import re, logging, time, commands
> +from autotest.client.shared import utils, error
> +from autotest.client.virt import virt_remote, libvirt_vm
> +
> +
> +def run_virsh_list(test, params, env):
> +    """
> +    Test command: virsh list.
> +
> +    There are 17 testcases according subtest.cfg:
> +    1) local test with parameter "--inactive"
> +    2) local test with parameter "--all"
> +    3) local test with parameter ""
> +    4) local test with parameter "xyz"
> +    5) local test with parameter domid
> +    6) local test with parameter domname
> +    7) local test with parameter domuuid
> +    8) virsh to local on remote host with parameter "--inactive"
> +    9) virsh to local on remote host with parameter "--all"
> +    10) virsh to local on remote host with parameter ""
> +    11) virsh to local on remote host with parameter "xyz"
> +    12) virsh to local on remote host with parameter domid
> +    13) virsh to local on remote host with parameter domname
> +    14) virsh to local on remote host with parameter domuuid
> +    15) local test with parameter "--inactive" when libvirtd off
> +    16) local test with parameter "--all" when libvirtd off
> +    17) local test with parameter "" when libvirtd off

We need more test scenarios to test the following options:

     --transient      list transient domains
     --persistent     list persistent domains
     --with-snapshot  list domains with existing snapshot
     --without-snapshot  list domains without a snapshot
     --state-running  list domains in running state
     --state-paused   list domains in paused state
     --state-shutoff  list domains in shutoff state
     --state-other    list domains in other states
     --autostart      list domains with autostart enabled
     --no-autostart   list domains with autostart disabled
     --with-managed-save  list domains with managed save state
     --without-managed-save  list domains without managed save
     --table          list table (default)
     --managed-save   mark inactive domains with managed save state
     --title          show short domain description


> +    """
> +    def list_local_on_remote(parameter_ref, remote_ip, remote_passwd, 
> local_ip):

list_local_on_remote? maybe,  list_domain(xx, xx, ..., flag='local') is 
enough then you need to
pass a flag value 'remote' or 'local' is default, or you don't need 
'flag' parameter, a 'uri' should
be enough, it may be local or remote uri.

> +        command_on_remote = "virsh -c qemu+ssh://%s/system list %s" % 
> (local_ip, parameter_ref)

Should call your virsh_list() then pass a remote uri rather than 
directly run 'virsh list' command again.

> +        session = virt_remote.remote_login("ssh", remote_ip, "22", 
> "root", remote_passwd, "#")
> +        time.sleep(5)
> +        status, output = session.cmd_status_output(command_on_remote, 
> internal_timeout=5)
> +        time.sleep(5)
> +        session.close()
> +        return int(status), output
> +
> +    vm_name = params.get("main_vm", "vm1")
> +    vm = env.get_vm(params["main_vm"])
> +    if not vm.is_alive():
> +        vm.start()
> +    time.sleep(5)
> +
> +    #Prepare libvirtd status
> +    libvirtd = params.get("libvirtd", "on")
> +    if libvirtd == "off":
> +        libvirt_vm.service_libvirtd_control("stop")

To be honest, I indeed don't like this, I saw each case(including 
existing cases) tested it with libvirtd service stop, IMHO, it's not a 
good idea to restart libvirtd service during the testing, it even probably
misses some bugs. In addition, AFAIK, virsh command can't work after 
libvirtd service stop except for 'virsh itself' group commands, perhaps 
we may discussed it with autotest guys later.

> +
> +    #run test case
> +    parameter_ref = params.get("parameter_ref", "")

s/parameter_ref/options/g.

> +    if parameter_ref == "id":
> +        domid = vm.get_id().strip()
> +        logging.info("%s's running-id is: %s", vm_name, domid)
> +        parameter_ref = domid
> +    elif parameter_ref == "uuid":
> +        domuuid = vm.get_uuid().strip()
> +        logging.info("%s's uuid is: %s", vm_name, domuuid)
> +        parameter_ref = domuuid
> +    elif parameter_ref == "inactive":
> +        vm.destroy()
> +        parameter_ref = "--inactive"
> +    elif parameter_ref == "name":
> +        parameter_ref = vm_name
> +    elif parameter_ref == "all":
> +        parameter_ref = "--all"
> +
> +    remote_ref = params.get("remote_ref", "local")
> +    if remote_ref == "remote":
> +        remote_ip = params.get("remote_ip", "none")
> +        remote_passwd = params.get("remote_passwd", "none")
> +        local_ip = params.get("local_ip", "none")
> +        logging.info("Execute virsh command on remote host %s.", 
> remote_ip)
> +        status, output = list_local_on_remote(parameter_ref, 
> remote_ip, remote_passwd, local_ip)

If there aren't guests are on remote machine, you may run virsh remotely 
to connect yourself local machine to simulate list remote guests.

> +        logging.info("Status:%s", status)
> +        logging.info("Output:\n%s", output)
> +    else:
> +        result = libvirt_vm.virsh_list(parameter_ref, 
> ignore_status=True)
> +        status = result.exit_status
> +        output = result.stdout.strip()
> +        logging.info("Status:%s", status)
> +        logging.info("Output:\n%s", output)
> +        if status:
> +            logging.info("Error:\n%s", result.stderr.strip())
> +
> +    #Recover libvirtd service status
> +    if libvirtd == "off":
> +        libvirt_vm.service_libvirtd_control("start")
> +
> +    #Check result
> +    status_error = params.get("status_error", "no")
> +    addition_status_error = params.get("addition_status_error", "no")
> +    status_error = (status_error == "no") and (addition_status_error 
> == "no")
> +    if not status_error:
> +        if status == 0 and parameter_ref != "":
> +            raise error.TestFail("Run successful with wrong command!")
> +    else:
> +        if status != 0:
> +            raise error.TestFail("Run failed with right command.")
> +        if not re.search(vm_name, output):
> +            raise error.TestFail("Run successful but result is not 
> expected.")
Thanks for your
_______________________________________________
Autotest mailing list
Autotest@test.kernel.org
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to