On 07/27/2012 02:09 AM, Yu Mingfei wrote:
This patch adds test for virsh domname.

Signed-off-by: Yu Mingfei <[email protected]>
---
  client/tests/libvirt/tests/virsh_domname.py |   63
+++++++++++++++++++++++++++
  1 files changed, 63 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..950c812
--- /dev/null
+++ b/client/tests/libvirt/tests/virsh_domname.py
@@ -0,0 +1,63 @@
+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>.
+
+    1) Prepare libvirtd status and test environment.
+    2) Try to get domname through valid and invalid command.
+    3) Recover libvirtd service and test environment.
+    4) Check result.
+    """
+    vm_name = params.get("main_vm", "vm1")
+    vm = env.get_vm(params["main_vm"])
+
+    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")
+    options = params.get("options", "%s")
+    options_suffix = params.get("options_suffix", "")
+    if options_ref == "id":
+        options_ref = domid
+        if options_ref == "-":
+            options = "%s"
+        else:
+            options_ref = int(domid)
+    elif options_ref == "uuid":
+        options_ref = domuuid
+        # UUID can get domain name in any state.
+        addition_status_error = "no"

This could be a little confusing if later someone puts a configuration setting addition_status_error = 'yes'. When the test runs, it will print out params, showing addition_status_error = 'yes'. However, code will silently set addition_status_error = "no".

Ideally, I think it would be good to avoid using 'addition_status_error' parameter (I'm not sure what it's used for).

However, I think to just get this code to "good enough" status, we should at least do a logging.warning("Changing addition_status_error parameter to NO!") if config. has set to 'yes'.

+    elif options_ref == "name":
+        options_ref = vm_name
+
+    if options:
+        options = (options % options_ref)
+    if options_suffix:
+        options = options + " " + options_suffix
+    result = libvirt_vm.virsh_domname(options, ignore_status=True,
print_info=True)
+

As before, I'm not totally thrilled with this big conditional on 'options_ref'. There's nothing logically wrong with doing it, rather it requires keeping configuration and test module code always in-sync. This can be a bit of a maintenance headache :S

Is there a way to simplify this - i.e. make the test module less "smart"? Maybe just have 'options' parameter and configuration spells out entire string to use? It's a little more ugly configuration, but is very easy to maintain, and very easy to add more test variants.

If you can't think of how to do this, don't worry about it. We can save it for a future enhancement. I'd just prefer to get it right the first time, _if_ possible.

+    #Recover libvirtd service to start
+    if libvirtd == "off":
+        libvirt_vm.service_libvirtd_control("start")
+        addition_status_error = "yes"

Note: This block is dependent on the preprocess_vm you're working on.

+    #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


Thanks again, it's coming along nicely.  I'm looking forward to v4!

--
Chris Evich, RHCA, RHCE, RHCDS, RHCSS
Quality Assurance Engineer
e-mail: cevich + `@' + redhat.com o: 1-888-RED-HAT1 x44214

_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel

Reply via email to