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

Fix file comment #51988

Merged
merged 4 commits into from
Mar 6, 2019
Merged

Fix file comment #51988

merged 4 commits into from
Mar 6, 2019

Conversation

mbunkus
Copy link
Contributor

@mbunkus mbunkus commented Mar 5, 2019

What does this PR do?

It fixes both the file.comment and file.uncomment state functions's behavior: both failed to do anything if the pattern is present in both commented and uncommented form.

What issues does this PR fix or reference?

It fixes #41818.

Previous Behavior

When both commented and uncommented lines with the pattern existed, both states did nothing and reported that the pattern was already (un)commented. Lines that could be (un)commented were not.

New Behavior

The logic is reversed. If there's at least one line to (un)comment, all relevant lines will be (un)commented. Only if there's nothing to do will a search for an already (un)commented line be made in order to make the return message more meaningful (either "pattern already (un)commented" or "pattern not found").

Tests written?

No

Commits signed with GPG?

Yes

When you had a file containing the pattern to comment in both
commented and uncommented form, the old logic was wrong. In such a
case it was not commenting the lines that could be commented and
instead returned that the pattern was already commented.

The new logic gives commenting precedence: if at least one line exists
that can be commented, they all will be, no matter if other lines that
have already been commented exist. Only if no lines to comment exist
will a check be made to see if there's an already commented pattern or
if the pattern doesn't exist at all.

The new behavior matches the file.comment module function's behavior.

This fixes #41818.
When you had a file containing the pattern to comment in both
commented and uncommented form, the old logic was wrong. In such a
case it was not uncommenting the lines that could be uncommented and
instead returned that the pattern was already uncommented.

The new logic gives uncommenting precedence: if at least one line
exists that can be uncommented, they all will be, no matter if other
lines that have already been commented exist. Only if no lines to
uncomment exist will a check be made to see if there's an already
uncommented pattern or if the pattern doesn't exist at all.

The new behavior matches the file.uncomment module function's
behavior.

See #41818 for an analog problem in the file.comment state function.
@twangboy twangboy added v2018.3.5 unsupported version v2019.2.1 unsupported version labels Mar 5, 2019
@twangboy
Copy link
Contributor

twangboy commented Mar 5, 2019

@mbunkus Looks like this is causing some test failures.

@mbunkus
Copy link
Contributor Author

mbunkus commented Mar 5, 2019

I'll be out of town for several days. I'd appreciate it if someone else could fix up the tests. If not, I'll try to get around to it end of next week or so.

@mbunkus
Copy link
Contributor Author

mbunkus commented Mar 6, 2019

I cannot run the tests at the moment. I've never done that before, so I don't know what the problem might be.

I have a venv set up & activated; it's the one I use for running my changed states/modules. I did read HACKING.rst and installed the dev requirements for Python 2.7 in the venv. However, running ./setup.py test results in:

# tons of messages about installing stuff, then:
running test
Traceback (most recent call last):
  File "/home/mosu/prog/salt/tests/runtests.py", line 61, in <module>
    from tests.integration import TestDaemon  # pylint: disable=W0403
  File "/home/mosu/prog/salt/tests/integration/__init__.py", line 34, in <module>
    from tests.support.processes import *  # pylint: disable=wildcard-import
  File "/home/mosu/prog/salt/tests/support/processes.py", line 18, in <module>
    from pytestsalt.utils import collect_child_processes, terminate_process, terminate_process_list  # pylint: disable=unused-import
ImportError: No module named pytestsalt.utils

Yeah… there's no file or directory whose name contains pytestsalt:

[0 mosu@sweet-chili (fix-file-comment) ~/prog/salt] find -iname '*pytestsalt*'
[0 mosu@sweet-chili (fix-file-comment) ~/prog/salt] find ~/opt/salt-dev/ -iname '*pytestsalt*'
[0 mosu@sweet-chili (fix-file-comment) ~/prog/salt]

So… what now?

@mbunkus
Copy link
Contributor Author

mbunkus commented Mar 6, 2019

Oh, pip install -r requirements/pytest.txt seems to fix that problem. Looks like HACKING.rst is outdated.

@mbunkus
Copy link
Contributor Author

mbunkus commented Mar 6, 2019

I've fixed the unit test logic to accommodate the change to the file.(un)comment state functions. That test (unit.states.test_file) passes for me now and should hopefully pass on the builders as well.

@twangboy twangboy merged commit dd813d8 into saltstack:develop Mar 6, 2019
garethgreenaway added a commit to garethgreenaway/salt that referenced this pull request Sep 19, 2019
dwoz added a commit that referenced this pull request Jan 10, 2020
@waynew waynew added the has master-port port to master has been created label Feb 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has master-port port to master has been created v2018.3.5 unsupported version v2019.2.1 unsupported version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

file.comment issue when multiple lines with some already commented
3 participants