On 03/19/2012 05:04 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 | 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 output:%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")
You had better to abstract a common function to return
related CPU/Memory information from virsh nodeinfo
instead of repeating run the following cmdline:
cmd = "virsh nodeinfo | grep 'XXXXXX' | awk '{print $N}'"
The physical host check is same as above:
cmd = "grep 'XXXX' /proc/XXXXX | awk '{print $N}'"
Others are fine for me.
Thanks,
Alex
> +
> + #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
> [email protected]
> http://test.kernel.org/cgi-bin/mailman/listinfo/autotest
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest