-
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
cmdmod: New group option for command execution & MacOS shell arg fix #43901
Conversation
Indecisive on the issue name. 😄 Here are some test runs on my local dev box:
This command should fail on other shells that are not fishy enough. 😉
Bash wasn't fishy enough.
If the
This shows a few more runs mixing
Files created whilst running under a different group inherit the group ownership, which can be particularly useful in some situations.
This demonstrates the new |
Is that my bad? It's not obvious to me what the problem is (if it's something I did). |
re-run py3 |
@boltronics I'm not sure, so I've restarted the py3 test to see if we get the same result. Offhand, it looks to me like the sub_minion test daemon didn't start, so let's see how the second run goes. :) |
There was a small merge conflict that I fixed by hand. |
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 good, did not miss any of the entry points and covers multi OS issues correctly. Nicely done @boltronics
Thanks all. I note this PR has a conflict at this point. Looks trivial to fix though since it's just a matter of relocating the changes in Normally I would just rebase against develop and force-push, but since everything has been approved at this point, I don't want to invalidate that. 😄 So should someone else be making that adjustment? |
To clarify, I'm happy to make the changes myself if preferred. Whatever works. Please let me know how you wish to proceed. |
Hi @boltronics - If you could handle the rebasing, that would be great. If you have any questions, please let us know. Thank you! |
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.
Needs a rebase and a few changes.
salt/modules/cmdmod.py
Outdated
@@ -22,6 +22,7 @@ | |||
import base64 | |||
import re | |||
import tempfile | |||
from distutils.spawn import find_executable |
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.
Please import this as a private function (i.e. from distutils.spawn import find_executable as _find_executable
). Importing a function into the global namespace of the module will both a) cause it to be picked up by the loader (and thus end up in the __salt__
dunder dictionary), and b) add it to the docs when they are built using Sphinx.
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.
Is there a reason we shouldn't just use salt.utils.path.which_bin
?
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 the tip. I hadn't noticed it.
salt/modules/cmdmod.py
Outdated
if salt.utils.platform.is_windows(): | ||
msg = 'group is not currently available on Windows' | ||
raise SaltInvocationError(msg) | ||
if not find_executable('sudo'): |
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.
As with the comment on the import above, let's make sure this is a private function (i.e. _find_executable
).
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.
Good catch! But I'll try to switch this over to which_bin
since that's already imported.
salt/utils/__init__.py
Outdated
@@ -1732,6 +1732,106 @@ def appendproctitle(name): | |||
setproctitle.setproctitle(setproctitle.getproctitle() + ' ' + name) | |||
|
|||
|
|||
def chugid(runas, group=None): |
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.
It looks like these functions were added separately in a different PR and already exist in develop. However, they have been moved to salt/utils/user.py
. Please check the functions you are adding here against their counterparts in that file and make any changes there. We should not be adding new functions to salt/utils/__init__.py
.
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.
Actually, they already existed when I originally submitted the PR but have since been moved. That was the original reason for needing to rebase after the initial approval, so will be sure to fix that up.
@boltronics I asked @terminalmage to swing past here again today but we also do need a rebase here, please. There are a couple of merge conflicts. Thanks. |
@boltronics I'll re-review once you get that rebase in. I do like the idea of using |
Hi @boltronics - Any chance you were able to come back to this? |
0b99ae2
to
a78b082
Compare
@rallytime @terminalmage I think that's sorted now. Sorry it took so long. |
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.
There's one minor thing here but it's not important enough to stand in the way of merging.
salt/modules/cmdmod.py
Outdated
@@ -372,10 +375,11 @@ def _get_stripped(cmd): | |||
# requested. The command output is what will be controlled by the | |||
# 'loglevel' parameter. | |||
msg = ( | |||
'Executing command {0}{1}{0} {2}in directory \'{3}\'{4}'.format( | |||
u'Executing command {0}{1}{0} {2}{3}in directory \'{4}\'{5}'.format( |
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.
The u
is unnecessary here since we're going to be using unicode_literals
.
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.
I should have noticed it wasn't in the original string (or rather, not the one there after rebasing). Sorry I didn't pick up on that. Fixed it anyway.
a78b082
to
f867eff
Compare
This has the side effect of having cmdmod support a custom shell on MacOS.
f867eff
to
c574bff
Compare
re-run py |
What does this PR do?
Adds the
group
argument to various functions incmdmod
for non-Windows hosts. Also enables theshell
option on OS X, which looked to have been silently ignored previously (although I don't have a Mac to test with).What issues does this PR fix or reference?
#43900
Previous Behavior
The
group
option did not exist. Theshell
option was ignored on OS X.New Behavior
The
group
option exists. Theshell
option should be honoured on OS X.Tests written?
No
Please review Salt's Contributing Guide for best practices.