~sinzui/juju-ci-tools/cloudsigma-lib

« back to all changes in this revision

Viewing changes to jujuci.py

  • Committer: Nate Finch
  • Date: 2015-06-02 03:47:22 UTC
  • mfrom: (968 origin/trunk)
  • mto: This revision was merged to the branch mainline in revision 976.
  • Revision ID: nate.finch@canonical.com-20150602034722-cr3lzq2yb6xdh7gz
merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
120
120
    return get_jenkins_json(credentials, artifact.location)
121
121
 
122
122
 
 
123
def get_buildvars(credentials, build_number, summary=False, env='unknown',
 
124
                  revision_build=False, version=False, branch=False,
 
125
                  short_branch=False, revision=False, short_revision=False):
 
126
    """Return requested information as text.
 
127
 
 
128
    The 'summary' kwarg returns intelligible information about the build.
 
129
    'env' is included in the summary text. Otherwise, a space-separated
 
130
    string composed of the each True kwarg is returned in this order:
 
131
        revision_build version short_branch short_revision branch revision
 
132
    Note that revision_build is always the same as build number;
 
133
    build_number can be an alias like 'lastBuild' or 'lastSuccessfulBuild'.
 
134
    """
 
135
    buildvars = retrieve_buildvars(credentials, build_number)
 
136
    buildvars['short_revision_id'] = buildvars['revision_id'][0:7]
 
137
    buildvars['short_branch'] = buildvars['branch'].split(':')[1]
 
138
    buildvars['env'] = env
 
139
    template = (
 
140
        'Testing {branch} {short_revision_id} on {env} for {revision_build}')
 
141
    if summary:
 
142
        text = template.format(**buildvars)
 
143
    else:
 
144
        data = []
 
145
        if revision_build:
 
146
            data.append(buildvars['revision_build'])
 
147
        if version:
 
148
            data.append(buildvars['version'])
 
149
        if short_branch:
 
150
            data.append(buildvars['short_branch'])
 
151
        if short_revision:
 
152
            data.append(buildvars['short_revision_id'])
 
153
        if branch:
 
154
            data.append(buildvars['branch'])
 
155
        if revision:
 
156
            data.append(buildvars['revision_id'])
 
157
        text = ' '.join(data)
 
158
    return text
 
159
 
 
160
 
123
161
def get_release_package_filename(credentials, build_data):
124
162
    revision_build = get_revision_build(build_data)
125
163
    version = retrieve_buildvars(credentials, revision_build)['version']
305
343
        'workspace', nargs='?', default='.',
306
344
        help='The place to store binaries.')
307
345
    add_credential_args(parser_get_certification_bin)
 
346
    parser_get_buildvars = subparsers.add_parser(
 
347
        'get-build-vars',
 
348
        help='Retrieve the build-vars for a build-revision.')
 
349
    parser_get_buildvars.add_argument(
 
350
        '--env', default='Unknown',
 
351
        help='The env name to include in the summary')
 
352
    parser_get_buildvars.add_argument(
 
353
        '--summary', action='store_true', default=False,
 
354
        help='Summarise the build var test data')
 
355
    parser_get_buildvars.add_argument(
 
356
        '--revision-build', action='store_true', default=False,
 
357
        help='Print the test revision build number')
 
358
    parser_get_buildvars.add_argument(
 
359
        '--version', action='store_true', default=False,
 
360
        help='Print the test juju version')
 
361
    parser_get_buildvars.add_argument(
 
362
        '--short-branch', action='store_true', default=False,
 
363
        help='Print the short name of the branch')
 
364
    parser_get_buildvars.add_argument(
 
365
        '--short-revision', action='store_true', default=False,
 
366
        help='Print the short revision of the branch')
 
367
    parser_get_buildvars.add_argument(
 
368
        '--branch', action='store_true', default=False,
 
369
        help='Print the test branch')
 
370
    parser_get_buildvars.add_argument(
 
371
        '--revision', action='store_true', default=False,
 
372
        help='Print the test revision')
 
373
    parser_get_buildvars.add_argument(
 
374
        'build', help='The build-revision build number')
 
375
    add_credential_args(parser_get_buildvars)
308
376
    parsed_args = parser.parse_args(args)
 
377
    if parsed_args.command == 'get-build-vars' and True not in (
 
378
            parsed_args.summary, parsed_args.revision_build,
 
379
            parsed_args.version, parsed_args.revision,
 
380
            parsed_args.short_branch, parsed_args.short_revision,
 
381
            parsed_args.branch, parsed_args.revision):
 
382
        parser_get_buildvars.error(
 
383
            'Expected --summary or one or more of: --revision-build, '
 
384
            '--version, --revision, --short-branch, --short-revision, '
 
385
            '--branch, --revision')
309
386
    credentials = get_credentials(parsed_args)
310
387
    return parsed_args, credentials
311
388
 
370
447
            path = get_certification_bin(credentials, args.version,
371
448
                                         args.workspace)
372
449
            print(path)
 
450
        elif args.command == 'get-build-vars':
 
451
            text = get_buildvars(
 
452
                credentials, args.build, env=args.env,
 
453
                summary=args.summary, revision_build=args.revision_build,
 
454
                version=args.version, short_branch=args.short_branch,
 
455
                short_revision=args.short_revision,
 
456
                branch=args.branch, revision=args.revision)
 
457
            print(text)
373
458
    except Exception as e:
374
459
        print(e)
375
460
        if args.verbose: