提交 b042c823 编写于 作者: Y Yu Wang

mac_change: Get correct mac when boot with multi-queue

get one mac is enough for the same device_id
Signed-off-by: NYu Wang <wyu@redhat.com>
上级 61df9071
import re
import logging
from autotest.client.shared import error
from virttest import error_context
from virttest import utils_misc
from virttest import utils_net
from virttest import utils_test
def check_guest_mac(mac, vm, device_id=None):
error.context("Check mac address via monitor", logging.info)
network_info = vm.monitor.info("network")
@error_context.context_aware
def check_guest_mac(test, mac, vm, device_id=None):
"""
check mac address of guest via qmp.
:param test: test object
:param mac: mac address of guest
:param vm: target vm
:param device_id: id of network pci device
"""
error_context.context("Check mac address via monitor", logging.info)
network_info = str(vm.monitor.info("network"))
if not device_id:
device_id = vm.virtnet[0].device_id
if device_id not in str(network_info):
err = "Could not find device '%s' from query-network monitor command."
err += "query-network command output: %s" % str(network_info)
raise error.TestFail(err)
for info in str(network_info).splitlines():
if re.match(device_id, info.strip(), re.I) and mac not in info:
err = "Cold not get correct mac from qmp command!"
err += "query-network command output: %s" % str(network_info)
raise error.TestFail(err)
if device_id not in network_info:
err = "Could not find device '%s' from query-network monitor command.\n"
err += "query-network command output: %s" % network_info
test.error(err)
if not re.search(("%s.*%s" % (device_id, mac)), network_info, re.M | re.I):
err = "Could not get correct mac from qmp command!\n"
err += "query-network command output: %s" % network_info
test.fail(err)
@error.context_aware
@error_context.context_aware
def run(test, params, env):
"""
Change MAC address of guest.
......@@ -60,7 +67,7 @@ def run(test, params, env):
os_variant = params.get("os_variant")
change_cmd_pattern = params.get("change_cmd")
logging.info("The initial MAC address is %s", old_mac)
check_guest_mac(old_mac, vm)
check_guest_mac(test, old_mac, vm)
if os_type == "linux":
interface = utils_net.get_linux_ifname(session_serial, old_mac)
if params.get("shutdown_int", "yes") == "yes":
......@@ -87,7 +94,7 @@ def run(test, params, env):
session.cmd(copy_cmd)
# Start change MAC address
error.context("Changing MAC address to %s" % new_mac, logging.info)
error_context.context("Changing MAC address to %s" % new_mac, logging.info)
if os_type == "linux":
change_cmd = change_cmd_pattern % (interface, new_mac)
else:
......@@ -97,8 +104,8 @@ def run(test, params, env):
session_serial.cmd_output_safe(change_cmd)
# Verify whether MAC address was changed to the new one
error.context("Verify the new mac address, and restart the network",
logging.info)
error_context.context("Verify the new mac address, and restart the network",
logging.info)
if os_type == "linux":
if params.get("shutdown_int", "yes") == "yes":
int_activate_cmd = params.get("int_activate_cmd",
......@@ -119,7 +126,7 @@ def run(test, params, env):
o = session_serial.cmd_output_safe("ipconfig /all")
if not re.findall("%s" % "-".join(new_mac.split(":")), o, re.I):
raise error.TestFail("Guest mac change failed")
test.fail("Guest mac change failed")
logging.info("Guest mac have been modified successfully")
if params.get("nettype") != "macvtap":
......@@ -132,13 +139,13 @@ def run(test, params, env):
session.close()
# Re-log into guest and check if session is responsive
error.context("Re-log into the guest", logging.info)
error_context.context("Re-log into the guest")
session = vm.wait_for_login(timeout=timeout)
if not session.is_responsive():
raise error.TestFail("The new session is not responsive.")
test.error("The new session is not responsive.")
if params.get("reboot_vm_after_mac_changed") == "yes":
error.context("Reboot guest and check the the mac address by "
"monitor", logging.info)
error_context.context("Reboot guest and check the the mac address by "
"monitor", logging.info)
mac_check = new_mac
if os_type == "linux":
nic = vm.virtnet[0]
......@@ -147,13 +154,13 @@ def run(test, params, env):
mac_check = old_mac
session_serial = vm.reboot(session_serial, serial=True)
check_guest_mac(mac_check, vm)
check_guest_mac(test, mac_check, vm)
if params.get("file_transfer", "no") == "yes":
error.context("File transfer between host and guest.",
logging.info)
error_context.context("File transfer between host and guest.",
logging.info)
utils_test.run_file_transfer(test, params, env)
else:
check_guest_mac(new_mac, vm)
check_guest_mac(test, new_mac, vm)
finally:
if os_type == "windows":
clean_cmd_pattern = params.get("clean_cmd")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册