-
Notifications
You must be signed in to change notification settings - Fork 39
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
Fix Python 3.9 compatibility #2352
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
50b42c5
Add Python 3.9 to tox environments
lunkwill42 51ab6f4
Add Python 3.9 to GitHub workflow matrix
lunkwill42 ce4d615
Add Python 3.9 to CI test image
lunkwill42 185bb46
Upgrade to latest networkx
lunkwill42 d83a559
Fix broken usage of networkx.Graph API
lunkwill42 5233e0a
Update docker dev image to Debian Bullseye
lunkwill42 da17fef
Lock dev docker image to to older pip version
lunkwill42 18462ed
Use pip, not pip-sync for package installs
lunkwill42 9713ec2
Add debug helpers to docker dev image
lunkwill42 9da4798
Debug log SNMP agent proxy destruction
lunkwill42 ce5f290
Upgrade to Twisted 20
lunkwill42 8689b55
Add Custom epollreactor implementation
lunkwill42 0f22245
Use the new epollreactor2 in ipdevpolld
lunkwill42 3ae7940
Use new custom reactor for integration tests
lunkwill42 93cbfaa
Add notes on dependency changes for Python 3.9
lunkwill42 e358b30
Purposefully disable pylint violation
lunkwill42 7099ea7
Upgrade IPy to 1.01, which supports Python 3.9
lunkwill42 2a9bdca
Strip incorrect and obsolete escape sequence
lunkwill42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# | ||
# Copyright (C) 2022 Sikt | ||
# | ||
# This file is part of Network Administration Visualized (NAV). | ||
# | ||
# NAV is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU General Public License version 3 as published by | ||
# the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. You should have received a copy of the GNU General Public | ||
# License along with NAV. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
"""Custom epollreactor implementation for ipdevpoll. | ||
|
||
This reactor inherits Twisted's original epollrecator, but overrides the one | ||
part that seems incompatible with pynetsnmp, which is central to ipdevpoll. | ||
""" | ||
import errno | ||
import logging | ||
|
||
from twisted.internet import epollreactor | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class EPollReactor2(epollreactor.EPollReactor): | ||
"""A reactor that uses epoll(7), with modified handling of closed file | ||
descriptors | ||
""" | ||
|
||
def _remove(self, xer, primary, other, selectables, event, antievent): | ||
""" | ||
Private method for removing a descriptor from the event loop. | ||
|
||
It does the inverse job of _add, and also add a check in case of the fd | ||
has gone away. | ||
|
||
It overrides the inherited epollreactor functionality to ensure that file | ||
descriptors closed behind our back are ignored and properly removed from the | ||
reactor's internal data structures. This is needed mostly because pynetsnmp | ||
adds reactor readers for file descriptors that are managed by the NET-SNMP C | ||
library. There is no way for Python code close these file descriptors in a | ||
controlled way, wherein they are removed from the reactor first - the | ||
NET-SNMP library will close them "behind our backs", so to speak. | ||
|
||
Attempting to unregister a closed file descriptor from the epoll object will | ||
cause an OSError that the original implementation left the client to handle - | ||
but this also caused the internal data structures of the reactor to become | ||
inconsistent. | ||
""" | ||
try: | ||
super()._remove(xer, primary, other, selectables, event, antievent) | ||
except OSError as error: | ||
if error.errno == errno.EBADF: | ||
fd = xer.fileno() | ||
_logger.debug("removing/ignoring bad file descriptor %r", fd) | ||
if fd in primary: | ||
primary.remove(fd) | ||
else: | ||
raise | ||
|
||
|
||
def install(): | ||
""" | ||
Install the epoll() reactor. | ||
""" | ||
p = EPollReactor2() | ||
from twisted.internet.main import installReactor | ||
|
||
installReactor(p) | ||
|
||
|
||
__all__ = ["EPollReactor2", "install"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, pip-sync ensures that the versions in the reqs are locked in, but that is hardly needed in a Dockerfile since a new image needs to be built anyway if there are changes to dependencies.