Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

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