Skip to content

Commit

Permalink
sriov: Add a checkpoint to check ping latency
Browse files Browse the repository at this point in the history
This PR adds a 2 vfs hostdev interfaces to check ping latency.

Signed-off-by: Yingshun Cui <[email protected]>
  • Loading branch information
Yingshun committed Jul 4, 2023
1 parent 94fd119 commit f090bd4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
40 changes: 36 additions & 4 deletions libvirt/tests/src/sriov/vm_lifecycle/sriov_vm_lifecycle_reboot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

from provider.sriov import check_points
from provider.sriov import sriov_base

Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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", "")
Expand Down
2 changes: 2 additions & 0 deletions provider/sriov/check_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down

0 comments on commit f090bd4

Please sign in to comment.