Example #1
0
def get_data(context, id, keys):
    """get_data(context, id, keys)

    Retrieve data field from a remoteci.

    >>> dcictl remoteci-get-data [OPTIONS]

    :param string id: ID of the remote CI to show [required]
    :param string id: Keys of the data field to retrieve [optional]
    """

    if keys:
        keys = keys.split(',')
    result = remoteci.get_data(context, id=id, keys=keys)
    utils.format_output(result, context.format, None, keys)
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)
Example #3
0
def get_data(context, args):
    keys = args.keys.split(",") if args.keys else args.keys
    return remoteci.get_data(context, id=args.id, keys=keys)