Skip to content

node.api('ipinterfaces').getall() crashes when MTU is not set #210

@icmtf

Description

@icmtf

Module Ipinterfaces crashes when parsing interfaces then MTU is not set

print(node.api('ipinterfaces').getall())

Throws this:

File "/home/me/arista/.venv/lib64/python3.6/site-packages/pyeapi/api/ipinterfaces.py", line 120, in _parse_mtu
   return dict(mtu=int(match.group(1)))
AttributeError: 'NoneType' object has no attribute 'group'

The method responsible for that is:

    def _parse_mtu(self, config):
        """Parses the config block and returns the configured IP MTU value

        The provided configuration block is scanned and the configured value
        for the IP MTU is returned as a dict object.  The IP MTU value is
        expected to always be present in the provided config block

        Args:
            config (str): The interface configuration block to parse

        Return:
            dict: A dict object intended to be merged into the resource dict
        """
        match = re.search(r'mtu (\d+)', config)
        return dict(mtu=int(match.group(1)))

Temporary fix:

Easy to fix by adding if-else statement similar to _parse_address() (lines 103, 104) in .venv/site-packages/pyeapi/api/ipinterfaces.py

Like this:

    def _parse_mtu(self, config):
        """Parses the config block and returns the configured IP MTU value

        The provided configuration block is scanned and the configured value
        for the IP MTU is returned as a dict object.  The IP MTU value is
        expected to always be present in the provided config block

        Args:
            config (str): The interface configuration block to parse

        Return:
            dict: A dict object intended to be merged into the resource dict
        """
        match = re.search(r'mtu (\d+)', config)
        value = int(match.group(1)) if match else None
        return dict(mtu=value)

When modified it runs like a charm:

{
    'defaults': {'name': 'defaults', 'address': None, 'mtu': None},
    'Ethernet1': {'name': 'Ethernet1', 'address': None, 'mtu': 1500},
    ...
    'Ethernet52': {'name': 'Ethernet52', 'address': None, 'mtu': 1500},
    'Management': {'name': 'Management', 'address': '10.10.10.10/24', 'mtu': 1500},
    'Vlan500': {'name': 'Vlan500', 'address': '10.10.10.20/24', 'mtu': 1500}
}

Please include this tiny fix in next release.

EDIT: Yes, I know that MTU should be included in every interface configuration however it shouldn't be forced.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions