-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add filter status to ps module #61421
Add filter status to ps module #61421
Conversation
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.
Hey @remyd1 thanks for the PR! This seems like a useful addition (without checking to see if there's anything else that could accomplish this - I'm assuming that you did that already, given the feature request!)
One thing that this would require is tests.
If you need help writing tests, attend one of the Test Clinics on Twitch!
I would still need a bit of help to write the corresponding test clinic. I looked at tour twitch streams but I am still kind of a bit lost. |
Tests updated ! Thanks @waynew |
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.
Just a small change request. Also there are failing tests related to this change that need to be fixed.
Returns a list of processes according to their states. | ||
See https://psutil.readthedocs.io/en/latest/index.html\ | ||
?highlight=status#process-status-constants | ||
|
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.
.. versionadded:: 3005
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.
Well, 3006 now 😂
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.
added (and updated the docstring a bit)
@remyd1 are you able to come back to this PR and fix the tests and fix the feedback submitted? |
This comment was marked as outdated.
This comment was marked as outdated.
1 similar comment
Hi! I'm your friendly PR bot!You might be wondering what I'm doing commenting here on your PR. Yes, as a matter of fact, I am... I'm just here to help us improve the documentation. I can't respond to Okay... so what do you do? I detect modules that are missing docstrings or "CLI Example" on existing docstrings! So what does that have to do with my PR? I noticed that in this PR there are some files changed that have some of these Okay, what are they? Well, my favorite, is that since you were making changes here I'm hoping that If I can, then what? Well, you can either add them to this PR or add them to another PR. Either way is fine! Well... what if I can't, or don't want to? That's also fine! We appreciate all contributions to the Salt Project. If you Whatever approach you decide to take, just drop a comment here letting us know! Detected Issues (click me)Check Known Missing Docstrings...........................................Failed - hook id: invoke - exit code: 1 Thanks again! |
Hi @Ch3LL , unfortunately I have no more time to dig into those test cases. Moreover, I am a bit lost with Mock, MagicMock and associated Salt methods... If anyone could fix these tests, it would be helpful. Thanks, |
@remyd1 I can take a look at this during tomorrow's Test Clinic. If you don't have the time/inclination to finish it up I may be able to get it sorted out 👍 |
Indeed, if you could check what is wrong here, it would be great 👍🏼 |
@remyd1 Didn't I look into this on Tuesday's Test Clinic? Were you able to update the tests here or do you need a bit more help to get this done? |
Hi @waynew No, sorry. As I said, I have less time to spend on this. Did you do stream some more tests on it ? Could you give me back you Twitch URL ? Anyway, I do not think I will be able to achieve this. Thanks, |
426b32d
to
c814043
Compare
@waynew looks like there are related test failures |
Doh! Yeah, looks like I didn't understand the API of the Process quite well |
Looks like just window, mac and windows are failing now |
530768f
to
647b17b
Compare
Renamed `filter` to `status` to match up with the psutil.Process.status. Also added a comment to call out the singular status vs multiple, and mention how that could be added in the future. Also added versionadded to the docs, re: @Ch3LL's feedback. Refactored the module a bit to pass tests, as well as simplify the return bits. There was no need to check that the return type was a generator - psutil.process_iter is going to yield always, and we don't really care about anything else getting mocked, we just want to iterate over it. Since psutil.Process already has a `.as_dict(attrs=...)` where we can filter by the attributes we care about, we can go ahead and use that instead of having to `pop` the ones we don't care about.
The problem: psutil has Process objects for different platforms, and those actually try to parse some system output bits that may not exist when we don't have a process with that PID. Since we're creating one with PID 42, we need to mock out all the shenanigans that the underlying Process will use. Specifically currently that's: - create_time - _parse_stat_file - status
On other platforms this attribute doesn't exist, but we don't really care. If it exists it shouldn't be a problem. So go ahead and create=True.
2001793
to
6a2cc33
Compare
Co-authored-by: Megan Wilhite <mwilhite@vmware.com>
@Ch3LL failures didn't look related - one looked like the underlying OS/Docker had an issue (completely unrelated to this module) and the others that I saw claimed to be a mem leak issue but... I'm guessing that's also a flaky test |
What does this PR do?
It allows to retrieve a list of processes according to their state, using
psutil
.What issues does this PR fix or reference?
Fixes: #61420
Merge requirements satisfied?
[NOTICE] Bug fixes or features added to Salt require tests.
Commits signed with GPG?
Yes
Please review Salt's Contributing Guide for best practices.
See GitHub's page on GPG signing for more information about signing commits with GPG.