1 # Copyright 2016 The Chromium Authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 6 # Recipe for uploading DM results. 7 8 9 import calendar 10 11 12 DEPS = [ 13 'recipe_engine/file', 14 'recipe_engine/json', 15 'recipe_engine/path', 16 'recipe_engine/properties', 17 'recipe_engine/step', 18 'recipe_engine/time', 19 'gsutil', 20 ] 21 22 23 GS_BUCKET_IMAGES = 'skia-infra-gm' 24 DM_JSON = 'dm.json' 25 VERBOSE_LOG = 'verbose.log' 26 27 28 def RunSteps(api): 29 builder_name = api.properties['buildername'] 30 revision = api.properties['revision'] 31 32 results_dir = api.path['start_dir'].join('dm') 33 34 # Move dm.json and verbose.log to their own directory. 35 json_file = results_dir.join(DM_JSON) 36 log_file = results_dir.join(VERBOSE_LOG) 37 tmp_dir = api.path['start_dir'].join('tmp_upload') 38 api.file.ensure_directory('makedirs tmp dir', tmp_dir) 39 api.file.copy('copy dm.json', json_file, tmp_dir) 40 api.file.copy('copy verbose.log', log_file, tmp_dir) 41 api.file.remove('rm old dm.json', json_file) 42 api.file.remove('rm old verbose.log', log_file) 43 44 # Upload the images. 45 image_dest_path = 'gs://%s/dm-images-v1' % GS_BUCKET_IMAGES 46 for ext in ['.png', '.pdf']: 47 files_to_upload = api.file.glob_paths( 48 'find images', 49 results_dir, 50 '*%s' % ext, 51 test_data=['someimage.png']) 52 # For some reason, glob returns results_dir when it should return nothing. 53 files_to_upload = [f for f in files_to_upload if str(f).endswith(ext)] 54 if len(files_to_upload) > 0: 55 api.gsutil.cp('images', results_dir.join('*%s' % ext), 56 image_dest_path, multithread=True) 57 58 # Upload the JSON summary and verbose.log. 59 now = api.time.utcnow() 60 summary_dest_path = '/'.join([ 61 'dm-json-v1', 62 str(now.year ).zfill(4), 63 str(now.month).zfill(2), 64 str(now.day ).zfill(2), 65 str(now.hour ).zfill(2), 66 revision, 67 builder_name, 68 str(int(calendar.timegm(now.utctimetuple())))]) 69 70 # Trybot results are further siloed by issue/patchset. 71 issue = api.properties.get('patch_issue') 72 patchset = api.properties.get('patch_set') 73 if issue and patchset: 74 summary_dest_path = '/'.join(( 75 'trybot', summary_dest_path, str(issue), str(patchset))) 76 77 summary_dest_path = 'gs://%s/%s' % (api.properties['gs_bucket'], 78 summary_dest_path) 79 80 api.gsutil.cp('JSON and logs', tmp_dir.join('*'), summary_dest_path, 81 extra_args=['-z', 'json,log']) 82 83 84 def GenTests(api): 85 builder = 'Test-Debian9-GCC-GCE-CPU-AVX2-x86_64-Debug' 86 yield ( 87 api.test('normal_bot') + 88 api.properties(buildername=builder, 89 gs_bucket='skia-infra-gm', 90 revision='abc123', 91 path_config='kitchen') 92 ) 93 94 yield ( 95 api.test('alternate_bucket') + 96 api.properties(buildername=builder, 97 gs_bucket='skia-infra-gm-alt', 98 revision='abc123', 99 path_config='kitchen') 100 ) 101 102 yield ( 103 api.test('failed_once') + 104 api.properties(buildername=builder, 105 gs_bucket='skia-infra-gm', 106 revision='abc123', 107 path_config='kitchen') + 108 api.step_data('upload images', retcode=1) 109 ) 110 111 yield ( 112 api.test('failed_all') + 113 api.properties(buildername=builder, 114 gs_bucket='skia-infra-gm', 115 revision='abc123', 116 path_config='kitchen') + 117 api.step_data('upload images', retcode=1) + 118 api.step_data('upload images (attempt 2)', retcode=1) + 119 api.step_data('upload images (attempt 3)', retcode=1) + 120 api.step_data('upload images (attempt 4)', retcode=1) + 121 api.step_data('upload images (attempt 5)', retcode=1) 122 ) 123 124 yield ( 125 api.test('trybot') + 126 api.properties( 127 buildername=builder, 128 gs_bucket='skia-infra-gm', 129 revision='abc123', 130 path_config='kitchen', 131 patch_storage='gerrit') + 132 api.properties.tryserver( 133 buildername=builder, 134 gerrit_project='skia', 135 gerrit_url='https://skia-review.googlesource.com/', 136 ) 137 ) 138