Skip to content

Commit

Permalink
Merge PR ceph#28199 into master
Browse files Browse the repository at this point in the history
* refs/pull/28199/head:
	qa/tasks: upgrade the check for -c sudo option in vstart_runner.py

Reviewed-by: Patrick Donnelly <[email protected]>
  • Loading branch information
batrick committed May 31, 2019
2 parents 955c832 + 96be56c commit d1ae319
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions qa/tasks/vstart_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,29 +248,27 @@ def _perform_checks_and_return_list_of_args(self, args, omit_sudo):
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"]
Expand Down

0 comments on commit d1ae319

Please sign in to comment.