Home | History | Annotate | Download | only in tests
      1 import logging
      2 from autotest_lib.client.common_lib import error
      3 from autotest_lib.client.virt import virt_test_utils
      4 
      5 
      6 def run_ping(test, params, env):
      7     """
      8     Ping the guest with different size of packets.
      9 
     10     Packet Loss Test:
     11     1) Ping the guest with different size/interval of packets.
     12 
     13     Stress Test:
     14     1) Flood ping the guest.
     15     2) Check if the network is still usable.
     16 
     17     @param test: KVM test object.
     18     @param params: Dictionary with the test parameters.
     19     @param env: Dictionary with test environment.
     20     """
     21     vm = env.get_vm(params["main_vm"])
     22     vm.verify_alive()
     23     session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360)))
     24 
     25     counts = params.get("ping_counts", 100)
     26     flood_minutes = float(params.get("flood_minutes", 10))
     27     nics = params.get("nics").split()
     28     strict_check = params.get("strict_check", "no") == "yes"
     29 
     30     packet_size = [0, 1, 4, 48, 512, 1440, 1500, 1505, 4054, 4055, 4096, 4192,
     31                    8878, 9000, 32767, 65507]
     32 
     33     try:
     34         for i, nic in enumerate(nics):
     35             ip = vm.get_address(i)
     36             if not ip:
     37                 logging.error("Could not get the ip of nic index %d: %s",
     38                               i, nic)
     39                 continue
     40 
     41             for size in packet_size:
     42                 logging.info("Ping with packet size %s", size)
     43                 status, output = virt_test_utils.ping(ip, 10,
     44                                                      packetsize=size,
     45                                                      timeout=20)
     46                 if strict_check:
     47                     ratio = virt_test_utils.get_loss_ratio(output)
     48                     if ratio != 0:
     49                         raise error.TestFail("Loss ratio is %s for packet size"
     50                                              " %s" % (ratio, size))
     51                 else:
     52                     if status != 0:
     53                         raise error.TestFail("Ping failed, status: %s,"
     54                                              " output: %s" % (status, output))
     55 
     56             logging.info("Flood ping test")
     57             virt_test_utils.ping(ip, None, flood=True, output_func=None,
     58                                 timeout=flood_minutes * 60)
     59 
     60             logging.info("Final ping test")
     61             status, output = virt_test_utils.ping(ip, counts,
     62                                                  timeout=float(counts) * 1.5)
     63             if strict_check:
     64                 ratio = virt_test_utils.get_loss_ratio(output)
     65                 if ratio != 0:
     66                     raise error.TestFail("Ping failed, status: %s,"
     67                                          " output: %s" % (status, output))
     68             else:
     69                 if status != 0:
     70                     raise error.TestFail("Ping returns non-zero value %s" %
     71                                          output)
     72     finally:
     73         session.close()
     74