-
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
Pkg bypass remediation #53320
Pkg bypass remediation #53320
Conversation
Changed salt.utils.fopen to salt.utils.files.fopen as the old style is being depricated.
This adds two separate tests. One to test the pkg.installed.bypass_file option and a second that tests the pkg.installed.bypass_file with pkg.installed.bypass_file_contains.
This fixes Python2 and Python3 compatibility.
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.
thanks for this fix! :) Looks like one of your tests is failing if you don't mind taking a look there.
@Ch3LL thank you. I saw the failed test. It was related to the default write behavior of the tempfile library. I've updated the function to write the temp_comment as a string only so both Python2 and Python3 can read it without any additional logic. So far it was passing tests on my laptop. Hopefully that is the last fix needed for the tests. |
By the way, I just realized that there is another (more generic and powerful) feature that could achieve the same result: #51846 Something along the lines:
And to check for file contents you can use If that works for you, you might want to roll back your previous PR as well, to make Salt more pythonic ( |
@max-arnold I tried testing this. It looks like the |
That is a bummer. Maybe @gtmanfred could chime in to help figure out why The other downside is that |
@max-arnold I'm now testing on the dev branch. It looks like it is working. While it is faster, it is still taking over a second on my Vagrant vs the 6-9ms with the bypass function. I welcome opinions on if the speed difference is worth the added feature. file.file_exists
file.sed_contains
|
@justindesilets I have no opinion on the speed difference, so it is up to you to decide (you have more context on how significant this issue is depending on the number of packages). If you want more feedback, I guess you can ask other folks in the Slack channel. Or maybe someone from SaltStack could weigh in. |
It sounds like the the bypass feature is used to work around the slow path of multiple calls to package databases, which sounds like a similar use-case for the aggregate system: https://docs.saltstack.com/en/latest/ref/states/aggregate.html#in-states I'm just a contributor with no architectural authority, but to be the bypass feature seems like a hack on the package module which should be removed. For the cases where it is truly needed, as @max-arnold points out, the requisite unless and execution module solution offers similar functionality with increased execution time, but with more generic and extendable invocation. |
On the other hand, the feature already exists within the salt codebase, albeit broken, which this PR is fixing. That alone warrants this PR despite the discussion on whether or not the feature itself is wanted/needed/optimal in the first place. |
I am fine with the bypass feature being removed. The only reason I added it in the first place is that I was unaware of any existing method to achieve the same result. I'd like to update the documentation with the examples talked about in this thread, but I am not sure what would be the best location for that? To maximized the effectiveness, you would want to use aggregate in combination with the unless requisite. Do anyone have any suggestions as to where something like this could be documented and highlighted for other users to find? |
I think that To add a hyperlink to the new unless/onlyif feature https://docs.saltstack.com/en/develop/ref/states/requisites.html#unless you can use the following rst syntax:
You could also add a note here https://docs.saltstack.com/en/latest/ref/states/aggregate.html To build the docs on your local machine you probably need to install this https://github.com/saltstack/salt/blob/develop/requirements/static/py2.7/docs.txt and then run |
Thank you @max-arnold. I should be able to work on a new PR for updating the documentation this week. I don't know the process for having a feature pulled back out. Are you able to provide any guidance on this? |
Since the feature is not yet released (feature freeze for Neon is expected in a few days), you can just create a PR (or reuse this one) with a reverse commit (use |
I think the unless/onlyif slowness might be caused by Lines 1942 to 1943 in 35646c5
The LazyLoader attempts to load every state module to find the possible CC: @gtmanfred |
What does this PR do?
Fixes a deprecated function call in the pkg.installed.bypass_file and pkg.installed.bypass_file_contains options.
Was: salt.utils.fopen Is: salt.utils.files.fopen
What issues does this PR fix or reference?
#50922 (comment)
Tests written?
Tests were added to tests.unit.states.test_pkg.py as:
Commits signed with GPG?
No