On 07/03/2012 03:46 AM, Alex Jia wrote: > On 07/03/2012 02:35 PM, Yu Mingfei wrote: >> This patch adds a new filefor xml functions. >> >> Signed-off-by: Yu Mingfei<yuming...@cn.fujitsu.com> >> --- >> client/virt/libvirt_xml_utils.py | 43 >> ++++++++++++++++++++++++++++++++++++++ >> 1 files changed, 43 insertions(+), 0 deletions(-) >> create mode 100644 client/virt/libvirt_xml_utils.py >> >> diff --git a/client/virt/libvirt_xml_utils.py >> b/client/virt/libvirt_xml_utils.py >> new file mode 100644 >> index 0000000..84a21b6 >> --- /dev/null >> +++ b/client/virt/libvirt_xml_utils.py >> @@ -0,0 +1,43 @@ >> +import logging, os, shutil >> +from xml.dom.minidom import parse, parseString >> +from autotest.client.shared import utils, error >> +import libvirt_vm >> + >> + >> +def create_new_vm(old_vm, newname, params): >> + """ >> + Create a new vm through an exist vm,the difference is name and uuid. > It just renames a vm, couldn't virsh edit do this?
virsh edit loads the file into $EDITOR but this is a different test. I think point here is to exercise virsh 'define' which takes xml input. >> + >> + @param old_vm:an exist vm object >> + @param newname:new vm name >> + @param params:params dict of your test target >> + @return:return a vm object >> + """ >> + oldfile = "/etc/libvirt/qemu/%s.xml" % old_vm.name >> + newfile = "/etc/libvirt/qemu/%s.xml" % newname >> + if oldfile == newfile: >> + logging.info("use old vm.") >> + return old_vm >> + shutil.copy(oldfile, newfile) >> + dom = parse(newfile) >> + root = dom.documentElement >> + node_name = root.getElementsByTagName("name")[0] >> + node_name.firstChild.data = "%s" % newname >> + node_uuid = root.getElementsByTagName("uuid")[0] >> + root.removeChild(node_uuid) >> + f=open(newfile, "w") >> + dom.writexml(f) >> + f.close() >> + >> + if not os.path.exists(newfile): >> + raise error.TestError("Failed to create xml file.") >> + >> + if params.has_key("uri"): >> + uri = params.get("uri") >> + status = libvirt_vm.virsh_define(newfile, uri) >> + if not status: >> + os.remove(newfile) >> + raise error.TestError("Failed to define a VM.") >> + >> + new_vm = libvirt_vm.VM(newname, params, old_vm.root_dir, >> old_vm.address_cache) >> + return new_vm >> -- 1.7.1 >> >> _______________________________________________ >> Autotest mailing list >> Autotest@test.kernel.org >> http://test.kernel.org/cgi-bin/mailman/listinfo/autotest > -- Chris Evich, RHCA, RHCE, RHCDS, RHCSS Quality Assurance Engineer e-mail: cevich + `@' + redhat.com o: 1-888-RED-HAT1 x44214 _______________________________________________ Autotest mailing list Autotest@test.kernel.org http://test.kernel.org/cgi-bin/mailman/listinfo/autotest