This patch adds 50 cases for virsh domanme.
Signed-off-by: Yu Mingfei <[email protected]>
---
client/tests/libvirt/tests/virsh_domname.py | 122 +++++++++++++++++++++++++++
1 files changed, 122 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..191dc5b
--- /dev/null
+++ b/client/tests/libvirt/tests/virsh_domname.py
@@ -0,0 +1,122 @@
+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>.
+
+ There are 50 testcases according subtest.cfg, list by its type:
+ 1) origin vm name to test valid options.(2)
+ 2) origin vm name to test invalid options.(6)
+ 3) new vm name(number) to test valid options.(2)
+ 4) new vm name(number) to test invalid options.(6)
+ 5) new vm name(symbol) to test valid options.(2)
+ 6) new vm name(symbol) to test invalid options.(6)
+ 7) new vm name(symbol_letter_number) to test valid options.(2)
+ 8) new vm name(symbol_letter_number) to test invalid options.(6)
+ 9) test valid options with vm paused.(2)
+ 10) test invalid options with vm paused.(6)
+ 11) test valid options with vm shut_off.(2)
+ 12) test invalid options with vm shut_off.(6)
+ 13) test valid options with libvirtd stop.(2)
+ """
+ #Define function for domname
+ def virsh_domname(option_ref):
+ """
+ Execute domanme with option(option_ref).
+ @param option_ref:options of domname
+ @return:a object of result, including exit_status,stdout,stderr
+ """
+ cmd = "virsh domname %s" % option_ref
+ cmd_result = utils.run(cmd, ignore_status=True)
+ logging.info("Status: %d", cmd_result.exit_status)
+ logging.info("Output: %s", cmd_result.stdout.strip())
+ logging.info("Error: %s", cmd_result.stderr.strip())
+ return cmd_result
+
+ vm_name = params.get("main_vm", "vm1")
+ vm = env.get_vm(params["main_vm"])
+ if vm.is_alive():
+ vm.destroy()
+ time.sleep(2)
+
+ #Rename vm if it is necessary and prepare its state
+ pre_vm_state = params.get("pre_vm_state", "running")
+ vm_ref = params.get("vm_ref", "origin_name")
+ if vm_ref == "new_name":
+ newname = params.get("new_vm_name", "")
+ vm.rename(newname)
+
+ if params.get("need_escape", "no") == "yes":
+ vm.name = "\\" + vm.name
+
+ if vm_ref == "new_name":
+ test_name = newname
+ else:
+ test_name = vm_name
+
+ if not pre_vm_state == "shut off":
+ vm.start()
+ time.sleep(5)
+
+ if 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
+ option_ref = params.get("option_ref", "id")
+ addition_status_error = params.get("addition_status_error", "no")
+ status_error = params.get("status_error", "no")
+ if option_ref == "id":
+ option_ref = domid
+ elif option_ref == "hex_id" and domid != "-":
+ option_ref = hex(int(domid))
+ elif option_ref == "uuid":
+ option_ref = domuuid
+ addition_status_error = "no"
+ elif option_ref == "invalid_uuid":
+ option_ref = params.get("invalid_uuid")
+ elif option_ref == "invalid_id":
+ option_ref = params.get("invalid_id")
+ elif option_ref == "invalid_param":
+ option_ref = "%s xyz" % domid
+ elif option_ref == "name":
+ option_ref = test_name
+
+ result = virsh_domname(option_ref)
+
+ #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)
+
+ #Cleanup
+ if vm_ref == "new_name":
+ vm.rename(vm_name)
+
+ #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() != test_name:
+ raise error.TestFail("Run failed because unexpected result.")
+ else:
+ if result.exit_status == 0 and result.stdout.strip != test_name:
+ raise error.TestFail("Run passed but result is unexpected.")
-- 1.7.1
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest