From b39f88e2e02fe814ea6fa27a8fe2cb041eb2159e Mon Sep 17 00:00:00 2001 From: Yu Wang Date: Tue, 8 May 2018 10:29:30 +0800 Subject: [PATCH] set_link: fix problem of packets lost during ping on windows guest Add ip check for windows guest and extend the timeout. Signed-off-by: Yu Wang --- qemu/tests/cfg/set_link.cfg | 2 +- qemu/tests/set_link.py | 39 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/qemu/tests/cfg/set_link.cfg b/qemu/tests/cfg/set_link.cfg index f6c3ce9d..f29b33a5 100644 --- a/qemu/tests/cfg/set_link.cfg +++ b/qemu/tests/cfg/set_link.cfg @@ -1,7 +1,7 @@ - set_link: install setup image_copy unattended_install.cdrom requires_root = yes type = set_link - test_timeout = 2000 + test_timeout = 2500 filesize = 4000 transfer_timeout = 1000 kill_vm =yes diff --git a/qemu/tests/set_link.py b/qemu/tests/set_link.py index 8a733528..b4b846c5 100644 --- a/qemu/tests/set_link.py +++ b/qemu/tests/set_link.py @@ -140,6 +140,43 @@ def run(test, params, env): finally: session.close() + def check_interface_ip_routine(session, mac_addr): + """ + The routine to check the ip of interface. + + :param session: a session to send check commands + :param mac_addr: the interface mac address + """ + ip_addr = utils_net.get_net_if_addrs_win(session, mac_addr) + guest_ipv4 = ip_addr["ipv4"] + for ip in guest_ipv4: + logging.debug("Check address: %s" % ip) + if len(ip) != 0 and not ip.startswith("169.254"): + return True + return False + + def check_interface_ip(timeout=600): + """ + Check whether the vm has got the available ip address. + + The check will be performed repeatedly until a correct ip address + is detected or after the specified time is expired. + + :param timeout: total checking time allowed + """ + error_context.context("Start checking guest ip", logging.info) + session = vm.wait_for_serial_login() + mac_addr = vm.get_mac_address() + try: + if not utils_misc.wait_for( + lambda: check_interface_ip_routine(session, mac_addr), + timeout, + step=5.0): + err_msg = "Can't get valid ip in %s seconds" % timeout + test.fail(err_msg) + finally: + session.close() + def set_link_test(linkid, link_up, expect_status, operstate_always_up=False, change_queues=False): """ @@ -165,6 +202,8 @@ def run(test, params, env): expect_status = win_media_connected guest_interface_operstate_check(expect_status, guest_ifname, change_queues) + if params.get("os_type") == "windows": + check_interface_ip() error_context.context("Check if guest network connective", logging.info) -- GitLab