~abentley/ci-director/convert-to-gitbranch

« back to all changes in this revision

Viewing changes to cidirector/update_outcome.py

  • Committer: Aaron Bentley
  • Date: 2016-06-27 16:08:22 UTC
  • mfrom: (174.1.7 update-outcome-artifacts)
  • Revision ID: aaron.bentley@canonical.com-20160627160822-p513wa2a3l49h78e
Upload artifacts from update-outcome, not ci-director.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    SUCCESS,
29
29
)
30
30
from storage import (
 
31
    ArtifactJob,
31
32
    BUILDING,
32
33
    datetime_from_timestamp,
33
34
    FAILED,
41
42
    date_str,
42
43
    ensure_dir,
43
44
    locked_open_rw,
 
45
    S3Storage,
44
46
    )
45
47
 
46
48
 
56
58
    parser.add_argument('-v', '--verbose', help='Verbose info',
57
59
                        action='store_true')
58
60
    parser.add_argument('--log-path', help='Where to write logs.',
59
 
                        default='ci-director.log')
 
61
                        default='update-outcome.log')
60
62
    parser.add_argument('--log-count', help='The number of backups to keep.',
61
63
                        default=2, type=int)
62
64
    return parser.parse_args()
642
644
        self.write_json(mongo_name, mongo_data, make_dir=True)
643
645
 
644
646
 
 
647
def upload_artifacts(jenkins, by_revision_build, s3_storage):
 
648
    """Upload the artifacts for newly-completed builds.
 
649
 
 
650
    by_revision_build should not include previously-uploaded builds, to avoid
 
651
    unnecessary re-uploads.
 
652
 
 
653
    Builds that do not have a result are not uploaded.  They lack artifacts,
 
654
    because that is a post-build action, and they have incomplete console
 
655
    logs, which could confuse other tools.
 
656
    """
 
657
    logger = logging.getLogger()
 
658
    for revision_build, jobs in by_revision_build.items():
 
659
        for job, job_data in jobs.items():
 
660
            artifact_job = ArtifactJob(job, logger)
 
661
            for build_info in job_data['builds'].values():
 
662
                if build_info['result'] is None:
 
663
                    logger.info(
 
664
                        'No result for {} #{}.  Skipping.'.format(
 
665
                            job, build_info['number']))
 
666
                    continue
 
667
                logger.info(
 
668
                    'Uploading artifacts for {} #{}'.format(
 
669
                        job, build_info['number']))
 
670
                artifact_job.archive_results(
 
671
                    jenkins, build_info, revision_build, s3_storage)
 
672
 
 
673
 
645
674
def main():
646
675
    """Entry point for update-outcome script."""
647
676
    args = parse_args()
649
678
    config = ConfigReader.read_config()
650
679
    setdefaulttimeout(30)
651
680
    jenkins = make_jenkins(config)
 
681
    s3_storage = S3Storage.from_config(config)
652
682
    outcome_dir = os.path.join(os.environ['HOME'],
653
683
                               '.config/ci-director-outcome')
654
684
    with OutcomeState(outcome_dir) as state:
655
685
        by_revision_build, cloud_health, new_last_completed = scan_new_builds(
656
686
            state.data, jenkins)
 
687
        upload_artifacts(jenkins, by_revision_build, s3_storage)
657
688
        cloud_health_builds = BuildFiles.for_cloud_health(state)
658
689
        list(cloud_health_builds.update_files(cloud_health))
659
690
        revision_build_files = BuildFiles.for_revision_builds(state)