On 08/28/2012 11:39 PM, 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.
+ """
+ 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
+
+
+ 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()
+
+ origin_mem = get_mem(vm_name)
+ logging.info("\n======\norigin memory : %i\n======", origin_mem)
+
+ #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
+
+ result = libvirt_vm.virsh_setmem(setmem_vm, options,
+ ignore_status=True,
print_info=True)
+ 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)
+
+ #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")
+ 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:
The same issue to previous cases, you should login the guest then check
actual memory value in /proc/meminfo rather than simply check it by
virsh itself.
In addition, you may test 'setmaxmem' command together such as
ballooning memory if you like,
Thanks,
Alex
+ 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
_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel