Skip to content

pyaoscx.mac.get_all not working when a VRRP is configured #24

@smirlach

Description

@smirlach

Hello,

i found an issue with getting the MAC addresses if a VRRP is configured and i would consider this as a bug. This is also used in other modules for example when getting a VLAN via VLAN.get(session,vlan_id).

When there is a VRRP configured for a VLAN the variable mac['port'] equals None.

mac_obj.port = Interface.from_response(session, mac["port"])

As far is i know this is right as there is no logical or physical Port assigned to the virtual MAC address of the VRRP. Still this is leading to an error, because later on api.py tries to access the items of mac['port'].

Before that the variable is handed over to interface.py as response_data:

def from_response(cls, session, response_data):
"""
Create an Interface object given a response_data related to the
Interface object.
:param cls: Object's class.
:param session: pyaoscx.Session object used to represent a logical
connection to the device.
:param response_data: The response must be a dictionary of the form:
{ "<interface_name>": URL }, with URL:
"/rest/v10.04/system/interfaces/<interface_name>"
:return: Interface object.
"""
interfaces_id_arr = session.api.get_keys(
response_data, Interface.resource_uri_name
)
interface_name = interfaces_id_arr[0]
return session.api.get_module(session, "Interface", interface_name)

After this response_data is handed over to api.py. Which finally tries to access the items of response_data which then leads to the Error "Ran into exception: 'NoneType' object has no attribute 'items'. Closing session."

pyaoscx/pyaoscx/api.py

Lines 84 to 101 in 648cfc7

def get_keys(self, response_data, module_name=None):
"""
Given a response_data obtain the indices of said dictionary and return
them. Get keys should be used for only one element in the
dictionary.
:param response_data: a dictionary object in the form of:
{
"idx_1,idx_2": "/rest/v10.0X/system/<module>/<idx_1>,<idx_2>",
}
:return indices: List of indices.
"""
indices = None
for k, v in response_data.items():
indices = k
indices = indices.split(",")
return indices

This happens because it is not checked at any point either if the current MAC address is a VRRP or if the port of the MAC address equals None. Those two points mentioned could also be a possible solution in my opinion which could be implemented via changing line 214 in mac.py to one of the following snippets:

Check if the port of the MAC address is None

if mac['port'] is not None:
    mac_obj.port = Interface.from_response(session, mac["port"])
else:
    mac_obj.port = None

Check if the given MAC address is configured via a VRRP

if 'vrrp' not in indices:
    mac_obj.port = Interface.from_response(session, mac["port"])
else:
    mac_obj.port = None

Those are just suggestions and i don't know if they are implemented in the right way to work for every usecase of pyaoscx.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions