mirror of
https://github.com/ceph/ceph
synced 2025-02-22 10:37:15 +00:00
qa/tasks: upgrade the check for -c sudo option in vstart_runner.py
Right now vstart_runner.py checks if the command to be ran as a different user using sudo is a single argument by checking if "-c" is the second last arguemnt. However, this check fails in a case where "-c" is option for a command being ran as root (e.g. "sudo python -c some-python-program"). So, add check for this. Fixes: http://tracker.ceph.com/issues/39385 Signed-off-by: Rishabh Dave <ridave@redhat.com>
This commit is contained in:
parent
9577d6b00b
commit
96be56c4f1
@ -248,29 +248,27 @@ class LocalRemote(object):
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
# Quotes don't work in Python's shell simulation as a bash user would
|
||||
# expect. However, it works fine it has special meaning for the given
|
||||
# command (writing a small python program on the command line).
|
||||
if 'sudo' in args and 'python' not in args and \
|
||||
'python2' not in args and 'python3' not in args:
|
||||
if '-c' in args:
|
||||
args_to_check = args[args.index('-c') + 1 : ]
|
||||
else:
|
||||
args_to_check = args
|
||||
|
||||
for arg in args_to_check:
|
||||
if arg.find("'") != -1 or arg.find('"') != -1:
|
||||
raise RuntimeError("Don't surround commands by "
|
||||
"single/double quotes")
|
||||
# Quotes wrapping a command argument don't work fine in Python's shell
|
||||
# simulation if the arguments contains spaces too. E.g. '"ls"' is OK
|
||||
# but "ls /" isn't.
|
||||
errmsg = "Don't surround arguments commands by quotes if it " + \
|
||||
"contains spaces.\nargs - %s" % (args)
|
||||
for arg in args:
|
||||
if (arg[0] in ['"', "'"] or arg[-1] in ['"', "'"]) and \
|
||||
(arg.find(' ') != -1 and 0 < arg.find(' ') < len(arg) - 1):
|
||||
raise RuntimeError(errmsg)
|
||||
|
||||
# ['sudo', '-u', 'user', '-s', 'path-to-shell', '-c', 'ls', 'a']
|
||||
# and ['sudo', '-u', user, '-s', path_to_shell, '-c', 'ls a'] are
|
||||
# treated differently by Python's shell simulation. Only latter has
|
||||
# the desired effect.
|
||||
if 'sudo' in args and '-c' in args:
|
||||
if args.index('-c') != len(args) - 2:
|
||||
raise RuntimeError("All args after '-c' should be a single "
|
||||
"string")
|
||||
errmsg = 'The entire command to executed as other user should be a ' +\
|
||||
'single argument.\nargs - %s' % (args)
|
||||
if ('sudo' in args or 'python' in args or 'python2' in args or
|
||||
'python3' in args) and '-c' in args:
|
||||
if args.index('-c') != len(args) - 2 and \
|
||||
args[args.index('-c') + 2].find('-') == -1:
|
||||
raise RuntimeError(errmsg)
|
||||
|
||||
if omit_sudo:
|
||||
args = [a for a in args if a != "sudo"]
|
||||
|
Loading…
Reference in New Issue
Block a user