On 07/13/2012 06:06 AM, Alex Jia wrote: > On 07/13/2012 05:53 PM, Yu Mingfei wrote: >> This patch adds test to file virsh_net_create.py. >> >> Signed-off-by: Yu Mingfei <yuming...@cn.fujitsu.com> >> --- >> client/tests/libvirt/tests/virsh_net_create.py | 61 >> ++++++++++++++++++++++++ >> 1 files changed, 61 insertions(+), 0 deletions(-) >> create mode 100644 client/tests/libvirt/tests/virsh_net_create.py >> >> diff --git a/client/tests/libvirt/tests/virsh_net_create.py >> b/client/tests/libvirt/tests/virsh_net_create.py >> new file mode 100644 >> index 0000000..3a02970 >> --- /dev/null >> +++ b/client/tests/libvirt/tests/virsh_net_create.py >> @@ -0,0 +1,61 @@ >> +import re, logging, time >> +from autotest.client.shared import utils, error >> +from autotest.client.virt import libvirt_vm >> + >> + >> +def run_virsh_net_create(test, params, env): >> + """ >> + Test command: virsh net-create. >> + >> + 1) Create default network with default XML file. >> + 2) Create network with none. >> + 3) Create network with a not exist option. >> + 4) Create default network with an additional string. >> + 5) Create default network with an additional option. >> + 6) Create default network with libvirtd stop. > > Please consider actual application and test scenario rather than simply > call virsh cmd and check them still using virsh cmd again. > > You should test different network such as NAT, Route, Isolate, etc then > install a guest to use new virtual network and check network connectivity. > > http://libvirt.org/formatnetwork.html > > Anyway, thanks for your patches. > > Alex > >> + """ >> + #If default network exists, destroy it for test. >> + list_output = libvirt_vm.virsh_net_list("", >> print_info=True).stdout.strip() >> + if re.search("default", list_output): >> + libvirt_vm.virsh_net_destroy("default", print_info=True) >> + >> + #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", "default") >> + extra = params.get("extra", "") >> + if options_ref == "default": >> + options_ref = "/etc/libvirt/qemu/networks/default.xml" >> + elif options_ref == "additional": >> + options_ref = "/etc/libvirt/qemu/networks/default.xml" >> + elif options_ref == "none": >> + options_ref == "" >> + >> + result = libvirt_vm.virsh_net_create(options_ref, extra, >> ignore_status=True, print_info=True) >> + status = result.exit_status >> + output = result.stdout.strip() >> + >> + #Recover libvirtd service start >> + if libvirtd == "off": >> + libvirt_vm.service_libvirtd_control("start") >> + >> + #Recover default network if neccessary. >> + list_output = libvirt_vm.virsh_net_list("", >> print_info=True).stdout.strip() >> + if not re.search("default", list_output): >> + >> libvirt_vm.virsh_net_create("/etc/libvirt/qemu/networks/default.xml", >> print_info=True) >> + >> + #Check status_error >> + status_error = params.get("status_error", "no") >> + addition_status_error = params.get("addition_status_error", "no") >> + status_error = (status_error == "no") and (addition_status_error >> == "no") >> + if not status_error: >> + if status == 0: >> + raise error.TestFail("Run successful with wrong command!") >> + else: >> + if status != 0: >> + raise error.TestFail("Run failed with right command.") >> + if not re.search(options_ref, output): >> + raise error.TestFail("Run successful but result is not >> expected.") >
I agree with both :) I think we should test closely to actual use (as Alex suggests). However, for initial commit (as you have done) don't kill yourself trying to account for every combination. What I suggest is, follow the sequence in the documentation: http://libvirt.org/formatnetwork.html with one sub-function per documentation section. For example: xml = make_general_metadata(vm) xml = make_connectivity(xml, vm) xml = make_qos(xml, vm) xml = make_postgroups(xml, vm) xml = make_addressing(xml, vm) Where each sub-function incrementally builds the XML based on Cartesian params input. But this is too complicated for for initial code. It's fine if you want to just put in stubs for now - i.e. make_qos() can just do 'return xml' for now. Other functions can just return equivalent of same sections in /etc/libvirt/qemu/networks/default.xml as you have done. This way, we have flexibility later to fill-out complete building functions, and utilize Cartesian system to make all of the combination for us. What I suggest for first pass, is put in the basic framework. -- 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