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

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

Closed
icmtf opened this issue Aug 17, 2021 · 1 comment
Closed

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

icmtf opened this issue Aug 17, 2021 · 1 comment
Labels

Comments

@icmtf
Copy link

icmtf commented Aug 17, 2021

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.

@ldn-softdev
Copy link
Contributor

Hi, this it seems to be an overlook:

        ... The IP MTU value is
        expected to always be present in the provided config block

- if that's the case, then system tests also should be upgraded to catch this situation. I'll mark this issue as a bug (so that I could track it for the next version) and will include the fix in the next version. Thanks for reporting it.

dlyssenko added a commit that referenced this issue Oct 7, 2022
fix for issue #210 - getall() fails in ipinterfaces module
dlyssenko added a commit that referenced this issue Jun 6, 2023
* Try importing ujson and rapidjson before json

ujson and rapidjson are libraries that are
faster to encode and decode JSON objects

* Implement configure_session() to send "configure session", diff() for "show session-config diff", commit() for "commit", and abort() for "abort"

* Bump version

* Fix issue #186, fix typo in client.py

* Amend tests for #186

* Amend remove vlan to vni mapping CLI

* Add config session documentation

* Add config session documentation

* Remove config session doc from wrong dir

* adding streaming option for commands

* Correct typo "mutlicast"

* Adding Power support(ppc64le)with continuous integration/testing to the project for architecture independent

* Inorrect import from 'collections' will stop working in Python 3.9

Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
Solving

* Fix python2 dependancy on collections

* Bump Python version to 3.9 for CI

* Fix #189 #190 #195

* Bump version to rc

* fixed issue #198

* #197 - updated vlans.getall() to handle vlan grouppings

* updated vlans.get() to return range/list of vlan ids (instead of input regex), plus updated relevant unit tests

* fixed import warning in abstract module

* updated documentation to avoid using localhost for off-box connections

* Refactor deprecated unittest aliases for Python 3.11 compatibility.

* Update configfile.rst

* fix for the issue #213

* Ignore subinterfaces on switchports.getall()

Signed-off-by: DavidVentura <[email protected]>

* Stop on whitespace

* extended config for unit testing issue #213

* Add a test

* Add new value from #213

* merge tests

* address perf issues on section splitting

* fix bad test

* Add option to not include defaults with node.running_config

Currently, the Node(conn).running_config always includes config defaults, this is not always wanted.
For example if you want to compare the running_config to the startup_config, it is easier to not have defaults included in the running_config.

With this option you can do something like this;
```
In [3]: conn = client.connect(**params)

In [4]: node = client.Node(conn, config_defaults=False)

In [5]: node.running_config.splitlines()[3:] == node.startup_config.splitlines()[4:]
Out[5]: True
```

* updated client descritpion to reflect issue #222

* mitor fix in the description for reST markdown

* another minor update for client.connect description

* Add support for passwords that cannot be used to login

* added sphinx_rtd_theme to dev-requrements.txt

* docs: fixing #231

* fixing collection.Iterables in test_utils.py for py3.10

* fixing collection.Iterables in test_utils.py for py3.10 - minor improvement

* fix for issue #234 - allow passing ssl context to pyeapi

* minor markdown fix in client module description

* fix passwd exposure in traceback issue

* fixed issue where sphinx failed to generate API modules doc, plus made it python3 ready

* readying pyeapi for github actions + minor style fixes

* Migrate from Travis CI to GitHub workflows

* extended python-version list for CI with 2.7 and 3.10

* removed password from showing in debugs

* added pep8 E128 to ignore list - to adopt to Arista coding style

* fixed my update to accomodate to unit tests and possibly invalid jsons

* minor typo fixes in comments

* one more minor typo fix in comments

* Update ci.yml

self approving - trivial change

* Update test_client.py

self-approved - this is non-functional, only syntactic change to keep flake8 happy

* Update eapilib.py

self-approving: non-functional, only syntactic changes to keep flake8 happier.

* Update ci.yml

adding flake8 upgrade, as it crashes in some python versions

* fix for issue #210 - getall() fails in ipinterfaces module

* fix for issue #193 - flood list for vxlan in interfaces returns wrong data

* enhanced `section` to match subsections and removed py2.7 from CI

* minor syntax change to keep flake8 happy

* added a doc string and dressed up the function, no functional change

* few more space adjustments to please flake8

* Store and pass credentials as header tuple

* Support session-based authorization

Create a Session API mixin for Http and Https connection methods that
uses the /login endpoint to store a Cookie for all future connections.
This is useful when using centralized AAA to reduce the load of repeated
command calls.

Note that the cookie does have a lifetime, and that the connection will
stop working once the cookie lifetime expires, unless the authentication
method is manually called again

* provisioning for providing CLI variants to handle deprecated cli transitions

* moved cli varinats functionality to clint.py module so that users could use it too

* fixed issue raising the exception properly for the last failed command

* fixed again raising the exception properly for the last failed command

* updated documentation

* space adjustment in the docstring

* provided comments on enforce_verification param deprecation

* removed python 3.5 and 3.6 from the workflows - unsupported

* fix issue #161 - add parsing of secondary ip from interfaces

* making flake8 happy

* Include error message in CommandError for commands that cause internal exceptions

* _parse_bgp_as regex to match as and asdot

* Checking if asn is asdot or not, and return string if asdot and int if not

* typo

* testing dumb shit

* dumby dumb dumb

* dafuq am i doing

* maybe just maybe

* i hate this shit i just wanna do neworking again :(

* lemme be a network engineer again please i wanna die

* play stupid games win stupid prices

* var typo

* testing

* testing suggested changes

* intendation error

* Update ipinterfaces.py

Replace IP MTU magic numbers with constants and provide references to RFCs

* Update ipinterfaces.py

* fixing doc build issues, errors, and providing docstring interpolation decorator

* fixing indents

* moved decorator's descriptin into the doc string

* removed deprecated spanningtree module

* removed all outdated python version checks

* minor improvement for docstr decorator

* Removed reference to python2 (#262)

* Removed reference to python2

* Removed support for lower versions of python

* Updated EOS version to the minimum supported

* Addressed formatting and error handling comments

* Refactored extra python2 check

* removed couple deprecations

* removed one more deprecation

* Created release-notes-1.0.0.rst

* Updated release-notes.rst

* Update VERSION

* Update __init__.py

* Update release-notes-1.0.0.rst

fixed a capital letter.

---------

Signed-off-by: DavidVentura <[email protected]>
Co-authored-by: Xavier Hardy <[email protected]>
Co-authored-by: Shintaro Kojima <[email protected]>
Co-authored-by: andriirr <[email protected]>
Co-authored-by: Andrii Rykhlivskyi <[email protected]>
Co-authored-by: mharista <[email protected]>
Co-authored-by: Bharath Ravindranath <[email protected]>
Co-authored-by: Will Hargrave <[email protected]>
Co-authored-by: Ubuntu <[email protected]>
Co-authored-by: Petr Klíma <[email protected]>
Co-authored-by: Dmitry Lyssenko <[email protected]>
Co-authored-by: Dmitry Lyssenko <[email protected]>
Co-authored-by: Karthikeyan Singaravelan <[email protected]>
Co-authored-by: DavidVentura <[email protected]>
Co-authored-by: erikl <[email protected]>
Co-authored-by: Jeremiah Millay <[email protected]>
Co-authored-by: steve ulrich <[email protected]>
Co-authored-by: Alarig Le Lay <[email protected]>
Co-authored-by: Stefano Rivera <[email protected]>
Co-authored-by: Brandon Ewing <[email protected]>
Co-authored-by: Dylan Kaplan <[email protected]>
Co-authored-by: bh-rr <[email protected]>
Co-authored-by: Greg Skinner <[email protected]>
Co-authored-by: chieto-arista <[email protected]>
dlyssenko added a commit that referenced this issue Jun 6, 2023
* Try importing ujson and rapidjson before json

ujson and rapidjson are libraries that are
faster to encode and decode JSON objects

* Implement configure_session() to send "configure session", diff() for "show session-config diff", commit() for "commit", and abort() for "abort"

* Bump version

* Fix issue #186, fix typo in client.py

* Amend tests for #186

* Amend remove vlan to vni mapping CLI

* Add config session documentation

* Add config session documentation

* Remove config session doc from wrong dir

* adding streaming option for commands

* Correct typo "mutlicast"

* Adding Power support(ppc64le)with continuous integration/testing to the project for architecture independent

* Inorrect import from 'collections' will stop working in Python 3.9

Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
Solving

* Fix python2 dependancy on collections

* Bump Python version to 3.9 for CI

* Fix #189 #190 #195

* Bump version to rc

* fixed issue #198

* #197 - updated vlans.getall() to handle vlan grouppings

* updated vlans.get() to return range/list of vlan ids (instead of input regex), plus updated relevant unit tests

* fixed import warning in abstract module

* updated documentation to avoid using localhost for off-box connections

* Refactor deprecated unittest aliases for Python 3.11 compatibility.

* Update configfile.rst

* fix for the issue #213

* Ignore subinterfaces on switchports.getall()



* Stop on whitespace

* extended config for unit testing issue #213

* Add a test

* Add new value from #213

* merge tests

* address perf issues on section splitting

* fix bad test

* Add option to not include defaults with node.running_config

Currently, the Node(conn).running_config always includes config defaults, this is not always wanted.
For example if you want to compare the running_config to the startup_config, it is easier to not have defaults included in the running_config.

With this option you can do something like this;
```
In [3]: conn = client.connect(**params)

In [4]: node = client.Node(conn, config_defaults=False)

In [5]: node.running_config.splitlines()[3:] == node.startup_config.splitlines()[4:]
Out[5]: True
```

* updated client descritpion to reflect issue #222

* mitor fix in the description for reST markdown

* another minor update for client.connect description

* Add support for passwords that cannot be used to login

* added sphinx_rtd_theme to dev-requrements.txt

* docs: fixing #231

* fixing collection.Iterables in test_utils.py for py3.10

* fixing collection.Iterables in test_utils.py for py3.10 - minor improvement

* fix for issue #234 - allow passing ssl context to pyeapi

* minor markdown fix in client module description

* fix passwd exposure in traceback issue

* fixed issue where sphinx failed to generate API modules doc, plus made it python3 ready

* readying pyeapi for github actions + minor style fixes

* Migrate from Travis CI to GitHub workflows

* extended python-version list for CI with 2.7 and 3.10

* removed password from showing in debugs

* added pep8 E128 to ignore list - to adopt to Arista coding style

* fixed my update to accomodate to unit tests and possibly invalid jsons

* minor typo fixes in comments

* one more minor typo fix in comments

* Update ci.yml

self approving - trivial change

* Update test_client.py

self-approved - this is non-functional, only syntactic change to keep flake8 happy

* Update eapilib.py

self-approving: non-functional, only syntactic changes to keep flake8 happier.

* Update ci.yml

adding flake8 upgrade, as it crashes in some python versions

* fix for issue #210 - getall() fails in ipinterfaces module

* fix for issue #193 - flood list for vxlan in interfaces returns wrong data

* enhanced `section` to match subsections and removed py2.7 from CI

* minor syntax change to keep flake8 happy

* added a doc string and dressed up the function, no functional change

* few more space adjustments to please flake8

* Store and pass credentials as header tuple

* Support session-based authorization

Create a Session API mixin for Http and Https connection methods that
uses the /login endpoint to store a Cookie for all future connections.
This is useful when using centralized AAA to reduce the load of repeated
command calls.

Note that the cookie does have a lifetime, and that the connection will
stop working once the cookie lifetime expires, unless the authentication
method is manually called again

* provisioning for providing CLI variants to handle deprecated cli transitions

* moved cli varinats functionality to clint.py module so that users could use it too

* fixed issue raising the exception properly for the last failed command

* fixed again raising the exception properly for the last failed command

* updated documentation

* space adjustment in the docstring

* provided comments on enforce_verification param deprecation

* removed python 3.5 and 3.6 from the workflows - unsupported

* fix issue #161 - add parsing of secondary ip from interfaces

* making flake8 happy

* Include error message in CommandError for commands that cause internal exceptions

* _parse_bgp_as regex to match as and asdot

* Checking if asn is asdot or not, and return string if asdot and int if not

* typo

* testing dumb shit

* dumby dumb dumb

* dafuq am i doing

* maybe just maybe

* i hate this shit i just wanna do neworking again :(

* lemme be a network engineer again please i wanna die

* play stupid games win stupid prices

* var typo

* testing

* testing suggested changes

* intendation error

* Update ipinterfaces.py

Replace IP MTU magic numbers with constants and provide references to RFCs

* Update ipinterfaces.py

* fixing doc build issues, errors, and providing docstring interpolation decorator

* fixing indents

* moved decorator's descriptin into the doc string

* removed deprecated spanningtree module

* removed all outdated python version checks

* minor improvement for docstr decorator

* Removed reference to python2 (#262)

* Removed reference to python2

* Removed support for lower versions of python

* Updated EOS version to the minimum supported

* Addressed formatting and error handling comments

* Refactored extra python2 check

* removed couple deprecations

* removed one more deprecation

* Created release-notes-1.0.0.rst

* Updated release-notes.rst

* Update VERSION

* Update __init__.py

* Update release-notes-1.0.0.rst

fixed a capital letter.

---------

Signed-off-by: DavidVentura <[email protected]>
Co-authored-by: Xavier Hardy <[email protected]>
Co-authored-by: Shintaro Kojima <[email protected]>
Co-authored-by: andriirr <[email protected]>
Co-authored-by: Andrii Rykhlivskyi <[email protected]>
Co-authored-by: mharista <[email protected]>
Co-authored-by: Bharath Ravindranath <[email protected]>
Co-authored-by: Will Hargrave <[email protected]>
Co-authored-by: Ubuntu <[email protected]>
Co-authored-by: Petr Klíma <[email protected]>
Co-authored-by: Dmitry Lyssenko <[email protected]>
Co-authored-by: Dmitry Lyssenko <[email protected]>
Co-authored-by: Karthikeyan Singaravelan <[email protected]>
Co-authored-by: DavidVentura <[email protected]>
Co-authored-by: erikl <[email protected]>
Co-authored-by: Jeremiah Millay <[email protected]>
Co-authored-by: steve ulrich <[email protected]>
Co-authored-by: Alarig Le Lay <[email protected]>
Co-authored-by: Stefano Rivera <[email protected]>
Co-authored-by: Brandon Ewing <[email protected]>
Co-authored-by: Dylan Kaplan <[email protected]>
Co-authored-by: bh-rr <[email protected]>
Co-authored-by: Greg Skinner <[email protected]>
Co-authored-by: chieto-arista <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants