提交 8b70ea29 编写于 作者: W wyu

ping.py:add ping interval for linux guest and add ping_ext_host test

improve ping from host to guest, add ping exceed/flood for guest to host,add windows support for multi_nics and fix some bugs in this patch.
Signed-off-by: NYu Wang <wyu@redhat.com>
上级 700b76e0
- ping: install setup image_copy unattended_install.cdrom - ping: install setup image_copy unattended_install.cdrom
virt_test_type = qemu libvirt virt_test_type = qemu libvirt
type = ping type = ping
counts = 100 ping_counts = 30
flood_minutes = 10 flood_minutes = 10
Linux: Linux:
packet_size = "0 1 4 48 64 512 1440 1500 1505 4054 4055 4096 4192 8878 9000 32767 65507" packet_size = "0 1 4 48 64 512 1440 1500 1505 4054 4055 4096 4192 8878 9000 32767 65507"
interval_time = "0.1 0.01 0.001 0.0001"
Windows: Windows:
packet_size = "0 1 4 48 64 512 1440 1500 1505 4054 4055 4096 4192 8878 9000 32767 65500" packet_size = "0 1 4 48 64 512 1440 1500 1505 4054 4055 4096 4192 8878 9000 32767 65500"
variants: variants:
- default_ping: - default_ping:
- multi_nics: - multi_nics:
no Windows
nics += ' nic2' nics += ' nic2'
pre_cmd = "for nic in `ls /sys/class/net|grep -v lo`;do arp -a|grep -v $nic && dhclient $nic;done" Linux:
pre_cmd = "for nic in `ls /sys/class/net|grep -v lo`;do arp -a|grep -v $nic && dhclient $nic;done"
- ext_host: - ext_host:
ping_ext_host = "yes" ping_ext_host = "yes"
ext_host_get_cmd = "ip route | awk '/default/ { print $3 }'" ext_host_get_cmd = "ip route | awk '/default/ { print $3 }'"
ext_host = "www.redhat.com"
...@@ -5,129 +5,119 @@ from autotest.client import utils ...@@ -5,129 +5,119 @@ from autotest.client import utils
from virttest import utils_test from virttest import utils_test
from virttest import utils_net from virttest import utils_net
from virttest import error_context
@error.context_aware
def _ping_with_params(test, params, dest, interface=None,
packet_size=None, interval=None,
count=0, session=None, flood=False):
if flood:
cmd = "ping " + dest + " -f -q"
if interface:
cmd += " -S %s" % interface
flood_minutes = float(params.get("flood_minutes", 10))
status, output = utils_net.raw_ping(cmd, flood_minutes * 60,
session, logging.debug)
else:
timeout = float(count) * 1.5
status, output = utils_net.ping(dest, count, interval, interface,
packet_size, session=session,
timeout=timeout)
if status != 0:
test.fail("Ping failed, status: %s,"
" output: %s" % (status, output))
if params.get("strict_check", "no") == "yes":
ratio = utils_test.get_loss_ratio(output)
if ratio != 0:
test.fail("Loss ratio is %s" % ratio)
@error_context.context_aware
def run(test, params, env): def run(test, params, env):
""" """
Ping the guest with different size of packets. Ping the guest with different size of packets.
1) Login to guest 1) Login to guest
2) Ping test on nic(s) from host 2) Ping test on nic(s) from host - default_ping/multi_nics
2.1) Ping with packet size from 0 to 65507 2.1) Ping with packet size from 0 to 65507
2.2) Flood ping test 2.2) Flood ping test
2.3) Ping test after flood ping, Check if the network is still alive 2.3) Ping test after flood ping, Check if the network is still alive
3) Ping test from guest side, packet size is from 0 to 65507 3) Ping test from guest side to external host - ext_host
(win guest is up to 65500) (Optional) 3.1) Ping with packet size from 0 to 65507 (win guest is up to 65500)
3.2) Flood ping test
3.3) Ping test after flood ping, Check if the network is still alive
:param test: QEMU test object. :param test: QEMU test object.
:param params: Dictionary with the test parameters. :param params: Dictionary with the test parameters.
:param env: Dictionary with test environment. :param env: Dictionary with test environment.
""" """
def _get_loss_ratio(output): counts = params.get("ping_counts", 30)
if params.get("strict_check", "no") == "yes": packet_sizes = params.get("packet_size", "").split()
ratio = utils_test.get_loss_ratio(output) interval_times = params.get("interval_time", "1").split()
if ratio != 0:
raise error.TestFail("Loss ratio is %s" % ratio)
timeout = int(params.get("login_timeout", 360)) timeout = int(params.get("login_timeout", 360))
ping_ext_host = params.get("ping_ext_host", "no") == "yes" ping_ext_host = params.get("ping_ext_host", "no") == "yes"
pre_cmd = params.get("pre_cmd", None)
vm = env.get_vm(params["main_vm"]) vm = env.get_vm(params["main_vm"])
error_context.context("Login to guest", logging.info)
vm.verify_alive() vm.verify_alive()
error.context("Login to guest", logging.info)
session = vm.wait_for_login(timeout=timeout) session = vm.wait_for_login(timeout=timeout)
# most of linux distribution don't add IP configuration for extra nics, # get the test ip, interface & session
# so get IP for extra nics via pre_cmd; dest_ips = []
if params.get("pre_cmd"): sessions = []
session.cmd(params["pre_cmd"], timeout=600) interfaces = []
if ping_ext_host: if ping_ext_host:
default_host = "www.redhat.com" ext_host = params.get("ext_host", "")
ext_host_get_cmd = params.get("ext_host_get_cmd", "") ext_host_get_cmd = params.get("ext_host_get_cmd", "")
try: try:
ext_host = utils.system_output(ext_host_get_cmd) ext_host = utils.system_output(ext_host_get_cmd)
except error.CmdError: except error.CmdError:
logging.warn("Can't get specified host with cmd '%s'," logging.warn("Can't get specified host with cmd '%s',"
" Fallback to default host '%s'", " Fallback to default host '%s'",
ext_host_get_cmd, default_host) ext_host_get_cmd, ext_host)
ext_host = default_host dest_ips = [ext_host]
sessions = [session]
if not ext_host: interfaces = [None]
# Fallback to a hardcode host, eg: else:
ext_host = default_host # most of linux distribution don't add IP configuration for extra nics,
# so get IP for extra nics via pre_cmd;
counts = params.get("ping_counts", 100) if pre_cmd:
flood_minutes = float(params.get("flood_minutes", 10)) session.cmd(pre_cmd, timeout=600)
for i, nic in enumerate(vm.virtnet):
packet_sizes = params.get("packet_size", "").split() ip = vm.get_address(i)
if ip.upper().startswith("FE80"):
for i, nic in enumerate(vm.virtnet): interface = utils_net.get_neigh_attch_interface(ip)
ip = vm.get_address(i) else:
if ip.upper().startswith("FE80"): interface = None
interface = utils_net.get_neigh_attch_interface(ip) nic_name = nic.get("nic_name")
else: if not ip:
interface = None test.fail("Could not get the ip of nic index %d: %s",
nic_name = nic.get("nic_name")
if not ip:
logging.error("Could not get the ip of nic index %d: %s",
i, nic_name) i, nic_name)
continue dest_ips.append(ip)
sessions.append(None)
error.base_context("Ping test on nic %s (index %d) from host" interfaces.append(interface)
" side" % (nic_name, i), logging.info)
for size in packet_sizes:
error.context("Ping with packet size %s" % size, logging.info)
status, output = utils_test.ping(ip, 10, packetsize=size,
interface=interface, timeout=20)
_get_loss_ratio(output)
if status != 0:
raise error.TestFail("Ping failed, status: %s,"
" output: %s" % (status, output))
error.context("Flood ping test", logging.info)
utils_test.ping(ip, None, flood=True, output_func=None,
interface=interface, timeout=flood_minutes * 60)
error.context("Ping test after flood ping, Check if the network is" for (ip, interface, session) in zip(dest_ips, interfaces, sessions):
" still alive", logging.info) error_context.context("Ping test with dest: %s" % ip, logging.info)
status, output = utils_test.ping(ip, counts, interface=interface,
timeout=float(counts) * 1.5)
_get_loss_ratio(output)
if status != 0: # ping with different size & interval
raise error.TestFail("Ping returns non-zero value %s" % output) for size in packet_sizes:
for interval in interval_times:
if ping_ext_host: logging.info("Ping with packet size: %s and interval: %s" %
error.base_context("Ping test from guest side," (size, interval))
" dest: '%s'" % ext_host, logging.info) _ping_with_params(test, params, ip, interface, size,
pkt_sizes = packet_sizes interval, session=session, count=counts)
# There is no ping program for guest, so let's hardcode...
cmd = ['ping'] # ping with flood
cmd.append(ext_host) # external host if not ping_ext_host or params.get("os_type") == "linux":
error_context.context("Flood ping test", logging.info)
if params.get("os_type") == "windows": _ping_with_params(test, params, ip, interface,
cmd.append("-n 10") session=session, flood=True)
cmd.append("-l %s")
# Windows doesn't support ping with packet # ping to check whether the network is alive
# larger than '65500' error_context.context("Ping test after flood ping,"
pkt_sizes = [p for p in packet_sizes if p < 65500] " Check if the network is still alive",
# Add a packet size just equal '65500' for windows logging.info)
pkt_sizes.append(65500) _ping_with_params(test, params, ip, interface,
else: session=session, count=counts)
cmd.append("-c 10") # ping 10 times
cmd.append("-s %s") # packet size
cmd = " ".join(cmd)
for size in pkt_sizes:
error.context("Ping with packet size %s" % size,
logging.info)
status, output = session.cmd_status_output(cmd % size,
timeout=60)
_get_loss_ratio(output)
if status != 0:
raise error.TestFail(("Ping external host failed,"
" status: %s, output: %s" %
(status, output)))
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册