• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import logging
2from autotest_lib.client.common_lib import error
3from autotest_lib.client.virt.tests import file_transfer
4from autotest_lib.client.virt import virt_test_utils
5
6
7def run_set_link(test, params, env):
8    """
9    KVM guest link test:
10    1) Boot up guest with one nic
11    2) Ping guest from host
12    3) Disable guest link and ping guest from host
13    4) Re-enable guest link and ping guest from host
14    5) Do file transfer test
15
16    @param test: kvm test object
17    @param params: Dictionary with the test parameters
18    @param env: Dictionary with test environment.
19    """
20    vm = virt_test_utils.get_living_vm(env, params.get("main_vm"))
21    timeout = float(params.get("login_timeout", 360))
22    session = virt_test_utils.wait_for_login(vm, 0, timeout, 0, 2)
23
24    def set_link_test(linkid):
25        """
26        Issue set_link commands and test its function
27
28        @param linkid: id of netdev or devices to be tested
29        """
30        ip = vm.get_address(0)
31
32        vm.monitor.cmd("set_link %s down" % linkid)
33        s, o = virt_test_utils.ping(ip, count=10, timeout=20)
34        if virt_test_utils.get_loss_ratio(o) != 100:
35            raise error.TestFail("Still can ping the %s after down %s" %
36                                 (ip, linkid))
37
38        vm.monitor.cmd("set_link %s up" % linkid)
39        s, o = virt_test_utils.ping(ip, count=10, timeout=20)
40        # we use 100% here as the notification of link status changed may be
41        # delayed in guest driver
42        if virt_test_utils.get_loss_ratio(o) == 100:
43            raise error.TestFail("Packet loss during ping %s after up %s" %
44                                 (ip, linkid))
45
46    netdev_id = vm.netdev_id[0]
47    device_id = vm.get_peer(netdev_id)
48    logging.info("Issue set_link commands for netdevs")
49    set_link_test(netdev_id)
50    logging.info("Issue set_link commands for network devics")
51    set_link_test(device_id)
52
53    file_transfer.run_file_transfer(test, params, env)
54    session.close()
55