On 31/08/12 22:21, Chris Evich wrote:
On 08/28/2012 11:39 AM, Yu Mingfei wrote:
Signed-off-by: Yu Mingfei<[email protected]>
---
  client/tests/libvirt/tests/virsh_setmem.py |   98
++++++++++++++++++++++++++++
  1 files changed, 98 insertions(+), 0 deletions(-)
  create mode 100644 client/tests/libvirt/tests/virsh_setmem.py

diff --git a/client/tests/libvirt/tests/virsh_setmem.py
b/client/tests/libvirt/tests/virsh_setmem.py
new file mode 100644
index 0000000..a9b5155
--- /dev/null
+++ b/client/tests/libvirt/tests/virsh_setmem.py
@@ -0,0 +1,98 @@
+import re, logging, commands, time
+from autotest.client.shared import utils, error
+from autotest.client.virt import libvirt_vm
+
+
+def run_virsh_setmem(test, params, env):
+    """
+    Test command: virsh setmem.
+
+    1) Prepare vm environment.
+    2) Prepare libvirt state.
+    3) Run test command and wait for current memory's stable.
+    4) Check result.
+    TODO: support new libvirt with more options.
+    """

Good, simple, well written docstring.  Thanks!

+    def get_mem(vm):
+        output = libvirt_vm.virsh_dominfo(vm)
+        lines = output.split("\n")
+        get_memory = 0
+        for line in lines:
+            if re.search("Used memory:", line):
+                get_memory = int(re.split(" ", line)[-2])
+        return get_memory

Hmmm, what about making this as a method on vm class? This seems like it would be useful function? If not, no worries, just a thought I had.
Ok, I will consider about it.:-)


+
+
+    vm_name = params.get("main_vm", "vm1")
+    vm = env.get_vm(params["main_vm"])
+    domid_result = libvirt_vm.virsh_domid(vm_name)
+    domid = domid_result.strip()
+    domuuid_result = libvirt_vm.virsh_uuid(vm_name)
+    domuuid = domuuid_result.strip()
+
+    if params.get("start_vm") != "no":
+        vm.wait_for_login()

Good catch!

+
+    origin_mem = get_mem(vm_name)
+    logging.info("\n======\norigin memory : %i\n======", origin_mem)

I have been in bad mood about too much logging.info() lately. However I think this one is okay.

+    #Prepare libvirtd service
+    libvirt = params.get("libvirt", "on")
+    if libvirt == "off":
+        libvirt_vm.service_libvirtd_control("stop")
+
+    #Run test case
+    vm_ref = params.get("vm_ref", "")
+    setmem_vm = params.get("setmem_vm", "%s")
+    options_ref = params.get("options_ref", "")
+    options_prefix = params.get("options_prefix", "")
+    options_suffix = params.get("options_suffix", "")
+
+    if vm_ref == "domid":
+        if domid == "-":
+            vm_ref = domid
+        else:
+            vm_ref = int(domid)
+    elif vm_ref == "domname":
+        vm_ref = vm_name
+    elif vm_ref == "domuuid":
+        vm_ref = domuuid
+
+    if options_ref == "default_half":
+        options_ref = origin_mem/2
+
+    setmem_vm = setmem_vm % vm_ref
+    new_memory = options_ref
+    options = options_prefix + " " + str(options_ref) + " " +
options_suffix

I'm nervous about having lots of code between changing libvirtd service state because if there is any problem, it can mess up all following tests. I had a big struggle with this while working on new virsh module.

Can we move all the options/parameter processing code above the '#Prepare libvirtd service'? I think it will be a little safer this way.
Thanks very much for your remider.
I run all ok in my test, so I do not notice this problem.:-)


+    result = libvirt_vm.virsh_setmem(setmem_vm, options,
+ ignore_status=True, print_info=True)

Also, '#Run test case' comment probably needs to move closer to here.

+    status = result.exit_status
+    #After set memory, guest's current memory will be set step by step
+    #wait 10s here to be stable
+    time.sleep(10)
+
+    #Recover libvirtd service
+    if libvirt == "off":
+        libvirt_vm.service_libvirtd_control("start")
+
+    if not status:
+        current_memory = int(get_mem(vm_name))
+        logging.info("\n======\ncurrent memory : %i\n======",
current_memory)

Is this too much logging.info()?  I can't tell anymore, it's up to you :D
But I just want to print memory before set and after set.:-(
Otherwise, we can not trace memory's change.


+
+    #check status_error
+    vm_status_error = params.get("vm_status_error", "no")
+    addition_status_error = params.get("addition_status_error", "no")
+    status_error = (vm_status_error == "no") and (addition_status_error
== "no")

What is addition_status_error for? I think I asked before, because it's only 'and' here with status_error. Other people may have same question, it would be good to put comment here and in config. explaining what addition_status_error is used for. Sorry, I have bad memory sometimes.
I'm very sorry, it's my fault. I will add explain as possible as I can.:-P


+    mem_status_error = params.get("mem_status_error", "no")
+    status_error = status_error and (mem_status_error == "no")
+    if status_error:
+        if status != 0:
+            raise error.TestFail("Run failed with right command!")
+        else:
+            if new_memory and current_memory != new_memory:
+                raise error.TestFail(
+                        "Run successful but result is not expected")
+    else:
+        if status == 0:
+            raise error.TestFail("Run successful with wrong command")
-- 1.7.1

--
Best Regards
Yu Mingfei


Otherwise looks good. It follows a familiar pattern as other tests which helps make it easy to understand. I like how the test module is very simple, and does not try to do complex operations.

Thanks
Yu

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

Reply via email to