Skip to content

Commit

Permalink
retry when nics name not found
Browse files Browse the repository at this point in the history
  • Loading branch information
LiliDeng committed Nov 25, 2023
1 parent 7fb2f39 commit 84fd0fe
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions microsoft/testsuites/xdp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Licensed under the MIT license.

import re
from time import sleep
from typing import List, Pattern

from lisa import Logger, Node, SkippedException, UnsupportedDistroException
Expand Down Expand Up @@ -29,6 +30,7 @@
]
_huge_page_disks = {"/mnt/huge": "", "/mnt/huge1g": "pagesize=1G"}
_huge_page_disks_rhel_arm64 = {"/mnt/huge": "", "/mnt/huge512m": "pagesize=512M"}
_nic_not_found = re.compile(r"Couldn't get device .* statistics", re.M)


def get_xdpdump(node: Node) -> XdpDump:
Expand Down Expand Up @@ -163,9 +165,23 @@ def _aggregate_count(
# there may not have vf nic
if not nic_name:
continue
stats = ethtool.get_device_statistics(
interface=nic_name, force_run=True
).counters
attempts = 0
max_attempts = 4
while attempts < max_attempts:
try:
stats = ethtool.get_device_statistics(
interface=nic_name, force_run=True
).counters
break
except Exception as identifier:
if _nic_not_found.search(str(identifier)):
log.debug(f"nic {nic_name} not found, need to reload nics")
sleep(2)
node.nics.reload()
nic_name = node.nics.get_primary_nic().lower
attempts += 1
else:
raise identifier
# the name and pattern ordered by syn/vf
for pattern in patterns:
items = {key: value for key, value in stats.items() if pattern.match(key)}
Expand Down

0 comments on commit 84fd0fe

Please sign in to comment.