[sflow] Exception handling for if_nametoindex (#11437) (#14457)

catch system error and log as warning level instead of
     error level in case interface was already deleted

Signed-off-by: Gokulnath-Raja <Gokulnath_R@dell.com>
This commit is contained in:
Gokulnath-Raja 2023-05-06 04:41:12 +05:30 committed by GitHub
parent a29d982aa5
commit eb99648a4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -45,7 +45,15 @@ class PortIndexMapper(object):
index = port_util.get_index_from_str(ifname)
if op == 'SET' and index is None:
return
ifindex = if_nametoindex(ifname)
# catch system error and log as warning level instead of
# error level in case interface was already deleted
ifindex = None
try:
ifindex = if_nametoindex(ifname)
except OSError as e:
logger.log_warning("%s" % str(e))
if op == 'SET' and ifindex is None:
return