This test module looks good to me, nice and simple, validates results against secondary sources, and when it breaks in possibly confusing ways there is clear exception string used. Nice work.
On 05/24/2012 10:38 PM, guyanhua wrote: > > This patch adds three test cases for "virsh nodeinfo" command. > > Use three cases:(1) Call virsh nodeinfo > (2) Call virsh nodeinfo with an unexpected option > (3) Call virsh nodeinfo with libvirtd service stop > > Signed-off-by: Gu Yanhua<[email protected]> > --- > client/tests/libvirt/tests/virsh_nodeinfo.py | 102 > ++++++++++++++++++++++++++ > 1 files changed, 102 insertions(+), 0 deletions(-) > create mode 100755 client/tests/libvirt/tests/virsh_nodeinfo.py > > diff --git a/client/tests/libvirt/tests/virsh_nodeinfo.py > b/client/tests/libvirt/tests/virsh_nodeinfo.py > new file mode 100755 > index 0000000..8350b84 > --- /dev/null > +++ b/client/tests/libvirt/tests/virsh_nodeinfo.py > @@ -0,0 +1,102 @@ > +import re, logging > +from autotest.client.shared import utils, error > +from autotest.client.virt import libvirt_vm > +from autotest.client import * > + > +def run_virsh_nodeinfo(test, params, env): > + """ > + Test the command virsh nodeinfo > + > + (1) Call virsh nodeinfo > + (2) Call virsh nodeinfo with an unexpected option > + (3) Call virsh nodeinfo with libvirtd service stop > + """ > + def _check_nodeinfo(verify_str, column): > + cmd = "virsh nodeinfo | grep \"%s\" | awk '{print $%s}'" % > (verify_str, column) > + cmd_result = utils.run(cmd, ignore_status=True) > + stdout = cmd_result.stdout.strip() > + logging.debug("Info %s on nodeinfo output:%s" % (verify_str, > stdout)) > + return stdout > + > + > + def output_check(): > + # Check CPU model > + cpu_model_nodeinfo = _check_nodeinfo('CPU model', 3) > + cpu_model_os = base_utils.get_current_kernel_arch() > + if not re.match(cpu_model_nodeinfo, cpu_model_os): > + raise error.TestFail("Virsh nodeinfo output didn't match CPU > model") > + > + # Check number of CPUs > + cpus_nodeinfo = int(_check_nodeinfo('CPU(s)', 2)) > + cpus_os = base_utils.count_cpus() > + if cpus_nodeinfo != cpus_os: > + raise error.TestFail("Virsh nodeinfo output didn't match number > of " > + "CPU(s)") > + > + # Check CPU frequency > + cpu_frequency_nodeinfo = _check_nodeinfo('CPU frequency', 3) > + cmd = ("cat /proc/cpuinfo | grep 'cpu MHz' | head -n1 | " > + "awk '{print $4}' | awk -F. '{print $1}'") > + cmd_result = utils.run(cmd, ignore_status=True) > + cpu_frequency_os = cmd_result.stdout.strip() > + if not re.match(cpu_frequency_nodeinfo, cpu_frequency_os): > + raise error.TestFail("Virsh nodeinfo output didn't match CPU " > + "frequency") > + > + # Check CPU socket(s) > + cpu_sockets_nodeinfo = int(_check_nodeinfo('CPU socket(s)', 3)) > + cmd = "grep 'physical id' /proc/cpuinfo | uniq | sort | uniq |wc -l" > + cmd_result = utils.run(cmd, ignore_status=True) > + cpu_NUMA_nodeinfo = _check_nodeinfo('NUMA cell(s)', 3) > + cpu_sockets_os = > int(cmd_result.stdout.strip())/int(cpu_NUMA_nodeinfo) > + if cpu_sockets_os != cpu_sockets_nodeinfo: > + raise error.TestFail("Virsh nodeinfo output didn't match CPU " > + "socket(s)") > + > + # Check Core(s) per socket > + cores_per_socket_nodeinfo = _check_nodeinfo('Core(s) per socket', 4) > + cmd = "grep 'cpu cores' /proc/cpuinfo | head -n1 | awk '{print $4}'" > + cmd_result = utils.run(cmd, ignore_status=True) > + cores_per_socket_os = cmd_result.stdout.strip() > + if not re.match(cores_per_socket_nodeinfo, cores_per_socket_os): > + raise error.TestFail("Virsh nodeinfo output didn't match Core(s) > " > + "per socket") > + > + # Check Memory size > + memory_size_nodeinfo = int(_check_nodeinfo('Memory size', 3)) > + memory_size_os = base_utils.memtotal() > + if memory_size_nodeinfo != memory_size_os: > + raise error.TestFail("Virsh nodeinfo output didn't match " > + "Memory size") > + > + > + # Prepare libvirtd service > + check_libvirtd = params.has_key("libvirtd") > + if check_libvirtd: > + libvirtd = params.get("libvirtd") > + if libvirtd == "off": > + libvirt_vm.service_libvirtd_control("stop") > + > + # Run test case > + option = params.get("virsh_node_options") > + status, output = libvirt_vm.virsh_nodeinfo(option) > + > + # Recover libvirtd service start > + if libvirtd == "off": > + libvirt_vm.service_libvirtd_control("start") > + > + # Check status_error > + status_error = params.get("status_error") > + if status_error == "yes": > + if status == 0: > + if libvirtd == "off": > + raise error.TestFail("Command 'virsh nodeinfo' succeeded " > + "with libvirtd service stopped, > incorrect") > + else: > + raise error.TestFail("Command 'virsh nodeinfo %s' succeeded" > + "(incorrect command)" % option) > + elif status_error == "no": > + output_check() > + if status != 0: > + raise error.TestFail("Command 'virsh nodeinfo %s' failed " > + "(correct command)" % option) > -- > 1.7.1 > > > _______________________________________________ > Autotest mailing list > [email protected] > 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 [email protected] http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
