init

Dependencies:   mbed

Committer:
Nathan Yonkee
Date:
Fri Mar 02 07:16:49 2018 -0700
Revision:
10:46a4cf51ee38
Parent:
9:d58e77ebd769
remove mbed-os

Who changed what in which revision?

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