summaryrefslogtreecommitdiffstats
path: root/scripts/automation/regression/misc_methods.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/automation/regression/misc_methods.py')
-rwxr-xr-xscripts/automation/regression/misc_methods.py45
1 files changed, 22 insertions, 23 deletions
diff --git a/scripts/automation/regression/misc_methods.py b/scripts/automation/regression/misc_methods.py
index 2341b9be..783858e8 100755
--- a/scripts/automation/regression/misc_methods.py
+++ b/scripts/automation/regression/misc_methods.py
@@ -20,29 +20,28 @@ def mix_string (str):
return str.replace(' ', '_').lower()
# executes given command, returns tuple (return_code, stdout, stderr)
-def run_command(cmd):
- print 'Running command:', cmd
- proc = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- (stdout, stderr) = proc.communicate()
- if stdout:
- print 'Stdout:\n%s' % stdout
- if stderr:
- print 'Stderr:\n%s' % stderr
- print 'Return code: %s' % proc.returncode
- return (proc.returncode, stdout, stderr)
-
-
-def run_remote_command(host, passwd, command_string):
- cmd = 'ssh -tt %s \'sudo sh -c "%s"\'' % (host, command_string)
- print 'Trying connection with ssh...'
- return_code, stdout, stderr = run_command(cmd)
- if return_code == 0:
- return (return_code, stdout, stderr)
- elif passwd is not None:
- print 'Trying connection with expect + sshpass.exp...'
- cmd = 'sshpass.exp %s %s root "%s"' % (passwd, host, command_string)
- return_code, stdout, stderr = run_command(cmd)
- return (return_code, stdout, stderr)
+def run_command(cmd, background = False):
+ if background:
+ print 'Running command in background:', cmd
+ with open(os.devnull, 'w') as tempf:
+ subprocess.Popen(shlex.split(cmd), stdin=tempf, stdout=tempf, stderr=tempf)
+ return (None,)*3
+ else:
+ print 'Running command:', cmd
+ proc = subprocess.Popen(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ (stdout, stderr) = proc.communicate()
+ if stdout:
+ print 'Stdout:\n%s' % stdout
+ if proc.returncode:
+ if stderr:
+ print 'Stderr:\n%s' % stderr
+ print 'Return code: %s' % proc.returncode
+ return (proc.returncode, stdout, stderr)
+
+
+def run_remote_command(host, command_string, background = False):
+ cmd = 'ssh -tt %s \'sudo sh -ec "%s"\'' % (host, command_string)
+ return run_command(cmd, background)
def generate_intf_lists (interfacesList):