aruba / pyaoscx

Python modules for AOS-CX
Apache License 2.0
37 stars 25 forks source link

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

Open smirlach opened 1 year ago

smirlach commented 1 year ago

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. https://github.com/aruba/pyaoscx/blob/648cfc7f63938004e41a6222ebfd9aeb62f67501/pyaoscx/mac.py#L214

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: https://github.com/aruba/pyaoscx/blob/648cfc7f63938004e41a6222ebfd9aeb62f67501/pyaoscx/interface.py#L365-L382

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." https://github.com/aruba/pyaoscx/blob/648cfc7f63938004e41a6222ebfd9aeb62f67501/pyaoscx/api.py#L84-L101

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 commented 1 year ago

@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 commented 1 year ago

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

smirlach commented 1 year ago

@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: aruba-automation@hpe.com
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 commented 1 year ago

@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!