On 03/19/2012 06:04 AM, 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
Hi Gu, after reviewing the nodeinfo tests, here are some comments: * A bunch of the information you wanted to query from the system are already available as autotest API. * A lot of shell script here could be turned into python and that would not make the test less understandable, on the contrary IMHO. * As Alex has pointed out, the places where we have grepping on the virsh nodeinfo output can be turned out into a utility function so the code can made shorter and easier to understand. * The functions to query things from the system could be turned into a python implementation and moved to the common autotest library client/bin/base_utils.py I've started to work on some of the points I mentioned, but did not implement the whole idea, please check a modified version of your test here: https://github.com/lmr/autotest/commit/6efce520710a6cedb57ffb3dd2a50218773a1e04 Would you please see the changes made and re-send the patch? Just remember that you can download that commit as a patch simply doing something like: curl https://github.com/lmr/autotest/commit/6efce520710a6cedb57ffb3dd2a50218773a1e04.patch | git am Thanks! > Signed-off-by: Gu Yanhua<guyanhua-f...@cn.fujitsu.com> > --- > client/tests/libvirt/tests/virsh_nodeinfo.py | 126 > ++++++++++++++++++++++++++ > 1 files changed, 126 insertions(+), 0 deletions(-) > create mode 100644 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 100644 > index 0000000..d433329 > --- /dev/null > +++ b/client/tests/libvirt/tests/virsh_nodeinfo.py > @@ -0,0 +1,126 @@ > +import logging, re > +from autotest_lib.client.common_lib import utils, error > +from autotest_lib.client.virt import libvirt_vm > + > +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 virsh_nodeinfo(option): > + cmd = "virsh nodeinfo %s" % option > + cmd_result = utils.run(cmd, ignore_status=True) > + logging.info("Output: %s", cmd_result.stdout.strip()) > + logging.error("Error: %s", cmd_result.stderr.strip()) > + logging.info("Status: %d", cmd_result.exit_status) > + return cmd_result.exit_status, cmd_result.stdout.strip() > + > + def output_check(): > + #check the CPU model > + cmd = "virsh nodeinfo | grep 'CPU model' | awk '{print $3}'" > + cmd_result_test = utils.run(cmd, ignore_status=True) > + logging.info("CPU model of virsh nodeinfo output:%s",\ > + cmd_result_test.stdout.strip()) > + cmd = "uname -m" > + cmd_result = utils.run(cmd, ignore_status=True) > + if not re.match(cmd_result_test.stdout.strip(),\ > + cmd_result.stdout.strip()): > + raise error.TestFail("virsh nodeinfo output invalid;\ > + didn't match CPU model") > + > + > + #check CPU(s) > + cmd = "virsh nodeinfo | grep 'CPU(s)' | awk '{print $2}'" > + cmd_result_test = utils.run(cmd, ignore_status=True) > + logging.info("CPU(s) of virsh nodeinfo output:%s",\ > + cmd_result_test.stdout.strip()) > + cmd = "grep processor /proc/cpuinfo | wc -l" > + cmd_result = utils.run(cmd, ignore_status=True) > + if not re.match(cmd_result_test.stdout.strip(), \ > + cmd_result.stdout.strip()): > + raise error.TestFail("virsh nodeinfo output invalid;\ > + didn't match CPU(s)") > + > + #check CPU frequency > + cmd = "virsh nodeinfo | grep 'CPU frequency' | awk '{print $3}'" > + cmd_result_test = utils.run(cmd, ignore_status=True) > + logging.info("CPU frequency of virsh nodeinfo output:%s",\ > + cmd_result_test.stdout.strip()) > + cmd = "cat /proc/cpuinfo | grep 'cpu MHz' | head -n1| awk '{print > $4}'|\ > + awk -F. '{print $1}'" > + cmd_result = utils.run(cmd, ignore_status=True) > + if not re.match(cmd_result_test.stdout.strip(),\ > + cmd_result.stdout.strip()): > + raise error.TestFail("virsh nodeinfo output invalid; \ > + didn't match CPU frequency") > + > + #check CPU socket(s) > + cmd = "virsh nodeinfo | grep 'CPU socket(s)' | awk '{print $3}'" > + cmd_result_test = utils.run(cmd, ignore_status=True) > + logging.info("CPU socket(s) of virsh nodeinfo ouimport logging, re from autotest_lib.client.common_lib import utils, error from autotest_lib.client.virt import libvirt_vm 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 'CPU model' | awk '{print $%s}'" % column cmd_result = utils.run(cmd, ignore_status=True) stdout = cmd_result.stdout.strip() logging.debug("Info %s on nodeinfo output:%s", stdout) return stdout def virsh_nodeinfo(option): cmd = "virsh nodeinfo %s" % option cmd_result = utils.run(cmd, ignore_status=True) logging.info("Output: %s", cmd_result.stdout.strip()) logging.error("Error: %s", cmd_result.stderr.strip()) logging.info("Status: %d", cmd_result.exit_status) return cmd_result.exit_status, cmd_result.stdout.strip() def output_check(): # Check CPU model cpu_model_nodeinfo = _check_nodeinfo('CPU model', 3) cpu_model_os = 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 = 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 = _check_nodeinfo('CPU socket(s)', 3) cmd = "grep 'physical id' /proc/cpuinfo | uniq | wc -l" cmd_result = utils.run(cmd, ignore_status=True) cpu_sockets_os = cmd_result.stdout.strip() if not re.match(cpu_sockets_nodeinfo, cpu_sockets_os): 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 = 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 = 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)tput:%s",\ > + cmd_result_test.stdout.strip()) > + cmd = "grep 'physical id' /proc/cpuinfo | uniq | wc -l" > + cmd_result = utils.run(cmd, ignore_status=True) > + if not re.match(cmd_result_test.stdout.strip(), \ > + cmd_result.stdout.strip()): > + raise error.TestFail("virsh nodeinfo output invalid; \ > + didn't match CPU socket(s)") > + > + #check Core(s) per socket > + cmd = "virsh nodeinfo | grep 'Core(s) per socket' | awk '{print $4}'" > + cmd_result_test = utils.run(cmd, ignore_status=True) > + logging.info("Core(s) per socket of virsh nodeinfo output:%s", \ > + cmd_result_test.stdout.strip()) > + cmd = "grep 'cpu cores' /proc/cpuinfo | head -n1 | awk '{print $4}'" > + cmd_result = utils.run(cmd, ignore_status=True) > + if not re.match(cmd_result_test.stdout.strip(), \ > + cmd_result.stdout.strip()): > + raise error.TestFail("virsh nodeinfo output invalid; \ > + didn't match Core(s) per socket") > + > + #check Memory size > + cmd = "virsh nodeinfo | grep 'Memory size' | awk '{print $3}'" > + cmd_result_test = utils.run(cmd, ignore_status=True) > + logging.info("Memory size of virsh nodeinfo output:%s", \ > + cmd_result_test.stdout.strip()) > + cmd = "grep 'MemTotal' /proc/meminfo | awk '{print $2}'" > + cmd_result = utils.run(cmd, ignore_status=True) > + if not re.match(cmd_result_test.stdout.strip(), \ > + cmd_result.stdout.strip()): > + raise error.TestFail("virsh nodeinfo output invalid; \ > + 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 = 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 Autotest@test.kernel.org http://test.kernel.org/cgi-bin/mailman/listinfo/autotest