<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import , print_function <EOL> import glob <EOL> import os <EOL> import re <EOL> import sys <EOL> import json <EOL> import time <EOL> import shutil <EOL> import optparse <EOL> import subprocess <EOL> import random <EOL> import salt . utils <EOL> try : <EOL> from salt . utils . nb_popen import NonBlockingPopen <EOL> except ImportError : <EOL> SALT_LIB = os . path . abspath ( <EOL> os . path . dirname ( os . path . dirname ( __file__ ) ) <EOL> ) <EOL> if SALT_LIB not in sys . path : <EOL> sys . path . insert ( <NUM_LIT:0> , SALT_LIB ) <EOL> try : <EOL> from salt . utils . nb_popen import NonBlockingPopen <EOL> except ImportError : <EOL> sys . path . insert ( <EOL> <NUM_LIT:0> , <EOL> os . path . join ( SALT_LIB , '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> from nb_popen import NonBlockingPopen <EOL> import yaml <EOL> try : <EOL> import requests <EOL> HAS_REQUESTS = True <EOL> except ImportError : <EOL> HAS_REQUESTS = False <EOL> SALT_GIT_URL = '<STR_LIT>' <EOL> def build_pillar_data ( options ) : <EOL> '''<STR_LIT>''' <EOL> pillar = { '<STR_LIT>' : options . test_transport , <EOL> '<STR_LIT>' : options . cloud_only , <EOL> '<STR_LIT>' : options . test_without_coverage is False } <EOL> if options . test_git_commit is not None : <EOL> pillar [ '<STR_LIT>' ] = options . test_git_commit <EOL> if options . test_git_url is not None : <EOL> pillar [ '<STR_LIT>' ] = options . test_git_url <EOL> if options . bootstrap_salt_url is not None : <EOL> pillar [ '<STR_LIT>' ] = options . bootstrap_salt_url <EOL> if options . bootstrap_salt_commit is not None : <EOL> pillar [ '<STR_LIT>' ] = options . bootstrap_salt_commit <EOL> if options . package_source_dir : <EOL> pillar [ '<STR_LIT>' ] = options . package_source_dir <EOL> if options . package_build_dir : <EOL> pillar [ '<STR_LIT>' ] = options . package_build_dir <EOL> if options . package_artifact_dir : <EOL> pillar [ '<STR_LIT>' ] = options . package_artifact_dir <EOL> if options . pillar : <EOL> pillar . update ( dict ( options . pillar ) ) <EOL> return yaml . dump ( pillar , default_flow_style = True , indent = <NUM_LIT:0> , width = sys . maxint ) . rstrip ( ) <EOL> def build_minion_target ( options , vm_name ) : <EOL> target = vm_name <EOL> for grain in options . grain_target : <EOL> target += '<STR_LIT>' . format ( grain ) <EOL> if options . grain_target : <EOL> return '<STR_LIT>' . format ( target ) <EOL> return target <EOL> def generate_vm_name ( options ) : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT>' in os . environ : <EOL> random_part = '<STR_LIT>' . format ( os . environ . get ( '<STR_LIT>' ) ) <EOL> else : <EOL> random_part = os . urandom ( <NUM_LIT:3> ) . encode ( '<STR_LIT>' ) <EOL> return '<STR_LIT>' . format ( options . vm_prefix , options . platform , random_part ) <EOL> def delete_vm ( options ) : <EOL> '''<STR_LIT>''' <EOL> cmd = '<STR_LIT>' . format ( options . delete_vm ) <EOL> print ( '<STR_LIT>' . format ( cmd ) ) <EOL> sys . stdout . flush ( ) <EOL> proc = NonBlockingPopen ( <EOL> cmd , <EOL> shell = True , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> stream_stds = True <EOL> ) <EOL> proc . poll_and_read_until_finish ( interval = <NUM_LIT:0.5> ) <EOL> proc . communicate ( ) <EOL> def echo_parseable_environment ( options , parser ) : <EOL> '''<STR_LIT>''' <EOL> output = [ ] <EOL> if options . platform : <EOL> name = generate_vm_name ( options ) <EOL> output . extend ( [ <EOL> '<STR_LIT>' . format ( options . platform ) , <EOL> '<STR_LIT>' . format ( name ) <EOL> ] ) <EOL> if options . provider : <EOL> output . append ( <EOL> '<STR_LIT>' . format ( options . provider ) <EOL> ) <EOL> if options . pull_request : <EOL> if HAS_REQUESTS is False : <EOL> parser . error ( <EOL> '<STR_LIT>' <EOL> ) <EOL> headers = { } <EOL> url = '<STR_LIT>' . format ( options . pull_request ) <EOL> github_access_token_path = os . path . join ( <EOL> os . environ . get ( '<STR_LIT>' , os . path . expanduser ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> if os . path . isfile ( github_access_token_path ) : <EOL> headers = { <EOL> '<STR_LIT>' : '<STR_LIT>' . format ( <EOL> open ( github_access_token_path ) . read ( ) . strip ( ) <EOL> ) <EOL> } <EOL> http_req = requests . get ( url , headers = headers ) <EOL> if http_req . status_code != <NUM_LIT:200> : <EOL> parser . error ( <EOL> '<STR_LIT>' . format ( http_req . json ( ) ) <EOL> ) <EOL> pr_details = http_req . json ( ) <EOL> output . extend ( [ <EOL> '<STR_LIT>' . format ( pr_details [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' . format ( pr_details [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' . format ( pr_details [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' . format ( pr_details [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) , <EOL> ] ) <EOL> sys . stdout . write ( '<STR_LIT>' . format ( '<STR_LIT:\n>' . join ( output ) ) ) <EOL> sys . stdout . flush ( ) <EOL> def download_unittest_reports ( options ) : <EOL> print ( '<STR_LIT>' ) <EOL> sys . stdout . flush ( ) <EOL> workspace = options . workspace <EOL> xml_reports_path = os . path . join ( workspace , '<STR_LIT>' ) <EOL> if os . path . isdir ( xml_reports_path ) : <EOL> shutil . rmtree ( xml_reports_path ) <EOL> os . makedirs ( xml_reports_path ) <EOL> cmds = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> vm_name = options . download_unittest_reports <EOL> for cmd in cmds : <EOL> cmd = cmd . format ( build_minion_target ( options , vm_name ) , vm_name , workspace ) <EOL> print ( '<STR_LIT>' . format ( cmd ) ) <EOL> sys . stdout . flush ( ) <EOL> proc = NonBlockingPopen ( <EOL> cmd , <EOL> shell = True , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> stream_stds = True <EOL> ) <EOL> proc . poll_and_read_until_finish ( interval = <NUM_LIT:0.5> ) <EOL> proc . communicate ( ) <EOL> if proc . returncode != <NUM_LIT:0> : <EOL> print ( <EOL> '<STR_LIT>' . format ( <EOL> proc . returncode <EOL> ) <EOL> ) <EOL> time . sleep ( <NUM_LIT> ) <EOL> def download_coverage_report ( options ) : <EOL> print ( '<STR_LIT>' ) <EOL> sys . stdout . flush ( ) <EOL> workspace = options . workspace <EOL> vm_name = options . download_coverage_report <EOL> if os . path . isfile ( os . path . join ( workspace , '<STR_LIT>' ) ) : <EOL> os . unlink ( os . path . join ( workspace , '<STR_LIT>' ) ) <EOL> cmds = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> for cmd in cmds : <EOL> cmd = cmd . format ( build_minion_target ( options , vm_name ) , vm_name , workspace ) <EOL> print ( '<STR_LIT>' . format ( cmd ) ) <EOL> sys . stdout . flush ( ) <EOL> proc = NonBlockingPopen ( <EOL> cmd , <EOL> shell = True , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> stream_stds = True <EOL> ) <EOL> proc . poll_and_read_until_finish ( interval = <NUM_LIT:0.5> ) <EOL> proc . communicate ( ) <EOL> if proc . returncode != <NUM_LIT:0> : <EOL> print ( <EOL> '<STR_LIT>' . format ( <EOL> proc . returncode <EOL> ) <EOL> ) <EOL> time . sleep ( <NUM_LIT> ) <EOL> def download_remote_logs ( options ) : <EOL> print ( '<STR_LIT>' ) <EOL> sys . stdout . flush ( ) <EOL> workspace = options . workspace <EOL> vm_name = options . download_remote_logs <EOL> for fname in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if os . path . isfile ( os . path . join ( workspace , fname ) ) : <EOL> os . unlink ( os . path . join ( workspace , fname ) ) <EOL> if not options . remote_log_path : <EOL> options . remote_log_path = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> cmds = [ ] <EOL> for remote_log in options . remote_log_path : <EOL> cmds . extend ( [ <EOL> '<STR_LIT>' . format ( remote_log ) , <EOL> '<STR_LIT>' . format ( remote_log ) , <EOL> '<STR_LIT>' . format ( remote_log ) , <EOL> '<STR_LIT>' . format ( <EOL> remote_log , <EOL> '<STR_LIT>' . format ( <EOL> os . path . basename ( remote_log ) , <EOL> '<STR_LIT>' if remote_log . endswith ( '<STR_LIT>' ) else '<STR_LIT>' <EOL> ) <EOL> ) <EOL> ] ) <EOL> for cmd in cmds : <EOL> cmd = cmd . format ( build_minion_target ( options , vm_name ) , vm_name , workspace ) <EOL> print ( '<STR_LIT>' . format ( cmd ) ) <EOL> sys . stdout . flush ( ) <EOL> proc = NonBlockingPopen ( <EOL> cmd , <EOL> shell = True , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> stream_stds = True <EOL> ) <EOL> proc . poll_and_read_until_finish ( interval = <NUM_LIT:0.5> ) <EOL> proc . communicate ( ) <EOL> if proc . returncode != <NUM_LIT:0> : <EOL> print ( <EOL> '<STR_LIT>' . format ( <EOL> proc . returncode <EOL> ) <EOL> ) <EOL> time . sleep ( <NUM_LIT> ) <EOL> def download_packages ( options ) : <EOL> print ( '<STR_LIT>' ) <EOL> sys . stdout . flush ( ) <EOL> workspace = options . workspace <EOL> vm_name = options . download_packages <EOL> for fglob in ( '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) : <EOL> for fname in glob . glob ( os . path . join ( workspace , fglob ) ) : <EOL> if os . path . isfile ( fname ) : <EOL> os . unlink ( fname ) <EOL> cmds = [ <EOL> ( '<STR_LIT>' <EOL> . format ( options . package_artifact_dir ) ) , <EOL> '<STR_LIT>' . format ( options . package_artifact_dir ) , <EOL> ( '<STR_LIT>' <EOL> . format ( options . package_artifact_dir ) ) , <EOL> ] <EOL> for cmd in cmds : <EOL> cmd = cmd . format ( build_minion_target ( options , vm_name ) , vm_name , workspace ) <EOL> print ( '<STR_LIT>' . format ( cmd ) ) <EOL> sys . stdout . flush ( ) <EOL> proc = NonBlockingPopen ( <EOL> cmd , <EOL> shell = True , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> stream_stds = True <EOL> ) <EOL> proc . poll_and_read_until_finish ( interval = <NUM_LIT:0.5> ) <EOL> proc . communicate ( ) <EOL> if proc . returncode != <NUM_LIT:0> : <EOL> print ( <EOL> '<STR_LIT>' . format ( <EOL> proc . returncode <EOL> ) <EOL> ) <EOL> time . sleep ( <NUM_LIT> ) <EOL> def run ( opts ) : <EOL> '''<STR_LIT>''' <EOL> vm_name = os . environ . get ( <EOL> '<STR_LIT>' , <EOL> generate_vm_name ( opts ) <EOL> ) <EOL> if opts . download_remote_reports : <EOL> if opts . test_without_coverage is False : <EOL> opts . download_coverage_report = vm_name <EOL> opts . download_unittest_reports = vm_name <EOL> opts . download_packages = vm_name <EOL> if opts . bootstrap_salt_commit is not None : <EOL> if opts . bootstrap_salt_url is None : <EOL> opts . bootstrap_salt_url = '<STR_LIT>' <EOL> cmd = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( <EOL> vm_name , <EOL> os . environ . get ( <EOL> '<STR_LIT>' , <EOL> opts . bootstrap_salt_commit <EOL> ) , <EOL> ** opts . __dict__ <EOL> ) <EOL> ) <EOL> else : <EOL> cmd = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( <EOL> vm_name , <EOL> os . environ . get ( <EOL> '<STR_LIT>' , <EOL> opts . bootstrap_salt_commit <EOL> ) , <EOL> ** opts . __dict__ <EOL> ) <EOL> ) <EOL> if opts . splay is not None : <EOL> cloud_downtime = random . randint ( <NUM_LIT:0> , opts . splay ) <EOL> print ( '<STR_LIT>' . format ( cloud_downtime ) ) <EOL> time . sleep ( cloud_downtime ) <EOL> print ( '<STR_LIT>' . format ( cmd ) ) <EOL> sys . stdout . flush ( ) <EOL> proc = NonBlockingPopen ( <EOL> cmd , <EOL> shell = True , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> stream_stds = True <EOL> ) <EOL> proc . poll_and_read_until_finish ( interval = <NUM_LIT:0.5> ) <EOL> proc . communicate ( ) <EOL> retcode = proc . returncode <EOL> if retcode != <NUM_LIT:0> : <EOL> print ( '<STR_LIT>' . format ( retcode ) ) <EOL> sys . stdout . flush ( ) <EOL> if opts . clean and '<STR_LIT>' not in os . environ : <EOL> delete_vm ( opts ) <EOL> sys . exit ( retcode ) <EOL> print ( '<STR_LIT>' . format ( retcode ) ) <EOL> sys . stdout . flush ( ) <EOL> bootstrap_downtime = random . randint ( <NUM_LIT:0> , opts . splay ) <EOL> print ( '<STR_LIT>' . format ( bootstrap_downtime ) ) <EOL> sys . stdout . flush ( ) <EOL> time . sleep ( bootstrap_downtime ) <EOL> if opts . bootstrap_salt_commit is not None : <EOL> print ( '<STR_LIT>' ) <EOL> cmd = '<STR_LIT>' . format ( build_minion_target ( opts , vm_name ) ) <EOL> print ( '<STR_LIT>' . format ( cmd ) ) <EOL> sys . stdout . flush ( ) <EOL> proc = subprocess . Popen ( <EOL> cmd , <EOL> shell = True , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> ) <EOL> stdout , _ = proc . communicate ( ) <EOL> retcode = proc . returncode <EOL> if retcode != <NUM_LIT:0> : <EOL> print ( '<STR_LIT>' . format ( retcode ) ) <EOL> sys . stdout . flush ( ) <EOL> if opts . clean and '<STR_LIT>' not in os . environ : <EOL> delete_vm ( opts ) <EOL> sys . exit ( retcode ) <EOL> outstr = salt . utils . to_str ( stdout ) . strip ( ) <EOL> if not outstr : <EOL> print ( '<STR_LIT>' . format ( retcode ) ) <EOL> sys . stdout . flush ( ) <EOL> if opts . clean and '<STR_LIT>' not in os . environ : <EOL> delete_vm ( opts ) <EOL> sys . exit ( retcode ) <EOL> try : <EOL> version_info = json . loads ( outstr ) <EOL> bootstrap_minion_version = os . environ . get ( <EOL> '<STR_LIT>' , <EOL> opts . bootstrap_salt_commit [ : <NUM_LIT:7> ] <EOL> ) <EOL> print ( '<STR_LIT>' . format ( version_info ) ) <EOL> if bootstrap_minion_version not in version_info [ vm_name ] : <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> print ( <EOL> '<STR_LIT>' . format ( <EOL> version_info [ vm_name ] , <EOL> bootstrap_minion_version <EOL> ) <EOL> ) <EOL> print ( '<STR_LIT>' ) <EOL> sys . stdout . flush ( ) <EOL> else : <EOL> print ( '<STR_LIT>' ) <EOL> except ValueError : <EOL> print ( '<STR_LIT>' . format ( outstr ) ) <EOL> if opts . cloud_only : <EOL> cloud_provider_downtime = random . randint ( <NUM_LIT:3> , opts . splay ) <EOL> time . sleep ( cloud_provider_downtime ) <EOL> cmd = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( <EOL> target = build_minion_target ( opts , vm_name ) , <EOL> cloud_prep_sls = '<STR_LIT>' , <EOL> pillar = build_pillar_data ( opts ) , <EOL> ) <EOL> ) <EOL> else : <EOL> standard_sls_downtime = random . randint ( <NUM_LIT:3> , opts . splay ) <EOL> time . sleep ( standard_sls_downtime ) <EOL> cmd = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( <EOL> target = build_minion_target ( opts , vm_name ) , <EOL> prep_sls = opts . prep_sls , <EOL> pillar = build_pillar_data ( opts ) , <EOL> ) <EOL> ) <EOL> print ( '<STR_LIT>' . format ( cmd ) ) <EOL> sys . stdout . flush ( ) <EOL> proc = subprocess . Popen ( <EOL> cmd , <EOL> shell = True , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> ) <EOL> stdout , stderr = proc . communicate ( ) <EOL> if stdout : <EOL> print ( salt . utils . to_str ( stdout ) ) <EOL> if stderr : <EOL> print ( salt . utils . to_str ( stderr ) ) <EOL> sys . stdout . flush ( ) <EOL> retcode = proc . returncode <EOL> if retcode != <NUM_LIT:0> : <EOL> print ( '<STR_LIT>' . format ( retcode ) ) <EOL> sys . stdout . flush ( ) <EOL> if opts . clean and '<STR_LIT>' not in os . environ : <EOL> delete_vm ( opts ) <EOL> sys . exit ( retcode ) <EOL> if opts . cloud_only : <EOL> cloud_provider_pillar = random . randint ( <NUM_LIT:3> , opts . splay ) <EOL> time . sleep ( cloud_provider_pillar ) <EOL> cmd = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( <EOL> target = build_minion_target ( opts , vm_name ) , <EOL> cloud_prep_sls = '<STR_LIT>' , <EOL> pillar = build_pillar_data ( opts ) , <EOL> ) <EOL> ) <EOL> print ( '<STR_LIT>' . format ( cmd ) ) <EOL> sys . stdout . flush ( ) <EOL> proc = subprocess . Popen ( <EOL> cmd , <EOL> shell = True , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . STDOUT , <EOL> ) <EOL> stdout , stderr = proc . communicate ( ) <EOL> if stdout : <EOL> print ( '<STR_LIT>' ) <EOL> if stderr : <EOL> print ( salt . utils . to_str ( stderr ) ) <EOL> sys . stdout . flush ( ) <EOL> retcode = proc . returncode <EOL> if retcode != <NUM_LIT:0> : <EOL> print ( '<STR_LIT>' . format ( retcode ) ) <EOL> sys . stdout . flush ( ) <EOL> if opts . clean and '<STR_LIT>' not in os . environ : <EOL> delete_vm ( opts ) <EOL> sys . exit ( retcode ) <EOL> if opts . prep_sls_2 is not None : <EOL> sls_2_downtime = random . randint ( <NUM_LIT:3> , opts . splay ) <EOL> time . sleep ( sls_2_downtime ) <EOL> cmd = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( <EOL> prep_sls_2 = opts . prep_sls_2 , <EOL> pillar = build_pillar_data ( opts ) , <EOL> target = build_minion_target ( opts , vm_name ) , <EOL> ) <EOL> ) <EOL> print ( '<STR_LIT>' . format ( cmd ) ) <EOL> sys . stdout . flush ( ) <EOL> proc = subprocess . Popen ( <EOL> cmd , <EOL> shell = True , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . STDOUT , <EOL> ) <EOL> stdout , stderr = proc . communicate ( ) <EOL> if stdout : <EOL> print ( salt . utils . to_str ( stdout ) ) <EOL> if stderr : <EOL> print ( salt . utils . to_str ( stderr ) ) <EOL> sys . stdout . flush ( ) <EOL> retcode = proc . returncode <EOL> if retcode != <NUM_LIT:0> : <EOL> print ( '<STR_LIT>' . format ( retcode ) ) <EOL> sys . stdout . flush ( ) <EOL> if opts . clean and '<STR_LIT>' not in os . environ : <EOL> delete_vm ( opts ) <EOL> sys . exit ( retcode ) <EOL> if opts . test_git_url is not None : <EOL> test_git_downtime = random . randint ( <NUM_LIT:1> , opts . splay ) <EOL> time . sleep ( test_git_downtime ) <EOL> print ( '<STR_LIT>' ) <EOL> cmd = '<STR_LIT>' . format ( build_minion_target ( opts , vm_name ) ) <EOL> print ( '<STR_LIT>' . format ( cmd ) ) <EOL> sys . stdout . flush ( ) <EOL> proc = subprocess . Popen ( <EOL> cmd , <EOL> shell = True , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> ) <EOL> stdout , _ = proc . communicate ( ) <EOL> retcode = proc . returncode <EOL> if retcode != <NUM_LIT:0> : <EOL> print ( '<STR_LIT>' . format ( retcode ) ) <EOL> sys . stdout . flush ( ) <EOL> if opts . clean and '<STR_LIT>' not in os . environ : <EOL> delete_vm ( opts ) <EOL> sys . exit ( retcode ) <EOL> if not stdout : <EOL> print ( '<STR_LIT>' . format ( retcode ) ) <EOL> sys . stdout . flush ( ) <EOL> if opts . clean and '<STR_LIT>' not in os . environ : <EOL> delete_vm ( opts ) <EOL> sys . exit ( retcode ) <EOL> try : <EOL> remotes_info = json . loads ( stdout . strip ( ) ) <EOL> if remotes_info is None or remotes_info [ vm_name ] is None or opts . test_git_url not in remotes_info [ vm_name ] : <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' . format ( opts . test_git_url , remotes_info ) ) <EOL> sys . stdout . flush ( ) <EOL> if opts . clean and '<STR_LIT>' not in os . environ : <EOL> delete_vm ( opts ) <EOL> sys . exit ( retcode ) <EOL> print ( '<STR_LIT>' ) <EOL> except ValueError : <EOL> print ( '<STR_LIT>' . format ( salt . utils . to_str ( stdout ) . strip ( ) ) ) <EOL> if opts . test_git_commit is not None : <EOL> test_git_commit_downtime = random . randint ( <NUM_LIT:1> , opts . splay ) <EOL> time . sleep ( test_git_commit_downtime ) <EOL> print ( '<STR_LIT>' ) <EOL> cmd = '<STR_LIT>' . format ( build_minion_target ( opts , vm_name ) ) <EOL> print ( '<STR_LIT>' . format ( cmd ) ) <EOL> sys . stdout . flush ( ) <EOL> proc = subprocess . Popen ( <EOL> cmd , <EOL> shell = True , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> ) <EOL> stdout , _ = proc . communicate ( ) <EOL> sys . stdout . flush ( ) <EOL> retcode = proc . returncode <EOL> if retcode != <NUM_LIT:0> : <EOL> print ( '<STR_LIT>' . format ( retcode ) ) <EOL> sys . stdout . flush ( ) <EOL> if opts . clean and '<STR_LIT>' not in os . environ : <EOL> delete_vm ( opts ) <EOL> sys . exit ( retcode ) <EOL> if not stdout : <EOL> print ( '<STR_LIT>' . format ( retcode ) ) <EOL> sys . stdout . flush ( ) <EOL> if opts . clean and '<STR_LIT>' not in os . environ : <EOL> delete_vm ( opts ) <EOL> sys . exit ( retcode ) <EOL> try : <EOL> revision_info = json . loads ( stdout . strip ( ) ) <EOL> if revision_info [ vm_name ] [ <NUM_LIT:7> : ] != opts . test_git_commit [ <NUM_LIT:7> : ] : <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' . format ( revision_info [ vm_name ] [ : <NUM_LIT:7> ] , opts . test_git_commit [ : <NUM_LIT:7> ] ) ) <EOL> sys . stdout . flush ( ) <EOL> if opts . clean and '<STR_LIT>' not in os . environ : <EOL> delete_vm ( opts ) <EOL> sys . exit ( retcode ) <EOL> print ( '<STR_LIT>' ) <EOL> except ValueError : <EOL> print ( '<STR_LIT>' . format ( salt . utils . to_str ( stdout ) . strip ( ) ) ) <EOL> test_begin_downtime = random . randint ( <NUM_LIT:3> , opts . splay ) <EOL> time . sleep ( test_begin_downtime ) <EOL> cmd = ( <EOL> '<STR_LIT>' . format ( <EOL> sls = opts . sls , <EOL> pillar = build_pillar_data ( opts ) , <EOL> target = build_minion_target ( opts , vm_name ) , <EOL> ) <EOL> ) <EOL> print ( '<STR_LIT>' . format ( cmd ) ) <EOL> sys . stdout . flush ( ) <EOL> proc = subprocess . Popen ( <EOL> cmd , <EOL> shell = True , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> ) <EOL> stdout , stderr = proc . communicate ( ) <EOL> outstr = salt . utils . to_str ( stdout ) <EOL> if outstr : <EOL> print ( outstr ) <EOL> if stderr : <EOL> print ( salt . utils . to_str ( stderr ) ) <EOL> sys . stdout . flush ( ) <EOL> try : <EOL> match = re . search ( r'<STR_LIT>' , outstr ) <EOL> retcode = int ( match . group ( '<STR_LIT>' ) ) <EOL> except AttributeError : <EOL> retcode = <NUM_LIT:1> <EOL> except ValueError : <EOL> retcode = <NUM_LIT:1> <EOL> except TypeError : <EOL> retcode = <NUM_LIT:1> <EOL> if outstr : <EOL> raise <EOL> if retcode == <NUM_LIT:0> : <EOL> time . sleep ( <NUM_LIT:3> ) <EOL> cmd = ( <EOL> '<STR_LIT>' . format ( <EOL> pillar = build_pillar_data ( opts ) , <EOL> target = build_minion_target ( opts , vm_name ) , <EOL> ) <EOL> ) <EOL> print ( '<STR_LIT>' . format ( cmd ) ) <EOL> sys . stdout . flush ( ) <EOL> proc = subprocess . Popen ( <EOL> cmd , <EOL> shell = True , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> ) <EOL> stdout , stderr = proc . communicate ( ) <EOL> if stdout : <EOL> print ( salt . utils . to_str ( stdout ) ) <EOL> if stderr : <EOL> print ( salt . utils . to_str ( stderr ) ) <EOL> sys . stdout . flush ( ) <EOL> download_packages ( opts ) <EOL> if opts . download_remote_reports : <EOL> download_unittest_reports ( opts ) <EOL> if opts . test_without_coverage is False : <EOL> download_coverage_report ( opts ) <EOL> if opts . clean and '<STR_LIT>' not in os . environ : <EOL> delete_vm ( opts ) <EOL> return retcode <EOL> def parse ( ) : <EOL> '''<STR_LIT>''' <EOL> parser = optparse . OptionParser ( ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = os . environ . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> default = os . path . abspath ( <EOL> os . environ . get ( <EOL> '<STR_LIT>' , <EOL> os . path . dirname ( os . path . dirname ( __file__ ) ) <EOL> ) <EOL> ) , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = os . environ . get ( '<STR_LIT>' , None ) , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = os . environ . get ( '<STR_LIT>' , None ) , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = None , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = None , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = None , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = None , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> choices = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> help = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = False , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = None , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT>' , <EOL> nargs = <NUM_LIT:2> , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> default = True , <EOL> action = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = False , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> type = int , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = None , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = False , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = None , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = None , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT>' , <EOL> default = [ ] , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = None , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT>' , <EOL> default = [ ] , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = False , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = True , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> ) <EOL> parser . add_option ( <EOL> '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> options , args = parser . parse_args ( ) <EOL> if options . delete_vm is not None and not options . test_git_commit : <EOL> delete_vm ( options ) <EOL> parser . exit ( <NUM_LIT:0> ) <EOL> if options . download_unittest_reports is not None and not options . test_git_commit : <EOL> download_unittest_reports ( options ) <EOL> parser . exit ( <NUM_LIT:0> ) <EOL> if options . test_without_coverage is False : <EOL> if options . download_coverage_report is not None and not options . test_git_commit : <EOL> download_coverage_report ( options ) <EOL> parser . exit ( <NUM_LIT:0> ) <EOL> if options . download_remote_logs is not None and not options . test_git_commit : <EOL> download_remote_logs ( options ) <EOL> parser . exit ( <NUM_LIT:0> ) <EOL> if not options . platform and not options . pull_request : <EOL> parser . exit ( '<STR_LIT>' ) <EOL> if not options . provider and not options . pull_request : <EOL> parser . exit ( '<STR_LIT>' ) <EOL> if options . echo_parseable_environment : <EOL> echo_parseable_environment ( options , parser ) <EOL> parser . exit ( <NUM_LIT:0> ) <EOL> if not options . test_git_commit and not options . pull_request : <EOL> parser . exit ( '<STR_LIT>' ) <EOL> return options <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> exit_code = run ( parse ( ) ) <EOL> print ( '<STR_LIT>' . format ( exit_code ) ) <EOL> sys . exit ( exit_code ) </s>
