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 useradd hard-coded relative command names #62088

Merged

Conversation

nicholasmhughes
Copy link
Collaborator

What does this PR do?

This PR adds support for searching for useradd, usermod, and userdel binaries using the salt.utils.path.which function instead of solely relying on the PATH environment variable to find them.

What issues does this PR fix or reference?

Fixes: #62087

Previous Behavior

Binaries would not be found if some "sbin" locations were not in the PATH, despite being installed.

New Behavior

The salt.utils.path.which function adds some standard paths into the search locations, so the binaries will still be found if in a "standard" location like /sbin/ even if that directory isn't in the PATH.

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.

@nicholasmhughes nicholasmhughes requested a review from a team as a code owner May 19, 2022 23:20
@nicholasmhughes nicholasmhughes requested review from whytewolf and removed request for a team May 19, 2022 23:20
@whytewolf
Copy link
Collaborator

Hey Nick,

Nice pr, looks like the tests will need to be skipped on a couple of operating systems.

@nicholasmhughes
Copy link
Collaborator Author

hmmm... looks like it's failing the old style tests because the which return isn't mocked. I guess I should probably ensure full pytest coverage and just remove the old unit tests.

@whytewolf
Copy link
Collaborator

Hey @nicholasmhughes so, my two cents on the mocking of which. I would rather know these fail on some operating systems that don't have useradd and the like. and have the tests account for that change. then to mock which and have it "work" when the module wouldn't actually work on an operating system.

but that is just my two cents. @waynew what do you think?

@nicholasmhughes
Copy link
Collaborator Author

re-run pr-opensuse-15-x86_64-py3-pytest

@nicholasmhughes
Copy link
Collaborator Author

re-run pr-fedora-34-x86_64-py3-pytest

@nicholasmhughes
Copy link
Collaborator Author

re-run pr-centos-7-x86_64-py3-tcp-pytest

@nicholasmhughes nicholasmhughes added the Phosphorus v3005.0 Release code name and version label May 21, 2022
@waynew
Copy link
Contributor

waynew commented May 23, 2022

@whytewolf when it comes to a unit test, mocking is preferable, but it wouldn't hurt at all to have a functional test that fails on Windows or other systems without useradd. Could do something like:

@pytest.mark.skipIf(..., "Should only fail on Windows/Mac")  # or whatever
def test_errors_out_when_no_useradd_exists():
    with pytest.raises(CommandExecutionError):
        ...

It might be worthwhile adding another test for successful platforms, but I think we actually do have some of those already? 🤔

@nicholasmhughes
Copy link
Collaborator Author

re-run full all

@whytewolf
Copy link
Collaborator

@whytewolf when it comes to a unit test, mocking is preferable, but it wouldn't hurt at all to have a functional test that fails on Windows or other systems without useradd. Could do something like:

@pytest.mark.skipIf(..., "Should only fail on Windows/Mac")  # or whatever
def test_errors_out_when_no_useradd_exists():
    with pytest.raises(CommandExecutionError):
        ...

It might be worthwhile adding another test for successful platforms, but I think we actually do have some of those already? 🤔

Woops totally didn't notice they were unit thought they were functional for some reason. You're right. unit should be mocked. the new test looks to cover my concern so approving.

Copy link
Contributor

@waynew waynew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 You rock!

@nicholasmhughes
Copy link
Collaborator Author

re-run pr-arch-lts-x86_64-py3-pytest

@garethgreenaway garethgreenaway merged commit de03178 into saltstack:master May 25, 2022
@nicholasmhughes nicholasmhughes deleted the fix-useradd-cmd-path branch May 25, 2022 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Phosphorus v3005.0 Release code name and version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] useradd.* functions hard code relative command name
4 participants