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

pyroute2 import fails if kernel local version does not start with a dash #885

Closed
fabi125 opened this issue Feb 25, 2022 · 8 comments
Closed

Comments

@fabi125
Copy link

fabi125 commented Feb 25, 2022

12a1aa8 changed how the kernel version gets parsed which seems to be a lot less lenient when it comes to parsing the version string.

trying to import pyroute2 0.6.7 on a host that is running a kernel with a version like 5.15.15.debug causes an exception:

$ uname -r
5.15.15.debug
$ pip show pyroute2
Name: pyroute2
Version: 0.6.7
Summary: Python Netlink library
Home-page: https://github.com/svinota/pyroute2
Author: 
Author-email: 
License: dual license GPLv2+ and Apache v2
Location: /home/fabi/pyroute2-env/lib/python3.8/site-packages
Requires: pyroute2.core, pyroute2.ethtool, pyroute2.ipdb, pyroute2.ipset, pyroute2.ndb, pyroute2.nftables, pyroute2.nslink
Required-by: 
$ python -c 'import pyroute2'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/fabi/pyroute2-env/lib/python3.8/site-packages/pyroute2/__init__.py", line 14, in <module>
    from pr2modules.config.version import __version__
  File "/home/fabi/pyroute2-env/lib/python3.8/site-packages/pr2modules/config/__init__.py", line 25, in <module>
    kernel = [int(x) for x in uname[2].split('-')[0].split('.')]
  File "/home/fabi/pyroute2-env/lib/python3.8/site-packages/pr2modules/config/__init__.py", line 25, in <listcomp>
    kernel = [int(x) for x in uname[2].split('-')[0].split('.')]
ValueError: invalid literal for int() with base 10: 'debug'

Other people seem to run into the issues as well. e.g. https://bugs.launchpad.net/neutron/+bug/1961906

@svinota svinota added the bug label Feb 25, 2022
@svinota
Copy link
Owner

svinota commented Feb 25, 2022

Oh. To be fixed tonight, thanks

svinota added a commit that referenced this issue Feb 26, 2022
@svinota
Copy link
Owner

svinota commented Feb 26, 2022

Please check if it will work for you.

Thank you again for the feedback.

@fabi125
Copy link
Author

fabi125 commented Feb 26, 2022

Awesome! Thanks for the super quick fix. Looks like this is working for me now:

In [2]: import pyroute2

In [3]: import pr2modules.config

In [4]: pr2modules.config.kernel
Out[4]: [5, 15, 15]

@svinota
Copy link
Owner

svinota commented Feb 26, 2022

NB: it's better to use pyroute2 imports like

from pyroute2 import config

Instead of pr2modules — since pyroute2 imports are public and never change the signature, while pr2modules are internal and may change unpredictably.

@svinota
Copy link
Owner

svinota commented Feb 26, 2022

(Maybe it's better to publish the public API list on one page)

@fabi125
Copy link
Author

fabi125 commented Feb 26, 2022

Ah yes, that's what I normally do. Just directly imported the file you changed. This works as expected as well:

In [1]: from pyroute2 import config

In [2]: config.kernel
Out[2]: [5, 15, 15]

@fabi125
Copy link
Author

fabi125 commented Mar 8, 2022

Any chance you could cut a new release with this change? Thanks!

@svinota
Copy link
Owner

svinota commented Mar 8, 2022

Sure thing. Expect it on Saturday.

hougaardj referenced this issue in pritunl/pritunl Mar 21, 2022
@svinota svinota added the fixed label Apr 17, 2022
@svinota svinota closed this as completed Apr 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants