Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
smirlach opened this issue Jul 5, 2023 · 4 comments
Open

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

smirlach opened this issue Jul 5, 2023 · 4 comments
Assignees

Comments

@smirlach
Copy link

smirlach commented Jul 5, 2023

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.

@tchiapuziowong
Copy link
Member

@smirlach thank you for bringing this to our attention! I'll bring this up with the team and they'll work on reproducing the issue and looking into a resolution! I'll update this issue when an expected fix is to be posted!

@tchiapuziowong
Copy link
Member

@smirlach Can you share the CLI configuration you're using to produce this issue?

@smirlach
Copy link
Author

@tchiapuziowong I'm using Python 3.9.6and

❯ pip show pyaoscx
Name: pyaoscx
Version: 2.4.1
Summary: AOS-CX Python Modules
Home-page: https://github.com/aruba/pyaoscx
Author: Aruba Automation
Author-email: [email protected]
License: Apache 2.0
Location: /Users/<user>/.pyenv/versions/3.9.6/lib/python3.9/site-packages
Requires: netaddr, PyYAML, requests, requests-toolbelt, wheel
Required-by: 

Do you need anything else specifically?

@tchiapuziowong
Copy link
Member

tchiapuziowong commented Jul 11, 2023

@smirlach apologies the switch CLI configuration, the interface and/or VLAN config that's producing this error for you
just saw you updated issue here with the config - thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants