Migrate the Jenkins script to the new Terminal class.

This commit is contained in:
Pedro Algarvio 2013-12-09 17:23:08 +00:00
parent 262e787664
commit aae6f0c4a1

View File

@ -17,12 +17,11 @@ import random
import shutil
import hashlib
import optparse
import subprocess
try:
from salt.utils.nb_popen import NonBlockingPopen
from salt.utils.vt import Terminal
except ImportError:
# Salt not installed, or nb_popen was not yet shipped with it
# Salt not installed, or vt was not yet shipped with it
SALT_LIB = os.path.abspath(
os.path.dirname(os.path.dirname(__file__))
)
@ -30,14 +29,14 @@ except ImportError:
sys.path.insert(0, SALT_LIB)
try:
# Let's try using the current checked out code
from salt.utils.nb_popen import NonBlockingPopen
from salt.utils.vt import Terminal
except ImportError:
# Still an ImportError??? Let's use some "brute-force"
sys.path.insert(
0,
os.path.join(SALT_LIB, 'salt', 'utils')
)
from nb_popen import NonBlockingPopen
from vt import Terminal # pylint: disable=F0401
def generate_vm_name(platform):
@ -61,15 +60,17 @@ def delete_vm(options):
print('Running CMD: {0}'.format(cmd))
sys.stdout.flush()
proc = NonBlockingPopen(
proc = Terminal(
cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
stream_stds=True
stream_stdout=True,
stream_stderr=True,
log_stderr=True,
log_stdout=True
)
proc.poll_and_read_until_finish()
proc.communicate()
while proc.isalive():
time.sleep(0.025)
return proc.exitstatus
def echo_parseable_environment(options):
@ -111,19 +112,21 @@ def download_unittest_reports(options):
print('Running CMD: {0}'.format(cmd))
sys.stdout.flush()
proc = NonBlockingPopen(
proc = Terminal(
cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stream_stds=True
stream_stdout=True,
stream_stderr=True,
log_stderr=True,
log_stdout=True
)
proc.poll_and_read_until_finish()
proc.communicate()
if proc.returncode != 0:
while proc.isalive():
time.sleep(0.025)
if proc.exitstatus != 0:
print(
'\nFailed to execute command. Exit code: {0}'.format(
proc.returncode
proc.exitstatus
)
)
time.sleep(0.25)
@ -151,19 +154,21 @@ def download_coverage_report(options):
print('Running CMD: {0}'.format(cmd))
sys.stdout.flush()
proc = NonBlockingPopen(
proc = Terminal(
cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stream_stds=True
stream_stdout=True,
stream_stderr=True,
log_stderr=True,
log_stdout=True
)
proc.poll_and_read_until_finish()
proc.communicate()
if proc.returncode != 0:
while proc.isalive():
time.sleep(0.025)
if proc.exitstatus != 0:
print(
'\nFailed to execute command. Exit code: {0}'.format(
proc.returncode
proc.exitstatus
)
)
time.sleep(0.25)
@ -196,19 +201,21 @@ def download_remote_logs(options):
print('Running CMD: {0}'.format(cmd))
sys.stdout.flush()
proc = NonBlockingPopen(
proc = Terminal(
cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stream_stds=True
stream_stdout=True,
stream_stderr=True,
log_stderr=True,
log_stdout=True
)
proc.poll_and_read_until_finish()
proc.communicate()
if proc.returncode != 0:
while proc.isalive():
time.sleep(0.025)
if proc.exitstatus != 0:
print(
'\nFailed to execute command. Exit code: {0}'.format(
proc.returncode
proc.exitstatus
)
)
time.sleep(0.25)
@ -234,17 +241,18 @@ def run(opts):
print('Running CMD: {0}'.format(cmd))
sys.stdout.flush()
proc = NonBlockingPopen(
proc = Terminal(
cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
stream_stds=True
stream_stdout=True,
stream_stderr=True,
log_stderr=True,
log_stdout=True
)
proc.poll_and_read_until_finish()
proc.communicate()
while proc.isalive():
time.sleep(0.025)
retcode = proc.returncode
retcode = proc.exitstatus
if retcode != 0:
print('Failed to bootstrap VM. Exit code: {0}'.format(retcode))
sys.stdout.flush()
@ -272,36 +280,36 @@ def run(opts):
print('Running CMD: {0}'.format(cmd))
sys.stdout.flush()
#proc = NonBlockingPopen(
proc = subprocess.Popen(
proc = Terminal(
cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
# stream_stds=True
stream_stdout=True,
stream_stderr=True,
log_stderr=True,
log_stdout=True
)
#proc.poll_and_read_until_finish()
stdout, stderr = proc.communicate()
if stdout:
print(stdout)
sys.stdout.flush()
try:
match = re.search(r'Test Suite Exit Code: (?P<exitcode>[\d]+)', stdout)
retcode = int(match.group('exitcode'))
except AttributeError:
# No regex matching
retcode = 1
except ValueError:
# Not a number!?
retcode = 1
except TypeError:
# No output!?
retcode = 1
if stdout:
# Anything else, raise the exception
raise
retcode = None
while proc.isalive():
stdout, _ = proc.recv()
if stdout and retcode is None:
try:
match = re.search(r'Test Suite Exit Code: (?P<exitcode>[\d]+)',
stdout)
if match:
retcode = int(match.group('exitcode'))
except AttributeError:
# No regex matching
retcode = 1
except ValueError:
# Not a number!?
retcode = 1
except TypeError:
# No output!?
retcode = 1
if stdout:
# Anything else, raise the exception
raise
time.sleep(0.025)
if opts.download_remote_reports:
# Download unittest reports