提交 fce9226a 编写于 作者: X Xiyue Wang

expose_host_mtu: add test case of expose host mtu to guest

Signed-off-by: NXiyue Wang <xiywang@redhat.com>
上级 27c77793
- expose_host_mtu: install setup image_copy unattended_install.cdrom
no RHEL.6 RHEL.5 RHEL.4 RHEL.3
no Windows
requires_root = yes
type = expose_host_mtu
kill_vm = yes
only virtio_net
start_vm = no
mtu_value = 4000
nic_extra_params = ",host_mtu=${mtu_value}"
nm_stop_cmd = systemctl stop NetworkManager
check_guest_mtu_cmd = "ifconfig %s"
set_guest_mtu_cmd = "ifconfig %s mtu ${mtu_value}"
bridge_get_if_cmd = "bridge link show | awk '{print $2}'"
Windows:
# TBD, will support later
check_guest_mtu_cmd = "netsh interface ipv4 show subinterface "%s""
import logging
import re
from avocado.utils import process
from virttest import error_context
from virttest import utils_net
from virttest import utils_test
from virttest import env_process
@error_context.context_aware
def run(test, params, env):
"""
Expose host MTU to guest test
1) Boot up guest with param 'host_mtu=4000' in nic part
2) Disable NetworkManager in guest
3) set mtu of guest tap (eg: tap0) and physical nic (eg: eno1) to
4000 in host
4) check the mtu in guest
5) ping from guest to external host with packet size 3972
:param test: kvm test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment
"""
def get_ovs_ports(ovs):
"""
Get ovs ports
:param ovs: ovs bridge name
"""
cmd = "ovs-vsctl list-ports %s" % ovs
return process.system_output(cmd, shell=True).decode()
def is_ovs_backend(netdst):
"""
Check whether the host is OVS backend
:param netdst: netdst get from command line
"""
return netdst in process.system_output("ovs-vsctl list-br",
ignore_status=True,
shell=True).decode()
def cleanup_ovs_ports(netdst, ports):
"""
Clean up created ovs ports in this case
:param netdst: netdst get from command line
:param ports: existing ports need to be remain before this test
"""
if is_ovs_backend(netdst) is True:
ports = set(get_ovs_ports(netdst).splitlines()) - \
set(ports.splitlines())
for p in ports:
process.system("ovs-vsctl del-port %s %s" % (netdst, p))
netdst = params.get("netdst", "switch")
if netdst in utils_net.Bridge().list_br():
cmd = params["bridge_get_if_cmd"]
host_hw_interface = process.system_output(
cmd, shell=True).decode().strip(':')
elif is_ovs_backend(netdst) is True:
host_hw_interface = get_ovs_ports(netdst)
tmp_ports = re.findall(r"t[0-9]-[a-zA-Z0-9]{6}", host_hw_interface)
if tmp_ports:
for p in tmp_ports:
process.system_output("ovs-vsctl del-port %s %s" %
(netdst, p))
host_hw_interface = get_ovs_ports(netdst)
else:
test.cancel("The host is using Macvtap backend, which is not"
" supported by now!")
params["start_vm"] = "yes"
env_process.preprocess_vm(test, params, env, params["main_vm"])
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
device_mac = vm.virtnet[0].mac
vm_iface = vm.get_ifname()
# TODO, will support windows later
process.system_output(params["nm_stop_cmd"])
process.system_output(params["set_guest_mtu_cmd"] % host_hw_interface)
process.system_output(params["set_guest_mtu_cmd"] % vm_iface)
os_type = params.get("os_type", "linux")
login_timeout = float(params.get("login_timeout", 360))
session = vm.wait_for_login(timeout=login_timeout)
host_ip = utils_net.get_ip_address_by_interface(params["netdst"])
if os_type == "linux": # TODO, will support windows later
session.cmd_output_safe(params["nm_stop_cmd"])
guest_ifname = utils_net.get_linux_ifname(session,
vm.get_mac_address())
output = session.cmd_output_safe(
params["check_guest_mtu_cmd"] % guest_ifname)
error_context.context(output, logging.info)
match_string = "mtu %s" % params["mtu_value"]
if match_string in output:
logging.info("Host mtu %s exposed to guest as expected!" %
params["mtu_value"])
logging.info("Ping from guest to host with packet size 3972")
status, output = utils_test.ping(host_ip, 10, packetsize=3972,
timeout=30, session=session)
ratio = utils_test.get_loss_ratio(output)
if ratio != 0:
test.fail("Loss ratio is %s", ratio)
else:
test.fail("host mtu %s not exposed to guest" % params["mtu_value"])
cleanup_ovs_ports(netdst, host_hw_interface)
session.close()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册