Skip to content

Commit

Permalink
Merge pull request #466 from tiiuae/mdm_agent_fix_iproute_getlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
TIISR authored Jul 11, 2024
2 parents 3d1667a + 3cb7a10 commit 5a7ef3f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import ipaddress
import errno
from pyroute2 import IPRoute, NetlinkError, arp # type: ignore[import-not-found, import-untyped]
from pyroute2.netlink.exceptions import NetlinkDumpInterrupted

from src import cbma_paths
from src.comms_controller import CommsController
Expand Down Expand Up @@ -280,7 +281,16 @@ def __delete_vlan_interfaces(self) -> bool:
def __get_interfaces(self) -> None:
interfaces = []
ip = IPRoute()
for link in ip.get_links():

ip_links = []
while True:
try:
ip_links = ip.get_links()
break
except NetlinkDumpInterrupted:
time.sleep(1)

for link in ip_links:
ifname = link.get_attr("IFLA_IFNAME")
ifstate = link.get_attr("IFLA_OPERSTATE")
mac_address = link.get_attr("IFLA_ADDRESS")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
# pylint: disable=too-few-public-methods, too-many-nested-blocks
from typing import Callable, List, Dict
import subprocess
import time
from copy import deepcopy
from pyroute2 import IPRoute
from pyroute2.netlink.exceptions import NetlinkDumpInterrupted

DUMMY_INTERFACE_NAME = 'ifdummy0'

Expand All @@ -24,7 +26,15 @@ def __init__(self, callback: Callable[[List[Dict]], None]) -> None:
self.__ipr = IPRoute()

def __get_initial_interfaces(self):
for link in self.__ipr.get_links():
ip_links = []
while True:
try:
ip_links = self.__ipr.get_links()
break
except NetlinkDumpInterrupted:
time.sleep(1)

for link in ip_links:
interface_info = self.__get_interface_info(link)
if interface_info:
self.__interfaces.append(interface_info)
Expand Down

0 comments on commit 5a7ef3f

Please sign in to comment.