pyroute2 icon indicating copy to clipboard operation
pyroute2 copied to clipboard

compat - object is not callable with ipdb_interfaces_view()

Open chateaulav opened this issue 1 year ago • 1 comments

Identified Problem

Identified underlying issues through use of the saltstack salt projects beacons utility.

beacon network_settings leverages pyroute2 for providing ability to monitor network interface related changes. This performs a direct import of:
from pyroute2.ndb.compat import ipdb_interfaces_view

However current version of https://github.com/svinota/pyroute2/blob/master/pyroute2/ndb/compat.py leverages older calls for select_records related ipdb that do not function correctly causing tracebacks related to:

TypeError: 'NoneType' object is not iterable

Reference for saltstack related module:
https://github.com/saltstack/salt/blob/master/salt/beacons/network_settings.py

Ubuntu 22.04
Python3.10

pyroute2 == 0.7.9
pyroute2.ndb == 0.6.13

Proposed Resolution

To avoid potential backport issues related to module, adding try/except statements can ensure that proper handling occurs if using ndb.

        try:
            interface['ipaddr'] = tuple(
                (
                    (x.address, x.prefixlen)
                    for x in (
                        ndb.addresses.dump().select_records(index=record.index)
                    )
                )
            )
        except:
            with ndb.addresses.summary() as report:
                report.select_records(ifname=f"{record.ifname}")
                interface['ipaddr'] = tuple(
                    ((x.address, x.prefixlen) for x in report)
                )
        try:
            interface['ports'] = tuple(
                (
                    x.index
                    for x in (
                        ndb.interfaces.dump().select_records(master=record.index)
                    )
                )
            )
        except:
            with ndb.interfaces.dump() as report:
                report.select_records(ifname=f"{record.ifname}")
                interface['ports'] = tuple(
                    (x.index for x in report)
                )
        try:
            interface['neighbours'] = tuple(
                (
                    x.dst
                    for x in (
                        ndb.neighbours.dump().select_records(ifindex=record.index)
                    )
                )
            )
        except:
            with ndb.neighbours.dump() as report:
                report.select_records(ifindex=record.index)
                interface['neighbours'] = tuple(
                    (x.dst for x in report)
                )

chateaulav avatar Oct 06 '23 14:10 chateaulav

associated pull request
https://github.com/svinota/pyroute2/pull/1133

chateaulav avatar Oct 25 '23 11:10 chateaulav