11 from __future__
import print_function
12 from builtins
import str
18 from BaseMTTUtility
import *
27 BaseMTTUtility.__init__(self)
35 lines = testDef.printOptions(self.
options)
41 if options
and name
in options:
45 elif type(val)
is str:
46 val = val.strip().lower()
47 return val
in [
'y',
'yes',
't',
'true',
'1']
55 if options
and name
in options:
57 if val
is None or val < 0:
61 def execute(self, options, cmdargs, testDef):
63 if 'dryrun' in testDef.options
and testDef.options[
'dryrun']:
68 merge = self.
_bool_option(options,
'merge_stdout_stderr')
80 elapsed_datetime =
None
87 mycmdargs.append(arg.replace(
'\"',
''))
88 testDef.logger.verbose_print(
"ExecuteCmd start: " +
' '.join(mycmdargs), timestamp=datetime.datetime.now()
if time_exec
else None)
91 testDef.logger.verbose_print(
"ExecuteCmd error: no cmdargs")
92 return (1, [], [
"MTT ExecuteCmd error: no cmdargs"], 0)
99 starttime = datetime.datetime.now()
104 p = subprocess.Popen(mycmdargs,
105 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
112 reads = [p.stdout.fileno(), p.stderr.fileno()]
113 ret = select.select(reads, [], [])
120 if fd == p.stdout.fileno():
121 read = p.stdout.readline()
123 read = read.decode(
'utf-8').rstrip()
124 testDef.logger.verbose_print(
'stdout: ' + read)
130 elif fd == p.stderr.fileno():
131 read = p.stderr.readline()
133 read = read.decode(
'utf-8').rstrip()
134 testDef.logger.verbose_print(
'stderr: ' + read)
138 if stdout_done
and stderr_done:
142 endtime = datetime.datetime.now()
143 elapsed_datetime = endtime - starttime
144 elapsed_secs = elapsed_datetime.total_seconds()
146 testDef.logger.verbose_print(
"ExecuteCmd done%s" % (
": elapsed=%s"%elapsed_datetime
if time_exec
else ""), \
147 timestamp=endtime
if time_exec
else None)
154 return (1, [], [str(e)], elapsed_secs)
156 return (p.returncode,
157 stdout[-1 * stdoutlines:],
158 stderr[-1 * stderrlines:],