提交 ff401c14 编写于 作者: X Xu Han 提交者: GitHub

Merge pull request #975 from xiywang/net_dev_already_in_use

nic_hotplug: add a new case for hot plug a netdev with the id already in use
......@@ -54,3 +54,8 @@
type = nic_hotplug
nics = ""
extra_params += "-net none"
- used_netdev:
used_sameid = yes
nic_hotplug_count = 1
type = nic_hotplug
devadd_match_string = "it's in use"
import logging
import random
from autotest.client.shared import error
from autotest.client.shared import utils
from virttest import utils_test
......@@ -10,7 +9,6 @@ from virttest import virt_vm
from virttest import utils_misc
@error.context_aware
def run(test, params, env):
"""
Test hotplug of NIC devices
......@@ -20,7 +18,8 @@ def run(test, params, env):
check if they are added
3) Add multi nic devices through monitor cmd and check if they are added
4) Check if new interface gets ip address
5) Disable primary link of guest
5) Disable primary link of guest, if test hot-plug nic with the netdev
already used, then no need to disable it, hot-plug the device directly.
6) Ping guest new ip from host
7) Delete nic device and netdev if user config "do_random_unhotplug"
8) Ping guest's new ip address after guest pause/resume
......@@ -63,7 +62,7 @@ def run(test, params, env):
vm.virtnet) if _nic == nic][0]
return vm.wait_for_get_address(index, timeout=90)
except IndexError:
raise error.TestError(
test.error(
"Nic '%s' not exists in VM '%s'" %
(nic["nic_name"], vm.name))
except (virt_vm.VMIPAddressMissingError,
......@@ -77,8 +76,8 @@ def run(test, params, env):
cached_ip = vm.address_cache.get(nic["mac"])
arps = utils.system_output("arp -aen")
logging.debug("Can't get IP address:")
logging.debug("\tCached IP: %s" % cached_ip)
logging.debug("\tARP table: %s" % arps)
logging.debug("\tCached IP: %s", cached_ip)
logging.debug("\tARP table: %s", arps)
return None
def ping_hotplug_nic(ip, mac, session, is_linux_guest):
......@@ -97,6 +96,19 @@ def run(test, params, env):
status, output = session.cmd_output_safe(del_route_cmd)
return status, output
def device_add_nic(pci_model, netdev, device_id):
"""
call device_add command, with param device_id, driver and netdev
:param pci_model: drivers for virtual device
:param netdev: netdev id for virtual device
:param device_id: device id for virtual device
"""
pci_add_cmd = "device_add id=%s, driver=%s, netdev=%s" % (device_id,
pci_model,
netdev)
add_output = vm.monitor.send_args_cmd(pci_add_cmd)
return add_output
login_timeout = int(params.get("login_timeout", 360))
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
......@@ -122,40 +134,55 @@ def run(test, params, env):
nic_model = nic_params["pci_model"]
nic_params["nic_model"] = nic_model
nic_params["nic_name"] = nic_name
error.context("Disable other link(s) of guest", logging.info)
disable_nic_list = primary_nic + nic_hotplugged
for nic in disable_nic_list:
if guest_is_linux:
ifname = utils_net.get_linux_ifname(s_session, nic["mac"])
s_session.cmd_output_safe("ifconfig %s 0.0.0.0" % ifname)
used_sameid = params.get("used_sameid")
if used_sameid == "yes":
useddevice_id = primary_nic[0].netdev_id
logging.info("Hot-plug NIC with the netdev already in use")
try:
add_output = device_add_nic(nic_model, useddevice_id, nic_name)
except Exception, err_msg:
match_error = params["devadd_match_string"]
if match_error in str(err_msg):
s_session.close()
return
else:
test.fail("Hot-plug error message is not as expected: "
"%s" % str(err_msg))
else:
s_session.cmd_output_safe("ipconfig /release all")
vm.set_link(nic.device_id, up=False)
error.context("Hotplug %sth '%s' nic named '%s'" % (nic_index,
nic_model,
nic_name))
test.fail("Qemu should failed hot-plugging nic with error")
else:
logging.info("Disable other link(s) of guest")
disable_nic_list = primary_nic + nic_hotplugged
for nic in disable_nic_list:
if guest_is_linux:
ifname = utils_net.get_linux_ifname(s_session, nic["mac"])
s_session.cmd_output_safe("ifconfig %s 0.0.0.0" % ifname)
else:
s_session.cmd_output_safe("ipconfig /release all")
vm.set_link(nic.device_id, up=False)
logging.debug("Hotplug %sth '%s' nic named '%s'",
nic_index, nic_model, nic_name)
hotplug_nic = vm.hotplug_nic(**nic_params)
error.context("Check if new interface gets ip address",
logging.info)
logging.info("Check if new interface gets ip address")
hotnic_ip = get_hotplug_nic_ip(
vm,
hotplug_nic,
s_session,
guest_is_linux)
if not hotnic_ip:
raise error.TestFail("Hotplug nic can get ip address")
test.fail("Hotplug nic can not get ip address")
logging.info("Got the ip address of new nic: %s", hotnic_ip)
error.context("Ping guest's new ip from host", logging.info)
logging.info("Ping guest's new ip from host")
status, output = ping_hotplug_nic(host_ip_addr, hotplug_nic["mac"],
s_session, guest_is_linux)
if status:
err_msg = "New nic failed ping test, error info: '%s'"
raise error.TestFail(err_msg % output)
test.fail(err_msg % output)
error.context("Reboot vm after hotplug nic", logging.info)
logging.info("Reboot vm after hotplug nic")
# reboot vm via serial port since some guest can't auto up
# hotplug nic and next step will check is hotplug nic works.
s_session = vm.reboot(session=s_session, serial=True)
......@@ -166,35 +193,32 @@ def run(test, params, env):
s_session,
guest_is_linux)
if not hotnic_ip:
raise error.TestFail(
test.fail(
"Hotplug nic can't get ip after reboot vm")
error.context("Ping guest's new ip from host", logging.info)
logging.info("Ping guest's new ip from host")
status, output = ping_hotplug_nic(host_ip_addr, hotplug_nic["mac"],
s_session, guest_is_linux)
if status:
err_msg = "New nic failed ping test, error info: '%s'"
raise error.TestFail(err_msg % output)
error.context("Pause vm", logging.info)
vm.monitor.cmd("stop")
vm.verify_status("paused")
error.context("Resume vm", logging.info)
vm.monitor.cmd("cont")
vm.verify_status("running")
error.context("Ping guest's new ip after resume", logging.info)
test.fail(err_msg % output)
logging.info("Pause vm")
vm.pause()
logging.info("Resume vm")
vm.resume()
logging.info("Ping guest's new ip after resume")
status, output = ping_hotplug_nic(host_ip_addr, hotplug_nic["mac"],
s_session, guest_is_linux)
if status:
err_msg = "New nic failed ping test after stop/cont, "
err_msg += "error info: '%s'" % output
raise error.TestFail(err_msg)
test.fail(err_msg)
# random hotunplug nic
nic_hotplugged.append(hotplug_nic)
if random.randint(0, 1) and params.get("do_random_unhotplug"):
error.context("Detaching the previously attached nic from vm",
logging.info)
logging.info("Detaching the previously attached nic from vm")
unplug_nic_index = random.randint(0, len(nic_hotplugged) - 1)
vm.hotunplug_nic(nic_hotplugged[unplug_nic_index].nic_name)
nic_hotplugged.pop(unplug_nic_index)
......@@ -204,11 +228,10 @@ def run(test, params, env):
finally:
for nic in nic_hotplugged:
vm.hotunplug_nic(nic.nic_name)
error.context("Re-enabling the primary link(s)", logging.info)
logging.info("Re-enabling the primary link(s)")
for nic in primary_nic:
vm.set_link(nic.device_id, up=True)
error.context("Reboot vm to verify it alive after hotunplug nic(s)",
logging.info)
logging.info("Reboot vm to verify it alive after hotunplug nic(s)")
serial = len(vm.virtnet) > 0 and False or True
session = vm.reboot(serial=serial)
vm.verify_alive()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册