From 512f4721a57b4d986fa104bfdaf99f3258b7c8f5 Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Thu, 11 Apr 2019 22:46:47 +0530 Subject: [PATCH] qa: move checks on command arguments to a different method Signed-off-by: Rishabh Dave --- qa/tasks/vstart_runner.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/qa/tasks/vstart_runner.py b/qa/tasks/vstart_runner.py index ece01701baf7f..5555eae9c5216 100644 --- a/qa/tasks/vstart_runner.py +++ b/qa/tasks/vstart_runner.py @@ -234,22 +234,30 @@ class LocalRemote(object): def put_file(self, src, dst, sudo=False): shutil.copy(src, dst) - def run(self, args, check_status=True, wait=True, - stdout=None, stderr=None, cwd=None, stdin=None, - logger=None, label=None, env=None, timeout=None, omit_sudo=True): - if str(type(args)).find('str') != -1: + def _perform_checks_and_return_list_of_args(self, args, omit_sudo): + # Since Python's shell simulation can only work when commands are + # provided as a list of argumensts... + if isinstance(args, str): args = args.split() + # We'll let sudo be a part of command even omit flag says otherwise in + # cases of commands which can normally be ran only by root. try: if args[args.index('sudo') + 1] in ['-u', 'passwd', 'chown']: omit_sudo = False except ValueError: pass - # We don't need no stinkin' sudo if omit_sudo: args = [a for a in args if a != "sudo"] + return args + + def run(self, args, check_status=True, wait=True, + stdout=None, stderr=None, cwd=None, stdin=None, + logger=None, label=None, env=None, timeout=None, omit_sudo=True): + args = self._perform_checks_and_return_list_of_args(args, omit_sudo) + # We have to use shell=True if any run.Raw was present, e.g. && shell = any([a for a in args if isinstance(a, Raw)]) -- 2.39.5