Nicolas Borla
/
BBR_1Ebene
BBR 1 Ebene
mbed-os/tools/upload_results.py@0:fbdae7e6d805, 2018-05-14 (annotated)
- Committer:
- borlanic
- Date:
- Mon May 14 11:29:06 2018 +0000
- Revision:
- 0:fbdae7e6d805
BBR
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:fbdae7e6d805 | 1 | """ |
borlanic | 0:fbdae7e6d805 | 2 | mbed SDK |
borlanic | 0:fbdae7e6d805 | 3 | Copyright (c) 2011-2013 ARM Limited |
borlanic | 0:fbdae7e6d805 | 4 | |
borlanic | 0:fbdae7e6d805 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
borlanic | 0:fbdae7e6d805 | 6 | you may not use this file except in compliance with the License. |
borlanic | 0:fbdae7e6d805 | 7 | You may obtain a copy of the License at |
borlanic | 0:fbdae7e6d805 | 8 | |
borlanic | 0:fbdae7e6d805 | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
borlanic | 0:fbdae7e6d805 | 10 | |
borlanic | 0:fbdae7e6d805 | 11 | Unless required by applicable law or agreed to in writing, software |
borlanic | 0:fbdae7e6d805 | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
borlanic | 0:fbdae7e6d805 | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
borlanic | 0:fbdae7e6d805 | 14 | See the License for the specific language governing permissions and |
borlanic | 0:fbdae7e6d805 | 15 | limitations under the License. |
borlanic | 0:fbdae7e6d805 | 16 | """ |
borlanic | 0:fbdae7e6d805 | 17 | import sys |
borlanic | 0:fbdae7e6d805 | 18 | import argparse |
borlanic | 0:fbdae7e6d805 | 19 | import xml.etree.ElementTree as ET |
borlanic | 0:fbdae7e6d805 | 20 | import requests |
borlanic | 0:fbdae7e6d805 | 21 | import urlparse |
borlanic | 0:fbdae7e6d805 | 22 | |
borlanic | 0:fbdae7e6d805 | 23 | def create_headers(args): |
borlanic | 0:fbdae7e6d805 | 24 | return { 'X-Api-Key': args.api_key } |
borlanic | 0:fbdae7e6d805 | 25 | |
borlanic | 0:fbdae7e6d805 | 26 | def finish_command(command, response): |
borlanic | 0:fbdae7e6d805 | 27 | print(command, response.status_code, response.reason) |
borlanic | 0:fbdae7e6d805 | 28 | print(response.text) |
borlanic | 0:fbdae7e6d805 | 29 | |
borlanic | 0:fbdae7e6d805 | 30 | if response.status_code < 400: |
borlanic | 0:fbdae7e6d805 | 31 | sys.exit(0) |
borlanic | 0:fbdae7e6d805 | 32 | else: |
borlanic | 0:fbdae7e6d805 | 33 | sys.exit(2) |
borlanic | 0:fbdae7e6d805 | 34 | |
borlanic | 0:fbdae7e6d805 | 35 | def create_build(args): |
borlanic | 0:fbdae7e6d805 | 36 | build = {} |
borlanic | 0:fbdae7e6d805 | 37 | build['buildType'] = args.build_type |
borlanic | 0:fbdae7e6d805 | 38 | build['number'] = args.build_number |
borlanic | 0:fbdae7e6d805 | 39 | build['source'] = args.build_source |
borlanic | 0:fbdae7e6d805 | 40 | build['status'] = 'running' |
borlanic | 0:fbdae7e6d805 | 41 | |
borlanic | 0:fbdae7e6d805 | 42 | r = requests.post(urlparse.urljoin(args.url, "api/builds"), headers=create_headers(args), json=build) |
borlanic | 0:fbdae7e6d805 | 43 | |
borlanic | 0:fbdae7e6d805 | 44 | if r.status_code < 400: |
borlanic | 0:fbdae7e6d805 | 45 | if args.property_file_format: |
borlanic | 0:fbdae7e6d805 | 46 | print("MBED_BUILD_ID=" + r.text) |
borlanic | 0:fbdae7e6d805 | 47 | else: |
borlanic | 0:fbdae7e6d805 | 48 | print(r.text) |
borlanic | 0:fbdae7e6d805 | 49 | |
borlanic | 0:fbdae7e6d805 | 50 | sys.exit(0) |
borlanic | 0:fbdae7e6d805 | 51 | else: |
borlanic | 0:fbdae7e6d805 | 52 | sys.exit(2) |
borlanic | 0:fbdae7e6d805 | 53 | |
borlanic | 0:fbdae7e6d805 | 54 | def finish_build(args): |
borlanic | 0:fbdae7e6d805 | 55 | data = {} |
borlanic | 0:fbdae7e6d805 | 56 | data['status'] = 'completed' |
borlanic | 0:fbdae7e6d805 | 57 | |
borlanic | 0:fbdae7e6d805 | 58 | r = requests.put(urlparse.urljoin(args.url, "api/builds/" + args.build_id), headers=create_headers(args), json=data) |
borlanic | 0:fbdae7e6d805 | 59 | finish_command('finish-build', r) |
borlanic | 0:fbdae7e6d805 | 60 | |
borlanic | 0:fbdae7e6d805 | 61 | def promote_build(args): |
borlanic | 0:fbdae7e6d805 | 62 | data = {} |
borlanic | 0:fbdae7e6d805 | 63 | data['buildType'] = 'Release' |
borlanic | 0:fbdae7e6d805 | 64 | |
borlanic | 0:fbdae7e6d805 | 65 | r = requests.put(urlparse.urljoin(args.url, "api/builds/" + args.build_id), headers=create_headers(args), json=data) |
borlanic | 0:fbdae7e6d805 | 66 | finish_command('promote-build', r) |
borlanic | 0:fbdae7e6d805 | 67 | |
borlanic | 0:fbdae7e6d805 | 68 | def abort_build(args): |
borlanic | 0:fbdae7e6d805 | 69 | data = {} |
borlanic | 0:fbdae7e6d805 | 70 | data['status'] = 'aborted' |
borlanic | 0:fbdae7e6d805 | 71 | |
borlanic | 0:fbdae7e6d805 | 72 | r = requests.put(urlparse.urljoin(args.url, "api/builds/" + args.build_id), headers=create_headers(args), json=data) |
borlanic | 0:fbdae7e6d805 | 73 | finish_command('abort-build', r) |
borlanic | 0:fbdae7e6d805 | 74 | |
borlanic | 0:fbdae7e6d805 | 75 | def add_project_runs(args): |
borlanic | 0:fbdae7e6d805 | 76 | ''' |
borlanic | 0:fbdae7e6d805 | 77 | ------------------------------------- |
borlanic | 0:fbdae7e6d805 | 78 | Notes on 'project_run_data' structure: |
borlanic | 0:fbdae7e6d805 | 79 | -------------------------------------- |
borlanic | 0:fbdae7e6d805 | 80 | 'projectRuns' - Tree structure used to keep track of what projects have |
borlanic | 0:fbdae7e6d805 | 81 | been logged in different report files. The tree is organized as follows: |
borlanic | 0:fbdae7e6d805 | 82 | |
borlanic | 0:fbdae7e6d805 | 83 | 'projectRuns': { - Root element of tree |
borlanic | 0:fbdae7e6d805 | 84 | |
borlanic | 0:fbdae7e6d805 | 85 | 'hostOs': { - Host OS on which project was built/tested |
borlanic | 0:fbdae7e6d805 | 86 | - ex. windows, linux, or mac |
borlanic | 0:fbdae7e6d805 | 87 | |
borlanic | 0:fbdae7e6d805 | 88 | 'platform': { - Platform for which project was built/tested |
borlanic | 0:fbdae7e6d805 | 89 | (Corresponds to platform names in targets.py) |
borlanic | 0:fbdae7e6d805 | 90 | - ex. K64F, LPC1768, NRF51822, etc. |
borlanic | 0:fbdae7e6d805 | 91 | |
borlanic | 0:fbdae7e6d805 | 92 | 'toolchain': { - Toolchain with which project was built/tested |
borlanic | 0:fbdae7e6d805 | 93 | (Corresponds to TOOLCHAIN_CLASSES names in toolchains/__init__.py) |
borlanic | 0:fbdae7e6d805 | 94 | - ex. ARM, uARM, GCC_ARM, etc. |
borlanic | 0:fbdae7e6d805 | 95 | |
borlanic | 0:fbdae7e6d805 | 96 | 'project': { - Project that was build/tested |
borlanic | 0:fbdae7e6d805 | 97 | (Corresponds to test id in tests.py or library id in libraries.py) |
borlanic | 0:fbdae7e6d805 | 98 | - For tests, ex. MBED_A1, MBED_11, DTCT_1 etc. |
borlanic | 0:fbdae7e6d805 | 99 | - For libraries, ex. MBED, RTX, RTOS, etc. |
borlanic | 0:fbdae7e6d805 | 100 | |
borlanic | 0:fbdae7e6d805 | 101 | }, |
borlanic | 0:fbdae7e6d805 | 102 | ... |
borlanic | 0:fbdae7e6d805 | 103 | }, |
borlanic | 0:fbdae7e6d805 | 104 | ... |
borlanic | 0:fbdae7e6d805 | 105 | }, |
borlanic | 0:fbdae7e6d805 | 106 | ... |
borlanic | 0:fbdae7e6d805 | 107 | } |
borlanic | 0:fbdae7e6d805 | 108 | } |
borlanic | 0:fbdae7e6d805 | 109 | |
borlanic | 0:fbdae7e6d805 | 110 | 'platforms_set' - Set of all the platform names mentioned in the given report files |
borlanic | 0:fbdae7e6d805 | 111 | |
borlanic | 0:fbdae7e6d805 | 112 | 'toolchains_set' - Set of all the toolchain names mentioned in the given report files |
borlanic | 0:fbdae7e6d805 | 113 | |
borlanic | 0:fbdae7e6d805 | 114 | 'names_set' - Set of all the project names mentioned in the given report files |
borlanic | 0:fbdae7e6d805 | 115 | |
borlanic | 0:fbdae7e6d805 | 116 | 'hostOses_set' - Set of all the host names given (only given by the command line arguments) |
borlanic | 0:fbdae7e6d805 | 117 | ''' |
borlanic | 0:fbdae7e6d805 | 118 | |
borlanic | 0:fbdae7e6d805 | 119 | project_run_data = {} |
borlanic | 0:fbdae7e6d805 | 120 | project_run_data['projectRuns'] = {} |
borlanic | 0:fbdae7e6d805 | 121 | project_run_data['platforms_set'] = set() |
borlanic | 0:fbdae7e6d805 | 122 | project_run_data['vendors_set'] = set() |
borlanic | 0:fbdae7e6d805 | 123 | project_run_data['toolchains_set'] = set() |
borlanic | 0:fbdae7e6d805 | 124 | project_run_data['names_set'] = set() |
borlanic | 0:fbdae7e6d805 | 125 | project_run_data['hostOses_set'] = set() |
borlanic | 0:fbdae7e6d805 | 126 | project_run_data['hostOses_set'].add(args.host_os) |
borlanic | 0:fbdae7e6d805 | 127 | |
borlanic | 0:fbdae7e6d805 | 128 | if args.build_report: |
borlanic | 0:fbdae7e6d805 | 129 | add_report(project_run_data, args.build_report, True, args.build_id, args.host_os) |
borlanic | 0:fbdae7e6d805 | 130 | |
borlanic | 0:fbdae7e6d805 | 131 | if args.test_report: |
borlanic | 0:fbdae7e6d805 | 132 | add_report(project_run_data, args.test_report, False, args.build_id, args.host_os) |
borlanic | 0:fbdae7e6d805 | 133 | |
borlanic | 0:fbdae7e6d805 | 134 | ts_data = format_project_run_data(project_run_data, args.limit) |
borlanic | 0:fbdae7e6d805 | 135 | total_result = True |
borlanic | 0:fbdae7e6d805 | 136 | |
borlanic | 0:fbdae7e6d805 | 137 | total_parts = len(ts_data) |
borlanic | 0:fbdae7e6d805 | 138 | print "Uploading project runs in %d parts" % total_parts |
borlanic | 0:fbdae7e6d805 | 139 | |
borlanic | 0:fbdae7e6d805 | 140 | for index, data in enumerate(ts_data): |
borlanic | 0:fbdae7e6d805 | 141 | r = requests.post(urlparse.urljoin(args.url, "api/projectRuns"), headers=create_headers(args), json=data) |
borlanic | 0:fbdae7e6d805 | 142 | print("add-project-runs part %d/%d" % (index + 1, total_parts), r.status_code, r.reason) |
borlanic | 0:fbdae7e6d805 | 143 | print(r.text) |
borlanic | 0:fbdae7e6d805 | 144 | |
borlanic | 0:fbdae7e6d805 | 145 | if r.status_code >= 400: |
borlanic | 0:fbdae7e6d805 | 146 | total_result = False |
borlanic | 0:fbdae7e6d805 | 147 | |
borlanic | 0:fbdae7e6d805 | 148 | if total_result: |
borlanic | 0:fbdae7e6d805 | 149 | print "'add-project-runs' completed successfully" |
borlanic | 0:fbdae7e6d805 | 150 | sys.exit(0) |
borlanic | 0:fbdae7e6d805 | 151 | else: |
borlanic | 0:fbdae7e6d805 | 152 | print "'add-project-runs' failed" |
borlanic | 0:fbdae7e6d805 | 153 | sys.exit(2) |
borlanic | 0:fbdae7e6d805 | 154 | |
borlanic | 0:fbdae7e6d805 | 155 | def prep_ts_data(): |
borlanic | 0:fbdae7e6d805 | 156 | ts_data = {} |
borlanic | 0:fbdae7e6d805 | 157 | ts_data['projectRuns'] = [] |
borlanic | 0:fbdae7e6d805 | 158 | ts_data['platforms'] = set() |
borlanic | 0:fbdae7e6d805 | 159 | ts_data['vendors'] = set() |
borlanic | 0:fbdae7e6d805 | 160 | ts_data['toolchains'] = set() |
borlanic | 0:fbdae7e6d805 | 161 | ts_data['names'] = set() |
borlanic | 0:fbdae7e6d805 | 162 | ts_data['hostOses'] = set() |
borlanic | 0:fbdae7e6d805 | 163 | return ts_data |
borlanic | 0:fbdae7e6d805 | 164 | |
borlanic | 0:fbdae7e6d805 | 165 | def finish_ts_data(ts_data, project_run_data): |
borlanic | 0:fbdae7e6d805 | 166 | ts_data['platforms'] = list(ts_data['platforms']) |
borlanic | 0:fbdae7e6d805 | 167 | ts_data['vendors'] = list(ts_data['vendors']) |
borlanic | 0:fbdae7e6d805 | 168 | ts_data['toolchains'] = list(ts_data['toolchains']) |
borlanic | 0:fbdae7e6d805 | 169 | ts_data['names'] = list(ts_data['names']) |
borlanic | 0:fbdae7e6d805 | 170 | ts_data['hostOses'] = list(ts_data['hostOses']) |
borlanic | 0:fbdae7e6d805 | 171 | |
borlanic | 0:fbdae7e6d805 | 172 | # Add all vendors to every projectRun submission |
borlanic | 0:fbdae7e6d805 | 173 | # TODO Either add "vendor" to the "project_run_data" |
borlanic | 0:fbdae7e6d805 | 174 | # or remove "vendor" entirely from the viewer |
borlanic | 0:fbdae7e6d805 | 175 | ts_data['vendors'] = list(project_run_data['vendors_set']) |
borlanic | 0:fbdae7e6d805 | 176 | |
borlanic | 0:fbdae7e6d805 | 177 | def format_project_run_data(project_run_data, limit): |
borlanic | 0:fbdae7e6d805 | 178 | all_ts_data = [] |
borlanic | 0:fbdae7e6d805 | 179 | current_limit_count = 0 |
borlanic | 0:fbdae7e6d805 | 180 | |
borlanic | 0:fbdae7e6d805 | 181 | ts_data = prep_ts_data() |
borlanic | 0:fbdae7e6d805 | 182 | ts_data['projectRuns'] = [] |
borlanic | 0:fbdae7e6d805 | 183 | |
borlanic | 0:fbdae7e6d805 | 184 | for hostOs_name, hostOs in project_run_data['projectRuns'].items(): |
borlanic | 0:fbdae7e6d805 | 185 | for platform_name, platform in hostOs.items(): |
borlanic | 0:fbdae7e6d805 | 186 | for toolchain_name, toolchain in platform.items(): |
borlanic | 0:fbdae7e6d805 | 187 | for project_name, project in toolchain.items(): |
borlanic | 0:fbdae7e6d805 | 188 | if current_limit_count >= limit: |
borlanic | 0:fbdae7e6d805 | 189 | finish_ts_data(ts_data, project_run_data) |
borlanic | 0:fbdae7e6d805 | 190 | all_ts_data.append(ts_data) |
borlanic | 0:fbdae7e6d805 | 191 | ts_data = prep_ts_data() |
borlanic | 0:fbdae7e6d805 | 192 | current_limit_count = 0 |
borlanic | 0:fbdae7e6d805 | 193 | |
borlanic | 0:fbdae7e6d805 | 194 | ts_data['projectRuns'].append(project) |
borlanic | 0:fbdae7e6d805 | 195 | ts_data['platforms'].add(platform_name) |
borlanic | 0:fbdae7e6d805 | 196 | ts_data['toolchains'].add(toolchain_name) |
borlanic | 0:fbdae7e6d805 | 197 | ts_data['names'].add(project_name) |
borlanic | 0:fbdae7e6d805 | 198 | ts_data['hostOses'].add(hostOs_name) |
borlanic | 0:fbdae7e6d805 | 199 | current_limit_count += 1 |
borlanic | 0:fbdae7e6d805 | 200 | |
borlanic | 0:fbdae7e6d805 | 201 | if current_limit_count > 0: |
borlanic | 0:fbdae7e6d805 | 202 | finish_ts_data(ts_data, project_run_data) |
borlanic | 0:fbdae7e6d805 | 203 | all_ts_data.append(ts_data) |
borlanic | 0:fbdae7e6d805 | 204 | |
borlanic | 0:fbdae7e6d805 | 205 | return all_ts_data |
borlanic | 0:fbdae7e6d805 | 206 | |
borlanic | 0:fbdae7e6d805 | 207 | def find_project_run(projectRuns, project): |
borlanic | 0:fbdae7e6d805 | 208 | keys = ['hostOs', 'platform', 'toolchain', 'project'] |
borlanic | 0:fbdae7e6d805 | 209 | |
borlanic | 0:fbdae7e6d805 | 210 | elem = projectRuns |
borlanic | 0:fbdae7e6d805 | 211 | |
borlanic | 0:fbdae7e6d805 | 212 | for key in keys: |
borlanic | 0:fbdae7e6d805 | 213 | if not project[key] in elem: |
borlanic | 0:fbdae7e6d805 | 214 | return None |
borlanic | 0:fbdae7e6d805 | 215 | |
borlanic | 0:fbdae7e6d805 | 216 | elem = elem[project[key]] |
borlanic | 0:fbdae7e6d805 | 217 | |
borlanic | 0:fbdae7e6d805 | 218 | return elem |
borlanic | 0:fbdae7e6d805 | 219 | |
borlanic | 0:fbdae7e6d805 | 220 | def add_project_run(projectRuns, project): |
borlanic | 0:fbdae7e6d805 | 221 | keys = ['hostOs', 'platform', 'toolchain'] |
borlanic | 0:fbdae7e6d805 | 222 | |
borlanic | 0:fbdae7e6d805 | 223 | elem = projectRuns |
borlanic | 0:fbdae7e6d805 | 224 | |
borlanic | 0:fbdae7e6d805 | 225 | for key in keys: |
borlanic | 0:fbdae7e6d805 | 226 | if not project[key] in elem: |
borlanic | 0:fbdae7e6d805 | 227 | elem[project[key]] = {} |
borlanic | 0:fbdae7e6d805 | 228 | |
borlanic | 0:fbdae7e6d805 | 229 | elem = elem[project[key]] |
borlanic | 0:fbdae7e6d805 | 230 | |
borlanic | 0:fbdae7e6d805 | 231 | elem[project['project']] = project |
borlanic | 0:fbdae7e6d805 | 232 | |
borlanic | 0:fbdae7e6d805 | 233 | def update_project_run_results(project_to_update, project, is_build): |
borlanic | 0:fbdae7e6d805 | 234 | if is_build: |
borlanic | 0:fbdae7e6d805 | 235 | project_to_update['buildPass'] = project['buildPass'] |
borlanic | 0:fbdae7e6d805 | 236 | project_to_update['buildResult'] = project['buildResult'] |
borlanic | 0:fbdae7e6d805 | 237 | project_to_update['buildOutput'] = project['buildOutput'] |
borlanic | 0:fbdae7e6d805 | 238 | else: |
borlanic | 0:fbdae7e6d805 | 239 | project_to_update['testPass'] = project['testPass'] |
borlanic | 0:fbdae7e6d805 | 240 | project_to_update['testResult'] = project['testResult'] |
borlanic | 0:fbdae7e6d805 | 241 | project_to_update['testOutput'] = project['testOutput'] |
borlanic | 0:fbdae7e6d805 | 242 | |
borlanic | 0:fbdae7e6d805 | 243 | def update_project_run(projectRuns, project, is_build): |
borlanic | 0:fbdae7e6d805 | 244 | found_project = find_project_run(projectRuns, project) |
borlanic | 0:fbdae7e6d805 | 245 | if found_project: |
borlanic | 0:fbdae7e6d805 | 246 | update_project_run_results(found_project, project, is_build) |
borlanic | 0:fbdae7e6d805 | 247 | else: |
borlanic | 0:fbdae7e6d805 | 248 | add_project_run(projectRuns, project) |
borlanic | 0:fbdae7e6d805 | 249 | |
borlanic | 0:fbdae7e6d805 | 250 | def add_report(project_run_data, report_file, is_build, build_id, host_os): |
borlanic | 0:fbdae7e6d805 | 251 | tree = None |
borlanic | 0:fbdae7e6d805 | 252 | |
borlanic | 0:fbdae7e6d805 | 253 | try: |
borlanic | 0:fbdae7e6d805 | 254 | tree = ET.parse(report_file) |
borlanic | 0:fbdae7e6d805 | 255 | except: |
borlanic | 0:fbdae7e6d805 | 256 | print(sys.exc_info()[0]) |
borlanic | 0:fbdae7e6d805 | 257 | print('Invalid path to report: %s', report_file) |
borlanic | 0:fbdae7e6d805 | 258 | sys.exit(1) |
borlanic | 0:fbdae7e6d805 | 259 | |
borlanic | 0:fbdae7e6d805 | 260 | test_suites = tree.getroot() |
borlanic | 0:fbdae7e6d805 | 261 | |
borlanic | 0:fbdae7e6d805 | 262 | for test_suite in test_suites: |
borlanic | 0:fbdae7e6d805 | 263 | platform = "" |
borlanic | 0:fbdae7e6d805 | 264 | toolchain = "" |
borlanic | 0:fbdae7e6d805 | 265 | vendor = "" |
borlanic | 0:fbdae7e6d805 | 266 | for properties in test_suite.findall('properties'): |
borlanic | 0:fbdae7e6d805 | 267 | for property in properties.findall('property'): |
borlanic | 0:fbdae7e6d805 | 268 | if property.attrib['name'] == 'target': |
borlanic | 0:fbdae7e6d805 | 269 | platform = property.attrib['value'] |
borlanic | 0:fbdae7e6d805 | 270 | project_run_data['platforms_set'].add(platform) |
borlanic | 0:fbdae7e6d805 | 271 | elif property.attrib['name'] == 'toolchain': |
borlanic | 0:fbdae7e6d805 | 272 | toolchain = property.attrib['value'] |
borlanic | 0:fbdae7e6d805 | 273 | project_run_data['toolchains_set'].add(toolchain) |
borlanic | 0:fbdae7e6d805 | 274 | elif property.attrib['name'] == 'vendor': |
borlanic | 0:fbdae7e6d805 | 275 | vendor = property.attrib['value'] |
borlanic | 0:fbdae7e6d805 | 276 | project_run_data['vendors_set'].add(vendor) |
borlanic | 0:fbdae7e6d805 | 277 | |
borlanic | 0:fbdae7e6d805 | 278 | for test_case in test_suite.findall('testcase'): |
borlanic | 0:fbdae7e6d805 | 279 | projectRun = {} |
borlanic | 0:fbdae7e6d805 | 280 | projectRun['build'] = build_id |
borlanic | 0:fbdae7e6d805 | 281 | projectRun['hostOs'] = host_os |
borlanic | 0:fbdae7e6d805 | 282 | projectRun['platform'] = platform |
borlanic | 0:fbdae7e6d805 | 283 | projectRun['toolchain'] = toolchain |
borlanic | 0:fbdae7e6d805 | 284 | projectRun['project'] = test_case.attrib['classname'].split('.')[-1] |
borlanic | 0:fbdae7e6d805 | 285 | projectRun['vendor'] = vendor |
borlanic | 0:fbdae7e6d805 | 286 | |
borlanic | 0:fbdae7e6d805 | 287 | project_run_data['names_set'].add(projectRun['project']) |
borlanic | 0:fbdae7e6d805 | 288 | |
borlanic | 0:fbdae7e6d805 | 289 | should_skip = False |
borlanic | 0:fbdae7e6d805 | 290 | skips = test_case.findall('skipped') |
borlanic | 0:fbdae7e6d805 | 291 | |
borlanic | 0:fbdae7e6d805 | 292 | if skips: |
borlanic | 0:fbdae7e6d805 | 293 | should_skip = skips[0].attrib['message'] == 'SKIP' |
borlanic | 0:fbdae7e6d805 | 294 | |
borlanic | 0:fbdae7e6d805 | 295 | if not should_skip: |
borlanic | 0:fbdae7e6d805 | 296 | system_outs = test_case.findall('system-out') |
borlanic | 0:fbdae7e6d805 | 297 | |
borlanic | 0:fbdae7e6d805 | 298 | output = "" |
borlanic | 0:fbdae7e6d805 | 299 | if system_outs: |
borlanic | 0:fbdae7e6d805 | 300 | output = system_outs[0].text |
borlanic | 0:fbdae7e6d805 | 301 | |
borlanic | 0:fbdae7e6d805 | 302 | if is_build: |
borlanic | 0:fbdae7e6d805 | 303 | projectRun['buildOutput'] = output |
borlanic | 0:fbdae7e6d805 | 304 | else: |
borlanic | 0:fbdae7e6d805 | 305 | projectRun['testOutput'] = output |
borlanic | 0:fbdae7e6d805 | 306 | |
borlanic | 0:fbdae7e6d805 | 307 | errors = test_case.findall('error') |
borlanic | 0:fbdae7e6d805 | 308 | failures = test_case.findall('failure') |
borlanic | 0:fbdae7e6d805 | 309 | projectRunPass = None |
borlanic | 0:fbdae7e6d805 | 310 | result = None |
borlanic | 0:fbdae7e6d805 | 311 | |
borlanic | 0:fbdae7e6d805 | 312 | if errors: |
borlanic | 0:fbdae7e6d805 | 313 | projectRunPass = False |
borlanic | 0:fbdae7e6d805 | 314 | result = errors[0].attrib['message'] |
borlanic | 0:fbdae7e6d805 | 315 | elif failures: |
borlanic | 0:fbdae7e6d805 | 316 | projectRunPass = False |
borlanic | 0:fbdae7e6d805 | 317 | result = failures[0].attrib['message'] |
borlanic | 0:fbdae7e6d805 | 318 | elif skips: |
borlanic | 0:fbdae7e6d805 | 319 | projectRunPass = True |
borlanic | 0:fbdae7e6d805 | 320 | result = skips[0].attrib['message'] |
borlanic | 0:fbdae7e6d805 | 321 | else: |
borlanic | 0:fbdae7e6d805 | 322 | projectRunPass = True |
borlanic | 0:fbdae7e6d805 | 323 | result = 'OK' |
borlanic | 0:fbdae7e6d805 | 324 | |
borlanic | 0:fbdae7e6d805 | 325 | if is_build: |
borlanic | 0:fbdae7e6d805 | 326 | projectRun['buildPass'] = projectRunPass |
borlanic | 0:fbdae7e6d805 | 327 | projectRun['buildResult'] = result |
borlanic | 0:fbdae7e6d805 | 328 | else: |
borlanic | 0:fbdae7e6d805 | 329 | projectRun['testPass'] = projectRunPass |
borlanic | 0:fbdae7e6d805 | 330 | projectRun['testResult'] = result |
borlanic | 0:fbdae7e6d805 | 331 | |
borlanic | 0:fbdae7e6d805 | 332 | update_project_run(project_run_data['projectRuns'], projectRun, is_build) |
borlanic | 0:fbdae7e6d805 | 333 | |
borlanic | 0:fbdae7e6d805 | 334 | def main(arguments): |
borlanic | 0:fbdae7e6d805 | 335 | # Register and parse command line arguments |
borlanic | 0:fbdae7e6d805 | 336 | parser = argparse.ArgumentParser() |
borlanic | 0:fbdae7e6d805 | 337 | parser.add_argument('-u', '--url', required=True, help='url to ci site') |
borlanic | 0:fbdae7e6d805 | 338 | parser.add_argument('-k', '--api-key', required=True, help='api-key for posting data') |
borlanic | 0:fbdae7e6d805 | 339 | |
borlanic | 0:fbdae7e6d805 | 340 | subparsers = parser.add_subparsers(help='subcommand help') |
borlanic | 0:fbdae7e6d805 | 341 | |
borlanic | 0:fbdae7e6d805 | 342 | create_build_parser = subparsers.add_parser('create-build', help='create a new build') |
borlanic | 0:fbdae7e6d805 | 343 | create_build_parser.add_argument('-b', '--build-number', required=True, help='build number') |
borlanic | 0:fbdae7e6d805 | 344 | create_build_parser.add_argument('-T', '--build-type', choices=['Nightly', 'Limited', 'Pull_Request', 'Release_Candidate'], required=True, help='type of build') |
borlanic | 0:fbdae7e6d805 | 345 | create_build_parser.add_argument('-s', '--build-source', required=True, help='url to source of build') |
borlanic | 0:fbdae7e6d805 | 346 | create_build_parser.add_argument('-p', '--property-file-format', action='store_true', help='print result in the property file format') |
borlanic | 0:fbdae7e6d805 | 347 | create_build_parser.set_defaults(func=create_build) |
borlanic | 0:fbdae7e6d805 | 348 | |
borlanic | 0:fbdae7e6d805 | 349 | finish_build_parser = subparsers.add_parser('finish-build', help='finish a running build') |
borlanic | 0:fbdae7e6d805 | 350 | finish_build_parser.add_argument('-b', '--build-id', required=True, help='build id') |
borlanic | 0:fbdae7e6d805 | 351 | finish_build_parser.set_defaults(func=finish_build) |
borlanic | 0:fbdae7e6d805 | 352 | |
borlanic | 0:fbdae7e6d805 | 353 | finish_build_parser = subparsers.add_parser('promote-build', help='promote a build to a release') |
borlanic | 0:fbdae7e6d805 | 354 | finish_build_parser.add_argument('-b', '--build-id', required=True, help='build id') |
borlanic | 0:fbdae7e6d805 | 355 | finish_build_parser.set_defaults(func=promote_build) |
borlanic | 0:fbdae7e6d805 | 356 | |
borlanic | 0:fbdae7e6d805 | 357 | abort_build_parser = subparsers.add_parser('abort-build', help='abort a running build') |
borlanic | 0:fbdae7e6d805 | 358 | abort_build_parser.add_argument('-b', '--build-id', required=True, help='build id') |
borlanic | 0:fbdae7e6d805 | 359 | abort_build_parser.set_defaults(func=abort_build) |
borlanic | 0:fbdae7e6d805 | 360 | |
borlanic | 0:fbdae7e6d805 | 361 | add_project_runs_parser = subparsers.add_parser('add-project-runs', help='add project runs to a build') |
borlanic | 0:fbdae7e6d805 | 362 | add_project_runs_parser.add_argument('-b', '--build-id', required=True, help='build id') |
borlanic | 0:fbdae7e6d805 | 363 | add_project_runs_parser.add_argument('-r', '--build-report', required=False, help='path to junit xml build report') |
borlanic | 0:fbdae7e6d805 | 364 | add_project_runs_parser.add_argument('-t', '--test-report', required=False, help='path to junit xml test report') |
borlanic | 0:fbdae7e6d805 | 365 | add_project_runs_parser.add_argument('-o', '--host-os', required=True, help='host os on which test was run') |
borlanic | 0:fbdae7e6d805 | 366 | add_project_runs_parser.add_argument('-l', '--limit', required=False, type=int, default=1000, help='Limit the number of project runs sent at a time to avoid HTTP errors (default is 1000)') |
borlanic | 0:fbdae7e6d805 | 367 | add_project_runs_parser.set_defaults(func=add_project_runs) |
borlanic | 0:fbdae7e6d805 | 368 | |
borlanic | 0:fbdae7e6d805 | 369 | args = parser.parse_args(arguments) |
borlanic | 0:fbdae7e6d805 | 370 | args.func(args) |
borlanic | 0:fbdae7e6d805 | 371 | |
borlanic | 0:fbdae7e6d805 | 372 | if __name__ == '__main__': |
borlanic | 0:fbdae7e6d805 | 373 | main(sys.argv[1:]) |