-
-
Notifications
You must be signed in to change notification settings - Fork 362
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
Socketify pynut #2792
Socketify pynut #2792
Conversation
Sounds great, thanks! For FSD, you can extend the testing setup in tests/NIT/nit.sh (called as The stack runs on dedicated random ports, can use custom SHUTDOWNCMD, and not running as root, so it won't actually shut down the computer. It does also call the python and C++ client tests. With FSD I think the Python client would be essentially another upsmon by role, so might need using that login? I'm at a conference now so can't think more deeply on that. To develop tests, see NIT_CASE envvar and |
I tried that testing setup but couldn't get it to work. Is this DCO thing mandatory? I really don't want to add my private email. |
I guess it's okay then. |
From CI failures, it seems the solution's syntax is for Python 3. Can you please rewrite it so the module would work on both new systems and those stuck with 2.7 or so?
Per https://stackoverflow.com/a/73333155/4715872 seems this would just need to dumb down the code a little, and write two lines instead of one (assign and check condition separately). UPDATE: Hm, inside a loop that might be a bit more difficult. Probably pre-assign the var to |
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.
Looks generally solid, thanks! Kudos for finding the extra bugs (e.g. timeout ignorance) ;)
Now we need to brush it up a bit, so tests would also pass for older systems stuck with Python 2.x, as commented earlier, and update some other recipe and doc files as noted in review comments.
@@ -110,18 +105,31 @@ timeout : Timeout used to wait for network response | |||
self.__port = port | |||
self.__login = login | |||
self.__password = password | |||
self.__timeout = 5 | |||
self.__timeout = timeout |
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.
Oopsie :D
if "true" == os.getenv('DEBUG', 'false'): | ||
print( "[DEBUG] Fall back to private copy of telnetlib for PyNUTClient\n" ) | ||
import nut_telnetlib as telnetlib | ||
import socket |
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.
Probably makes sense to add to the changelog above, that a "better solution" did get developed. And in NEWS.adoc
too.
Eventually also drop nut_telnetlib
from Git, Makefile.am
, setup.py
...
I gather that socket
is available in core of both 2.x and 3.x Pythons, right?
Ah yea I forgot the walrus operator was only added in 3.8. I've gotten a bit addicted to it and use it automatically without thinking now 😆.
For the changelog I was thinking this:
I'm not sure how to update NEWS.adoc though. What section would it go in? Would it overwrite the older one?
Oh yea absolutely, socket is ancient, it's been there since at least v1.4 in 1996. Maybe even pre 1.0, though not sure. |
Thanks! The changelog proposal looks right. For NEWS.adoc, see one of the topmost section with (planned) changes between 2.8.2 and 2.8.3. There could be an entry about providing nut_telnetlib - if it was after 2.8.2 already, can be replaced :) |
Just love to see how far a bit of know-how can go! :) |
✅ Build nut 2.8.2.2710-master completed (commit f874be659c by @cgarz) |
Ah yea I see it now. Reading it I'm actually thinking it might be good as is. |
Might be, not online now to check more. |
Ah no probs, appending would make it:
That look good? |
In NEWS, PR/issue numbers can be comma-separated. |
Thanks that does look nicer. Switched to: Should I commit those now? Or is there anything else to update? |
I guess, any mentions of |
Yes it shows:
Should I remove/change these and |
Yes please, if you have a moment to perfect the PR :) |
Handles choosing IPv4 and IPv6 automatically.
remove nut_telnetlib.py references.
remove nut_telnetlib.py reference.
remove nut_have_telnetlib checks
I've committed those changes now however I'm not sure about Running
I'll remove |
Thanks for the heads-up about I suggest to look at earlier changes that added |
… for "socket" instead of "telnetlib" module [networkupstools#2183] Signed-off-by: Jim Klimov <[email protected]>
I've updated the Local |
Excellent! Thanks so much, I was sitting there staring at the diffs not having a clue how to fix it 😆. Are all the other files good? |
…do not need anymore Signed-off-by: Jim Klimov <[email protected]>
I've re-read that note, it seems to have been more about name resolution, which I am not sure which layer had a problem with. De-facto, as there were experiments with "dual-stack" TCP support, it was found that in some cases the server with I'll generalize the message and that would be it. Here it is a comment why we don't use one "localhost" listener but two for explicit IP addresses. |
…IPv4/6 addresses, not a name, for upsd.conf Signed-off-by: Jim Klimov <[email protected]>
Thanks a lot, merging! |
…empty) for recipe to be fully defined [#2792] Signed-off-by: Jim Klimov <[email protected]>
Fantastic! Thanks for all your help with finishing it off. |
Well, sadly or not, but development entails more than just a bit of great coding :) |
FWIW, current state of the module should be uploaded to https://test.pypi.org/project/pynutclient/2.8.2.2132/ now, so can be tested as a standalone module. |
As discussed in #2183 I have updated
PyNUT.py.in
to no longer requirenut_telnetlib.py
.The update required only minimal changes to how the client sends and receives data from upsd.
Essentially, I just went through the file and switched all
self.__srv_handler
write
tosend
and allread_until
calls to a new function. The only other thing is fixing the timeout init argument.Testing has been performed by simply adding:
To the bottom of the script and running in pycharm debug mode to note the contents of all the variables and noting the logs/effect on the server.