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

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-04-19 00:27:44 +05:30 committed by GitHub
parent 2b3b85bac8
commit 60f9602095
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) index = port_util.get_index_from_str(ifname)
if op == 'SET' and index is None: if op == 'SET' and index is None:
return 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: if op == 'SET' and ifindex is None:
return return