From f090bd45732fcfa6aa736570a2cebe2cdc0f4c52 Mon Sep 17 00:00:00 2001 From: Yingshun Cui Date: Tue, 4 Jul 2023 16:18:15 +0800 Subject: [PATCH] sriov: Add a checkpoint to check ping latency This PR adds a 2 vfs hostdev interfaces to check ping latency. Signed-off-by: Yingshun Cui --- .../sriov_vm_lifecycle_reboot.cfg | 2 + .../vm_lifecycle/sriov_vm_lifecycle_reboot.py | 40 +++++++++++++++++-- provider/sriov/check_points.py | 2 + 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/libvirt/tests/cfg/sriov/vm_lifecycle/sriov_vm_lifecycle_reboot.cfg b/libvirt/tests/cfg/sriov/vm_lifecycle/sriov_vm_lifecycle_reboot.cfg index e5bbeebd2f..320a461cd2 100644 --- a/libvirt/tests/cfg/sriov/vm_lifecycle/sriov_vm_lifecycle_reboot.cfg +++ b/libvirt/tests/cfg/sriov/vm_lifecycle/sriov_vm_lifecycle_reboot.cfg @@ -19,6 +19,8 @@ variants test_scenario: - managed_yes: iface_dict = {'managed': 'yes', 'type_name': 'hostdev', 'hostdev_address': {'type_name': 'pci', 'attrs': vf_pci_addr}, 'driver': {'driver_attr': {'name': 'vfio'}}, 'alias': {'name': 'ua-89cbe690-6c6c-4f2f-adac-5826fe52ea74'}, 'mac_address': mac_addr} + iface_dict2 = {'managed': 'yes', 'type_name': 'hostdev', 'hostdev_address': {'type_name': 'pci', 'attrs': vf_pci_addr2}, 'driver': {'driver_attr': {'name': 'vfio'}}} + check_ping_time = "yes" - managed_no: iface_dict = {'managed': 'no', 'type_name': 'hostdev', 'hostdev_address': {'type_name': 'pci', 'attrs': vf_pci_addr}, 'alias': {'name': 'ua-89cbe690-6c6c-4f2f-adac-5826fe52ea74'}} - without_managed: diff --git a/libvirt/tests/src/sriov/vm_lifecycle/sriov_vm_lifecycle_reboot.py b/libvirt/tests/src/sriov/vm_lifecycle/sriov_vm_lifecycle_reboot.py index 8fa0e30bad..4723c4cac2 100644 --- a/libvirt/tests/src/sriov/vm_lifecycle/sriov_vm_lifecycle_reboot.py +++ b/libvirt/tests/src/sriov/vm_lifecycle/sriov_vm_lifecycle_reboot.py @@ -1,3 +1,5 @@ +import re + from provider.sriov import check_points from provider.sriov import sriov_base @@ -7,6 +9,21 @@ from virttest.utils_test import libvirt +def get_avg_ping_time(vm_session, params): + """ + Get the average time of ping command + + :param vm_session: VM session + :param params: Test parameters + :return: The average response time + """ + ping_count = int(params.get("ping_count", '10')) + ping_time = check_points.check_vm_network_accessed( + vm_session, ping_count=ping_count, ping_timeout=30) + return int(re.findall( + "10 packets.*time (\d+)", ping_time)[0]) / ping_count + + def run(test, params, env): """ Reboot vm with a hostdev interface/device @@ -26,12 +43,20 @@ def run_test(): iface_dev = sriov_test_obj.create_iface_dev(dev_type, iface_dict) vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name) libvirt.add_vm_device(vmxml, iface_dev) + if params.get("iface_dict2"): + vf_pci_addr2 = sriov_test_obj.vf_pci_addr2 + iface_dict2 = eval(params.get("iface_dict2")) + iface_dev2 = sriov_test_obj.create_iface_dev(dev_type, iface_dict2) + libvirt.add_vm_device( + vm_xml.VMXML.new_from_dumpxml(vm_name), iface_dev2) test.log.info("TEST_STEP2: Start the VM") vm.start() vm.cleanup_serial_console() vm.create_serial_console() - vm.wait_for_serial_login(timeout=240).close() + vm_session = vm.wait_for_serial_login(timeout=240) + if params.get("check_ping_time") == "yes": + avg_ping_time = get_avg_ping_time(vm_session, params) test.log.info("TEST_STEP3: Reboot the vm") virsh.reboot(vm.name, debug=True, ignore_status=False) @@ -44,9 +69,16 @@ def run_test(): br_name = None if test_scenario == 'failover': br_name = br_dict['source'].get('bridge') - check_points.check_vm_network_accessed(vm_session, - tcpdump_iface=br_name, - tcpdump_status_error=True) + if params.get("check_ping_time") == "yes": + avg_ping_time2 = get_avg_ping_time(vm_session, params) + test.log.debug(f"ping before reboot: {avg_ping_time}," + f"ping after reboot: {avg_ping_time2}") + if avg_ping_time >= avg_ping_time * 3: + test.fail("High latency after soft reboot!") + else: + check_points.check_vm_network_accessed(vm_session, + tcpdump_iface=br_name, + tcpdump_status_error=True) dev_type = params.get("dev_type", "") dev_source = params.get("dev_source", "") diff --git a/provider/sriov/check_points.py b/provider/sriov/check_points.py index f5895bbd2e..06231f64ae 100644 --- a/provider/sriov/check_points.py +++ b/provider/sriov/check_points.py @@ -137,6 +137,7 @@ def check_vm_network_accessed(vm_session, ping_count=3, ping_timeout=5, the string "ICMP echo request" :param ping_dest: Ping destination address :raise: test.fail when ping fails. + :return: Output of ping command """ if not ping_dest: ping_dest = sriov_base.get_ping_dest(vm_session) @@ -163,6 +164,7 @@ def check_vm_network_accessed(vm_session, ping_count=3, ping_timeout=5, exceptions.TestFail("Get incorrect tcpdump output: {}, it " "should include '{}'." .format(output, pat_str)) + return o def check_vm_iface_num(session, exp_num, timeout=10, first=0.0):