def push_stack_details(context, undercloud, stack_name='overcloud'): undercloud.yum_install(['git']) repo_url = 'https://github.com/goneri/tripleo-stack-dump' undercloud.run( 'test -d tripleo-stack-dump || git clone ' + repo_url, user='******') undercloud.add_environment_file( user='******', filename='stackrc') undercloud.run( './tripleo-stack-dump/list_nodes_status', user='******') undercloud.run( './tripleo-stack-dump/tripleo-stack-dump ' + stack_name, user='******') with undercloud.open('/home/stack/tripleo-stack-dump.json') as fd: j = job.get( context, id=context.last_job_id).json()['job'] job.update( context, id=context.last_job_id, etag=j['etag'], configuration=json.load(fd))
def run_tests(context, undercloud_ip, key_filename, remoteci_id, user='******', stack_name='overcloud'): # Retrieve the certification_id data field. In order to run # the rhcert test suite if enabled. If absent set to empty string. data = remoteci.get_data( context, remoteci_id, ['certification_id']).json() certification_id = data and data.get('certification_id', '') # redirect the log messages to the DCI Control Server # https://github.com/shazow/urllib3/issues/523 requests.packages.urllib3.disable_warnings() dci_handler = DciHandler(context) logger = logging.getLogger('tripleohelper') logger.addHandler(dci_handler) undercloud = tripleohelper.undercloud.Undercloud( hostname=undercloud_ip, user=user, key_filename=key_filename) undercloud.create_stack_user() final_status = 'success' if undercloud.run( 'test -f stackrc', user='******', success_status=(0, 1,))[1] != 0: msg = 'undercloud deployment failure' jobstate.create(context, 'failure', msg, context.last_job_id) return jobstate.create( context, 'running', 'Running tripleo-stack-dump', context.last_job_id) push_stack_details(context, undercloud, stack_name=stack_name) rcfile = stack_name + 'rc' if undercloud.run( 'test -f ' + rcfile, user='******', success_status=(0, 1,))[1] != 0: msg = 'overcloud deployment failure' jobstate.create(context, 'failure', msg, context.last_job_id) return tests = job.list_tests(context, context.last_job_id).json()['tests'] try: for t in tests['tests']: if 'url' not in t['data']: continue jobstate.create( context, 'running', 'Running test ' + t['name'], context.last_job_id) url = t['data']['url'] undercloud.add_environment_file( user='******', filename=rcfile) undercloud.run('curl -O ' + url, user='******') undercloud.run(( 'DCI_CERTIFICATION_ID=%s ' 'DCI_REMOTECI_ID=%s ' 'DCI_JOB_ID=%s ' 'DCI_OVERCLOUD_STACK_NAME=%s ' 'bash -x run.sh') % ( certification_id, remoteci_id, context.last_job_id, stack_name), user='******') with undercloud.open('result.xml', user='******') as fd: file.create( context, t['name'], fd.read(), mime='application/junit', job_id=context.last_job_id) except Exception: msg = traceback.format_exc() final_status = 'failure' print(msg) else: msg = 'test(s) success' dci_handler.emit(None) jobstate.create(context, final_status, msg, context.last_job_id)