Signed-off-by: Li Yang <[email protected]>
---
.../libvirt/tests/virsh_domxml_from_native.py | 104
++++++++++++++++++++
1 files changed, 104 insertions(+), 0 deletions(-)
create mode 100644 client/tests/libvirt/tests/virsh_domxml_from_native.py
diff --git a/client/tests/libvirt/tests/virsh_domxml_from_native.py
b/client/tests/libvirt/tests/virsh_domxml_from_native.py
new file mode 100644
index 0000000..df8c90e
--- /dev/null
+++ b/client/tests/libvirt/tests/virsh_domxml_from_native.py
@@ -0,0 +1,104 @@
+import re, os, os.path, logging, commands ,time
+from autotest.client.shared import utils, error
+from autotest.client.virt import libvirt_vm
+
+
+def run_virsh_domxml_from_native(test, params, env):
+ """
+ Test command: virsh domxml-from-native.
+ """
+ vm_name = params.get("main_vm", "vm1")
+ vm = env.get_vm(params["main_vm"])
+ vm.verify_alive()
+ time.sleep(2)
+
+ #define function
+
+ def virsh_convxml(vm_name, guest_args):
+ """
+ Put dumpxml vm'infomation to a file
+ @param: vm_name : VM's name
+ @param: guest_args : File which will save config infomation.
+ """
+ utils.run("touch %s" % guest_args, ignore_status=True)
+ grep_command = "ps ax | grep qemu |grep -v grep | grep %s" %
vm_name
+ sed_command = "| sed -e 's/^\s\+//g' | cut -d' ' -f1"
+ command = grep_command + sed_command
+ guest, PID = commands.getstatusoutput(command)
+ command = "ps -p %s -o args | sed -e 's/COMMAND//g'" % PID
+ guest, cmdline = commands.getstatusoutput(command)
+ file = open(guest_args,'w')
+ file.write(cmdline)
+ file.close()
+ command = "sed -i 's/ -drive [^ ]* / /g' %s" % guest_args
+ commands.getstatusoutput(command)
+ libvirt_vm.virsh_dumpxml(vm_name)
+ status, output = commands.getstatusoutput("cat %s" % guest_args)
+ logging.info("file: %s",output)
+
+ def put_vm_info_to_file(vm_name, vm_ref, guest_args, file_exist):
+ """
+ Put vm'infomation to a file when file exists.
+ @param: vm_name : VM's name.
+ @param: vm_ref : Decide 'domxml-from-native' conmand's options.
+ @param: guest_args : File which will save config infomation.
+ @param: file_exist : Judge file exists or not.
+ """
+ if vm_ref == "file_guest_args" or (vm_ref ==
"file_guest_args_invalid"
+ and file_exist == "file_exist"):
+ virsh_convxml(vm_name, guest_args)
+
+ def modify_ref(vm_ref, guest_args, invalid_guest_args):
+ """
+ Motify vm_ref(virsh_domxml_from_native's options) according to
+ vm_ref(input) and return motified vm_ref
+ @param: vm_ref : Decide 'domxml-from-native' conmand's options.
+ @param: guest_args: 'domxml-from-native' conmand's options(file).
+ @param: args: 'domxml-from-native' conmand's invalid options.
+ """
+ if vm_ref == "file_guest_args":
+ vm_ref = "qemu-argv %s %s" % (guest_args, invalid_guest_args)
+ elif vm_ref == "invalid_guest_args":
+ vm_ref = "qemu-argv %s" % invalid_guest_args
+ elif vm_ref == "file_guest_args_invalid":
+ vm_ref = "qemu-argv %s %s"% (guest_args, invalid_guest_args)
+ return vm_ref
+
+ #prepare libvirtd service
+ file_exist = params.get("file_exist","null")
+ libvirtd = params.get("libvirtd", "on")
+ #run test case
+
+ vm_ref = params.get("vm_ref")
+ guest_args = params.get("guest_args")
+ args = params.get("invalid_guest_args")
+ #put vm's infomation to a file
+ put_vm_info_to_file(vm_name, vm_ref, guest_args, file_exist)
+
+ #modify domxml-from-native's options
+ vm_ref = modify_ref(vm_ref, guest_args, args)
+
+ #libvirtd off
+ if libvirtd =="off":
+ libvirt_vm.libvirtd_stop()
+ vm_ref = "qemu-argv %s" % guest_args
+ ret = libvirt_vm.virsh_domxml_from_native(vm_ref,ignore_status=True)
+ status = ret.exit_status
+
+ #recover libvirtd service start
+ if libvirtd =="off":
+ libvirt_vm.libvirtd_start()
+ time.sleep(5)
+
+ #clean up
+ if os.path.exists(guest_args):
+ os.remove(guest_args)
+
+ #check status_error
+ status_error = params.get("status_error")
+ if status_error == "yes":
+ if status == 0:
+ raise error.TestFail("Run successfully with wrong command!")
+ elif status_error == "no":
+ if status != 0:
+ raise error.TestFail("Run failed with right command")
--
1.7.1
--
Regards,
--------------------------------------------------
Li Yang
TEL:+86+25-86630566-8526
EMail:[email protected]
--------------------------------------------------
_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel