----- Original Message ----- From: "Yu Mingfei" <[email protected]> To: "Chris Evich" <[email protected]>, "Alex Jia" <[email protected]> Cc: [email protected] Sent: Wednesday, July 25, 2012 4:04:41 PM Subject: [PATCH 3/3 v2] Add test for virsh domname
This patch adds test for virsh domname. Signed-off-by: Yu Mingfei <[email protected]> --- client/tests/libvirt/tests/virsh_domname.py | 83 +++++++++++++++++++++++++++ 1 files changed, 83 insertions(+), 0 deletions(-) create mode 100644 client/tests/libvirt/tests/virsh_domname.py diff --git a/client/tests/libvirt/tests/virsh_domname.py b/client/tests/libvirt/tests/virsh_domname.py new file mode 100644 index 0000000..b2ef07f --- /dev/null +++ b/client/tests/libvirt/tests/virsh_domname.py @@ -0,0 +1,83 @@ +import logging, time +from autotest.client.shared import utils, error +from autotest.client.virt import libvirt_vm + + +def run_virsh_domname(test, params, env): + """ + Test command: virsh domname <id/uuid>. + + There are 26 testcases, list by its type: + 1) test valid options.(2) + 2) test invalid options.(6) + 3) test valid options with vm paused.(2) + 4) test invalid options with vm paused.(6) + 5) test valid options with vm shut_off.(2) + 6) test invalid options with vm shut_off.(6) I remembered I have ever sent a simple example from libvirt upstream to you, you may use id and uuid to get VM's name then compare whether they are the same name. Alex + 7) test valid options with libvirtd stop.(2) + """ + vm_name = params.get("main_vm", "vm1") + vm = env.get_vm(params["main_vm"]) + if not vm.is_alive(): + vm.start() + time.sleep(5) + + pre_vm_state = params.get("pre_vm_state", "running") + if pre_vm_state == "shut off": + vm.destroy() + time.sleep(2) + elif pre_vm_state == "paused": + vm.pause() + time.sleep(2) + + domid = vm.get_id().strip() + domuuid = vm.get_uuid().strip() + + #Prepare libvirtd status + libvirtd = params.get("libvirtd", "on") + if libvirtd == "off": + libvirt_vm.service_libvirtd_control("stop") + + #run test case + options_ref = params.get("options_ref", "id") + addition_status_error = params.get("addition_status_error", "no") + status_error = params.get("status_error", "no") + if options_ref == "id": + options_ref = domid + elif options_ref == "hex_id" and domid != "-": + options_ref = hex(int(domid)) + elif options_ref == "uuid": + options_ref = domuuid + addition_status_error = "no" + elif options_ref == "invalid_uuid": + options_ref = params.get("invalid_uuid") + elif options_ref == "invalid_id": + options_ref = params.get("invalid_id") + elif options_ref == "invalid_param": + options_ref = "%s xyz" % domid + elif options_ref == "name": + options_ref = vm_name + + result = libvirt_vm.virsh_domname(options_ref, ignore_status=True, print_info=True) + + #Recover libvirtd service to start + if libvirtd == "off": + libvirt_vm.service_libvirtd_control("start") + addition_status_error = "yes" + + if pre_vm_state == "paused": + vm.resume() + time.sleep(2) + + if vm.is_alive(): + vm.destroy() + time.sleep(2) + + #check status_error + status_error = (status_error == "no") and (addition_status_error == "no") + if status_error: + if result.exit_status != 0 or result.stdout.strip() != vm_name: + raise error.TestFail("Run failed because unexpected result.") + else: + if result.exit_status == 0 and result.stdout.strip() != vm_name: + raise error.TestFail("Run passed but result is unexpected.") -- 1.7.1 -- Best Regards Yu Mingfei _______________________________________________ Autotest mailing list [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
