-
Notifications
You must be signed in to change notification settings - Fork 68
Closed
Labels
Description
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.