Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 -u |
| 2 | |
| 3 | """ lava_helper.py: |
| 4 | |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 5 | Generate custom defined LAVA definitions rendered from Jinja2 templates. |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 6 | It can also parse the yaml output of LAVA and verify the test outcome """ |
| 7 | |
| 8 | from __future__ import print_function |
| 9 | |
| 10 | __copyright__ = """ |
| 11 | /* |
Karl Zhang | 08681e6 | 2020-10-30 13:56:03 +0800 | [diff] [blame] | 12 | * Copyright (c) 2018-2020, Arm Limited. All rights reserved. |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 13 | * |
| 14 | * SPDX-License-Identifier: BSD-3-Clause |
| 15 | * |
| 16 | */ |
| 17 | """ |
Karl Zhang | 08681e6 | 2020-10-30 13:56:03 +0800 | [diff] [blame] | 18 | |
| 19 | __author__ = "tf-m@lists.trustedfirmware.org" |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 20 | __project__ = "Trusted Firmware-M Open CI" |
Karl Zhang | 08681e6 | 2020-10-30 13:56:03 +0800 | [diff] [blame] | 21 | __version__ = "1.2.0" |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 22 | |
| 23 | import os |
| 24 | import sys |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 25 | import shutil |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 26 | import argparse |
| 27 | from copy import deepcopy |
| 28 | from collections import OrderedDict |
| 29 | from jinja2 import Environment, FileSystemLoader |
| 30 | from lava_helper_configs import * |
| 31 | |
| 32 | try: |
| 33 | from tfm_ci_pylib.utils import save_json, load_json, sort_dict,\ |
Minos Galanakis | ea42123 | 2019-06-20 17:11:28 +0100 | [diff] [blame] | 34 | load_yaml, test, print_test |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 35 | from tfm_ci_pylib.lava_rpc_connector import LAVA_RPC_connector |
| 36 | except ImportError: |
| 37 | dir_path = os.path.dirname(os.path.realpath(__file__)) |
| 38 | sys.path.append(os.path.join(dir_path, "../")) |
| 39 | from tfm_ci_pylib.utils import save_json, load_json, sort_dict,\ |
Minos Galanakis | ea42123 | 2019-06-20 17:11:28 +0100 | [diff] [blame] | 40 | load_yaml, test, print_test |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 41 | from tfm_ci_pylib.lava_rpc_connector import LAVA_RPC_connector |
| 42 | |
| 43 | |
| 44 | def sort_lavagen_config(cfg): |
| 45 | """ Create a constact dictionary object. This method is tailored for |
| 46 | the complicated configuration structure of this module """ |
| 47 | |
| 48 | res = OrderedDict() |
| 49 | if sorted(lavagen_config_sort_order) == sorted(cfg.keys()): |
| 50 | item_list = sorted(cfg.keys(), |
| 51 | key=lambda x: lavagen_config_sort_order.index(x)) |
| 52 | else: |
| 53 | item_list = sorted(cfg.keys(), key=len) |
| 54 | for k in item_list: |
| 55 | v = cfg[k] |
| 56 | if isinstance(v, dict): |
| 57 | res[k] = sort_lavagen_config(v) |
| 58 | elif isinstance(v, list) and isinstance(v[0], dict): |
| 59 | res[k] = [sort_dict(e, lava_gen_monitor_sort_order) for e in v] |
| 60 | else: |
| 61 | res[k] = v |
| 62 | return res |
| 63 | |
| 64 | |
| 65 | def save_config(cfg_f, cfg_obj): |
| 66 | """ Export configuration to json file """ |
| 67 | save_json(cfg_f, sort_lavagen_config(cfg_obj)) |
| 68 | |
| 69 | |
| 70 | def print_configs(): |
| 71 | """ Print supported configurations """ |
| 72 | |
| 73 | print("%(pad)s Built-in configurations: %(pad)s" % {"pad": "*" * 10}) |
| 74 | for k in lava_gen_config_map.keys(): |
| 75 | print("\t * %s" % k) |
| 76 | |
| 77 | |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 78 | def get_artifact_url(artifact_store_url, params, filename): |
Fathi Boudra | 83e4f29 | 2020-12-04 22:33:40 +0100 | [diff] [blame^] | 79 | return "{}/{}/artifact/build-ci-all/{}_{}_Config{}_{}_{}/install/outputs/{}/{}".format( |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 80 | artifact_store_url, |
| 81 | params['build_no'], |
| 82 | params['platform'], |
| 83 | params['compiler'], |
| 84 | params['name'], |
| 85 | params['build_type'], |
| 86 | params['boot_type'], |
| 87 | params['platform'], |
| 88 | filename, |
| 89 | ) |
| 90 | |
| 91 | def get_recovery_url(recovery_store_url, build_no, recovery): |
| 92 | return("{}/{}/artifact/{}".format( |
| 93 | recovery_store_url, |
| 94 | build_no, |
| 95 | recovery |
| 96 | )) |
| 97 | |
| 98 | def get_job_name(name, params, job): |
| 99 | return("{}_{}_{}_{}_{}_{}_{}_{}".format( |
| 100 | name, |
| 101 | job, |
| 102 | params['platform'], |
| 103 | params['build_no'], |
| 104 | params['compiler'], |
| 105 | params['build_type'], |
| 106 | params['boot_type'], |
| 107 | params['name'], |
| 108 | )) |
| 109 | |
| 110 | def generate_test_definitions(config, work_dir, user_args): |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 111 | """ Get a dictionary configuration, and an existing jinja2 template |
| 112 | and generate a LAVA compatbile yaml definition """ |
| 113 | |
| 114 | template_loader = FileSystemLoader(searchpath=work_dir) |
| 115 | template_env = Environment(loader=template_loader) |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 116 | recovery_store_url = "{}/job/{}".format( |
| 117 | user_args.jenkins_url, |
| 118 | user_args.jenkins_job |
| 119 | ) |
| 120 | build_no = user_args.build_no |
| 121 | artifact_store_url = recovery_store_url |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 122 | template_file = config.pop("templ") |
| 123 | |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 124 | definitions = {} |
| 125 | |
| 126 | for platform, recovery in config['platforms'].items(): |
| 127 | recovery_image_url = get_recovery_url( |
| 128 | recovery_store_url, |
| 129 | build_no, |
| 130 | recovery) |
| 131 | for compiler in config['compilers']: |
| 132 | for build_type in config['build_types']: |
| 133 | for boot_type in config['boot_types']: |
| 134 | for test_name, test_dict in config['tests'].items(): |
| 135 | params = { |
| 136 | "device_type": config['device_type'], |
| 137 | "job_timeout": config['job_timeout'], |
| 138 | "action_timeout": config['action_timeout'], |
| 139 | "monitor_timeout": config['monitor_timeout'], |
| 140 | "poweroff_timeout": config['poweroff_timeout'], |
| 141 | 'compiler': compiler, |
| 142 | 'build_type': build_type, |
| 143 | 'build_no': build_no, |
| 144 | 'boot_type': boot_type, |
| 145 | 'name': test_name, |
| 146 | 'test': test_dict, |
| 147 | 'platform': platform, |
| 148 | 'recovery_image_url': recovery_image_url, |
| 149 | } |
| 150 | params.update({ |
| 151 | 'firmware_url': get_artifact_url( |
| 152 | artifact_store_url, |
| 153 | params, |
| 154 | test_dict['binaries']['firmware'] |
| 155 | ), |
| 156 | 'bootloader_url': get_artifact_url( |
| 157 | artifact_store_url, |
| 158 | params, |
| 159 | test_dict['binaries']['bootloader'] |
| 160 | ) |
| 161 | }) |
| 162 | params.update({ |
| 163 | 'job_name': get_job_name( |
| 164 | config['job_name'], |
| 165 | params, |
| 166 | user_args.jenkins_job, |
| 167 | ) |
| 168 | }) |
| 169 | |
| 170 | definition = template_env.get_template(template_file).render(params) |
| 171 | definitions.update({params['job_name']: definition}) |
| 172 | return definitions |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 173 | |
| 174 | |
| 175 | def generate_lava_job_defs(user_args, config): |
| 176 | """ Create a LAVA test job definition file """ |
| 177 | |
| 178 | # Evaluate current directory |
| 179 | if user_args.work_dir: |
| 180 | work_dir = os.path.abspath(user_args.work_dir) |
| 181 | else: |
| 182 | work_dir = os.path.abspath(os.path.dirname(__file__)) |
| 183 | |
| 184 | # If a single platform is requested and it exists in the platform |
| 185 | if user_args.platform and user_args.platform in config["platforms"]: |
| 186 | # Only test this platform |
| 187 | platform = user_args.platform |
| 188 | config["platforms"] = {platform: config["platforms"][platform]} |
| 189 | |
| 190 | # Generate the ouptut definition |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 191 | definitions = generate_test_definitions(config, work_dir, user_args) |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 192 | |
| 193 | # Write it into a file |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 194 | out_dir = os.path.abspath(user_args.lava_def_output) |
| 195 | if os.path.exists(out_dir): |
| 196 | shutil.rmtree(out_dir) |
| 197 | os.makedirs(out_dir) |
| 198 | for name, definition in definitions.items(): |
| 199 | out_file = os.path.join(out_dir, "{}{}".format(name, ".yaml")) |
| 200 | with open(out_file, "w") as F: |
| 201 | F.write(definition) |
| 202 | print("Definition created at %s" % out_file) |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 203 | |
| 204 | |
| 205 | def test_map_from_config(lvg_cfg=tfm_mps2_sse_200): |
| 206 | """ Extract all required information from a lavagen config map |
| 207 | and generate a map of required tests, indexed by test name """ |
| 208 | |
| 209 | test_map = {} |
| 210 | suffix_l = [] |
| 211 | for p in lvg_cfg["platforms"]: |
| 212 | for c in lvg_cfg["compilers"]: |
| 213 | for bd in lvg_cfg["build_types"]: |
| 214 | for bt in lvg_cfg["boot_types"]: |
| 215 | suffix_l.append("%s_%s_%s_%s_%s" % (p, c, "%s", bd, bt)) |
| 216 | |
| 217 | for test_cfg_name, tst in lvg_cfg["tests"].items(): |
| 218 | for monitor in tst["monitors"]: |
| 219 | for suffix in suffix_l: |
| 220 | key = (monitor["name"] + "_" + suffix % test_cfg_name).lower() |
| 221 | # print (monitor['required']) |
| 222 | test_map[key] = monitor['required'] |
| 223 | |
| 224 | return deepcopy(test_map) |
| 225 | |
| 226 | |
| 227 | def test_lava_results(user_args, config): |
| 228 | """ Uses input of a test config dictionary and a LAVA summary Files |
| 229 | and determines if the test is a successful or not """ |
| 230 | |
| 231 | # Parse command line arguments to override config |
| 232 | result_raw = load_yaml(user_args.lava_results) |
| 233 | |
| 234 | test_map = test_map_from_config(config) |
| 235 | t_dict = {k: {} for k in test_map} |
| 236 | |
| 237 | # Return true if test is contained in test_groups |
| 238 | def test_filter(x): |
| 239 | return x["metadata"]['definition'] in test_map |
| 240 | |
| 241 | # Create a dictionary with common keys as the test map and test results |
| 242 | # {test_suite: {test_name: pass/fail}} |
| 243 | def format_results(x): |
| 244 | t_dict[x["metadata"]["definition"]].update({x["metadata"]["case"]: |
| 245 | x["metadata"]["result"]}) |
| 246 | |
| 247 | # Remove all irelevant entries from data |
| 248 | test_results = list(filter(test_filter, result_raw)) |
| 249 | |
| 250 | # Call the formatter |
| 251 | list(map(format_results, test_results)) |
| 252 | |
Minos Galanakis | ea42123 | 2019-06-20 17:11:28 +0100 | [diff] [blame] | 253 | # Remove the ignored commits if requested |
| 254 | if user_args.ignore_configs: |
| 255 | print(user_args.ignore_configs) |
| 256 | for cfg in user_args.ignore_configs: |
| 257 | try: |
| 258 | print("Rejecting config: ", cfg) |
| 259 | t_dict.pop(cfg) |
| 260 | except KeyError as e: |
| 261 | print("Warning! Rejected config %s not found" |
| 262 | " in LAVA results" % cfg) |
| 263 | |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 264 | # We need to check that each of the tests contained in the test_map exist |
| 265 | # AND that they have a passed status |
| 266 | t_sum = 0 |
Minos Galanakis | ea42123 | 2019-06-20 17:11:28 +0100 | [diff] [blame] | 267 | |
| 268 | with open("lava_job.url", "r") as F: |
| 269 | job_url = F.read().strip() |
| 270 | |
| 271 | out_rep = {"report": {}, |
| 272 | "_metadata_": {"job_url": job_url}} |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 273 | for k, v in t_dict.items(): |
| 274 | try: |
Minos Galanakis | ea42123 | 2019-06-20 17:11:28 +0100 | [diff] [blame] | 275 | out_rep["report"][k] = test(test_map[k], |
| 276 | v, |
| 277 | pass_text=["pass"], |
| 278 | error_on_failed=False, |
| 279 | test_name=k, |
| 280 | summary=user_args.lava_summary) |
| 281 | t_sum += int(out_rep["report"][k]["success"]) |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 282 | # Status can be None if a test did't fully run/complete |
| 283 | except TypeError as E: |
| 284 | t_sum = 1 |
Minos Galanakis | ea42123 | 2019-06-20 17:11:28 +0100 | [diff] [blame] | 285 | print("\n") |
| 286 | sl = [x["name"] for x in out_rep["report"].values() |
| 287 | if x["success"] is True] |
| 288 | fl = [x["name"] for x in out_rep["report"].values() |
| 289 | if x["success"] is False] |
| 290 | |
| 291 | if sl: |
| 292 | print_test(t_list=sl, status="passed", tname="Tests") |
| 293 | if fl: |
| 294 | print_test(t_list=fl, status="failed", tname="Tests") |
| 295 | |
| 296 | # Generate the output report is requested |
| 297 | if user_args.output_report: |
| 298 | save_json(user_args.output_report, out_rep) |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 299 | |
| 300 | # Every single of the tests need to have passed for group to succeed |
| 301 | if t_sum != len(t_dict): |
| 302 | print("Group Testing FAILED!") |
Minos Galanakis | ea42123 | 2019-06-20 17:11:28 +0100 | [diff] [blame] | 303 | if user_args.eif: |
| 304 | sys.exit(1) |
| 305 | else: |
| 306 | print("Group Testing PASS!") |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 307 | |
| 308 | |
| 309 | def test_lava_dispatch_credentials(user_args): |
| 310 | """ Will validate if provided token/credentials are valid. It will return |
| 311 | a valid connection or exit program if not""" |
| 312 | |
| 313 | # Collect the authentication tokens |
| 314 | try: |
| 315 | if user_args.token_from_env: |
| 316 | usr = os.environ['LAVA_USER'] |
| 317 | secret = os.environ['LAVA_TOKEN'] |
| 318 | elif user_args.token_usr and user_args.token_secret: |
| 319 | usr = user_args.token_usr |
| 320 | secret = user_args.token_secret |
| 321 | |
| 322 | # Do not submit job without complete credentials |
| 323 | if not len(usr) or not len(secret): |
| 324 | raise Exception("Credentials not set") |
| 325 | |
| 326 | lava = LAVA_RPC_connector(usr, |
| 327 | secret, |
| 328 | user_args.lava_url, |
| 329 | user_args.lava_rpc) |
| 330 | |
| 331 | # Test the credentials againist the backend |
| 332 | if not lava.test_credentials(): |
| 333 | raise Exception("Server rejected user authentication") |
| 334 | except Exception as e: |
| 335 | print("Credential validation failed with : %s" % e) |
| 336 | print("Did you set set --lava_token_usr, --lava_token_secret?") |
| 337 | sys.exit(1) |
| 338 | return lava |
| 339 | |
| 340 | |
| 341 | def lava_dispatch(user_args): |
| 342 | """ Submit a job to LAVA backend, block untill it is completed, and |
| 343 | fetch the results files if successful. If not, calls sys exit with 1 |
| 344 | return code """ |
| 345 | |
| 346 | lava = test_lava_dispatch_credentials(user_args) |
| 347 | job_id, job_url = lava.submit_job(user_args.dispatch) |
Minos Galanakis | ea42123 | 2019-06-20 17:11:28 +0100 | [diff] [blame] | 348 | |
| 349 | # The reason of failure will be reported to user by LAVA_RPC_connector |
| 350 | if job_id is None and job_url is None: |
| 351 | sys.exit(1) |
| 352 | else: |
| 353 | print("Job submitted at: " + job_url) |
| 354 | |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 355 | with open("lava_job.id", "w") as F: |
| 356 | F.write(str(job_id)) |
| 357 | print("Job id %s stored at lava_job.id file." % job_id) |
Minos Galanakis | ea42123 | 2019-06-20 17:11:28 +0100 | [diff] [blame] | 358 | with open("lava_job.url", "w") as F: |
| 359 | F.write(str(job_url)) |
| 360 | print("Job url %s stored at lava_job.url file." % job_id) |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 361 | |
| 362 | # Wait for the job to complete |
| 363 | status = lava.block_wait_for_job(job_id, int(user_args.dispatch_timeout)) |
| 364 | print("Job %s returned with status: %s" % (job_id, status)) |
| 365 | if status == "Complete": |
| 366 | lava.get_job_results(job_id, user_args.lava_job_results) |
| 367 | print("Job results exported at: %s" % user_args.lava_job_results) |
| 368 | sys.exit(0) |
| 369 | sys.exit(1) |
| 370 | |
| 371 | |
| 372 | def dispatch_cancel(user_args): |
| 373 | """ Sends a cancell request for user provided job id (dispatch_cancel)""" |
| 374 | lava = test_lava_dispatch_credentials(user_args) |
| 375 | id = user_args.dispatch_cancel |
| 376 | result = lava.cancel_job(id) |
| 377 | print("Request to cancell job: %s returned with status %s" % (id, result)) |
| 378 | |
| 379 | |
| 380 | def load_config_overrides(user_args): |
| 381 | """ Load a configuration from multiple locations and override it with |
| 382 | user provided arguemnts """ |
| 383 | |
| 384 | if user_args.config_file: |
| 385 | print("Loading config from file %s" % user_args.config_file) |
| 386 | try: |
| 387 | config = load_json(user_args.config_file) |
| 388 | except Exception: |
| 389 | print("Failed to load config from: %s ." % user_args.config_file) |
| 390 | sys.exit(1) |
| 391 | else: |
| 392 | print("Using built-in config: %s" % user_args.config_key) |
| 393 | try: |
| 394 | config = lava_gen_config_map[user_args.config_key] |
| 395 | except KeyError: |
| 396 | print("No template found for config: %s" % user_args.config_key) |
| 397 | sys.exit(1) |
| 398 | |
| 399 | config["build_no"] = user_args.build_no |
| 400 | |
Minos Galanakis | ea42123 | 2019-06-20 17:11:28 +0100 | [diff] [blame] | 401 | # Override with command line provided URL/Job Name |
| 402 | if user_args.jenkins_url: |
| 403 | _over_d = {"jenkins_url": user_args.jenkins_url, |
| 404 | "jenkins_job": "%(jenkins_job)s"} |
| 405 | config["recovery_store_url"] = config["recovery_store_url"] % _over_d |
| 406 | config["artifact_store_url"] = config["artifact_store_url"] % _over_d |
| 407 | |
| 408 | if user_args.jenkins_job: |
| 409 | _over_d = {"jenkins_job": user_args.jenkins_job} |
| 410 | config["recovery_store_url"] = config["recovery_store_url"] % _over_d |
| 411 | config["artifact_store_url"] = config["artifact_store_url"] % _over_d |
| 412 | |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 413 | # Add the template folder |
| 414 | config["templ"] = os.path.join(user_args.template_dir, config["templ"]) |
| 415 | return config |
| 416 | |
| 417 | |
| 418 | def main(user_args): |
| 419 | """ Main logic, forked according to task arguments """ |
| 420 | |
| 421 | # If a configuration listing is requested |
| 422 | if user_args.ls_config: |
| 423 | print_configs() |
| 424 | return |
| 425 | elif user_args.cconfig: |
| 426 | config_key = user_args.cconfig |
| 427 | if config_key in lava_gen_config_map.keys(): |
| 428 | config_file = "lava_job_gen_cfg_%s.json" % config_key |
| 429 | save_config(config_file, lava_gen_config_map[config_key]) |
| 430 | print("Configuration exported at %s" % config_file) |
| 431 | return |
Minos Galanakis | ea42123 | 2019-06-20 17:11:28 +0100 | [diff] [blame] | 432 | if user_args.dispatch is not None or user_args.dispatch_cancel is not None: |
| 433 | pass |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 434 | else: |
| 435 | config = load_config_overrides(user_args) |
| 436 | |
| 437 | # Configuration is assumed fixed at this point |
| 438 | if user_args.lava_results: |
| 439 | print("Evaluating File", user_args.lava_results) |
| 440 | test_lava_results(user_args, config) |
| 441 | elif user_args.dispatch: |
| 442 | lava_dispatch(user_args) |
| 443 | elif user_args.dispatch_cancel: |
| 444 | dispatch_cancel(user_args) |
| 445 | elif user_args.create_definition: |
| 446 | print("Generating Lava") |
| 447 | generate_lava_job_defs(user_args, config) |
| 448 | else: |
| 449 | print("Nothing to do, please select a task") |
| 450 | |
| 451 | |
| 452 | def get_cmd_args(): |
| 453 | """ Parse command line arguments """ |
| 454 | |
| 455 | # Parse command line arguments to override config |
| 456 | parser = argparse.ArgumentParser(description="Lava Helper") |
| 457 | |
| 458 | def_g = parser.add_argument_group('Create LAVA Definition') |
| 459 | disp_g = parser.add_argument_group('Dispatch LAVA job') |
| 460 | parse_g = parser.add_argument_group('Parse LAVA results') |
| 461 | config_g = parser.add_argument_group('Configuration handling') |
| 462 | over_g = parser.add_argument_group('Overrides') |
| 463 | |
| 464 | # Configuration control |
| 465 | config_g.add_argument("-cn", "--config-name", |
| 466 | dest="config_key", |
| 467 | action="store", |
| 468 | default="tfm_mps2_sse_200", |
| 469 | help="Select built-in configuration by name") |
| 470 | config_g.add_argument("-cf", "--config-file", |
| 471 | dest="config_file", |
| 472 | action="store", |
| 473 | help="Load config from external file in JSON format") |
| 474 | config_g.add_argument("-te", "--task-config-export", |
| 475 | dest="cconfig", |
| 476 | action="store", |
| 477 | help="Export a json file with the current config " |
| 478 | "parameters") |
| 479 | config_g.add_argument("-tl", "--task-config-list", |
| 480 | dest="ls_config", |
| 481 | action="store_true", |
| 482 | default=False, |
| 483 | help="List built-in configurations") |
| 484 | |
| 485 | def_g.add_argument("-tc", "--task-create-definition", |
| 486 | dest="create_definition", |
| 487 | action="store_true", |
| 488 | default=False, |
| 489 | help="Used in conjunction with --config parameters. " |
| 490 | "A LAVA compatible job definition will be created") |
| 491 | def_g.add_argument("-cb", "--create-definition-build-no", |
| 492 | dest="build_no", |
| 493 | action="store", |
| 494 | default="lastSuccessfulBuild", |
| 495 | help="JENKINGS Build number selector. " |
| 496 | "Default: lastSuccessfulBuild") |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 497 | def_g.add_argument("-co", "--create-definition-output-dir", |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 498 | dest="lava_def_output", |
| 499 | action="store", |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 500 | default="job_results", |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 501 | help="Set LAVA compatible .yaml output file") |
| 502 | |
| 503 | # Parameter override commands |
| 504 | over_g.add_argument("-ow", "--override-work-path", |
| 505 | dest="work_dir", |
| 506 | action="store", |
| 507 | help="Working Directory (absolute path)") |
| 508 | over_g.add_argument("-ot", "--override-template-dir", |
| 509 | dest="template_dir", |
| 510 | action="store", |
| 511 | default="jinja2_templates", |
| 512 | help="Set directory where Jinja2 templates are stored") |
| 513 | over_g.add_argument("-op", "--override-platform", |
| 514 | dest="platform", |
| 515 | action="store", |
| 516 | help="Override platform.Only the provided one " |
Minos Galanakis | ea42123 | 2019-06-20 17:11:28 +0100 | [diff] [blame] | 517 | "will be tested") |
| 518 | over_g.add_argument("-ou", "--override-jenkins-url", |
| 519 | dest="jenkins_url", |
| 520 | action="store", |
Minos Galanakis | 4407424 | 2019-10-14 09:59:11 +0100 | [diff] [blame] | 521 | help="Override %%(jenkins_url)s params in config if " |
Minos Galanakis | ea42123 | 2019-06-20 17:11:28 +0100 | [diff] [blame] | 522 | "present. Sets the jenkings address including " |
| 523 | "port") |
| 524 | over_g.add_argument("-oj", "--override-jenkins-job", |
| 525 | dest="jenkins_job", |
| 526 | action="store", |
Minos Galanakis | 4407424 | 2019-10-14 09:59:11 +0100 | [diff] [blame] | 527 | help="Override %%(jenkins_job)s params in config if " |
Minos Galanakis | ea42123 | 2019-06-20 17:11:28 +0100 | [diff] [blame] | 528 | "present. Sets the jenkings job name") |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 529 | parse_g.add_argument("-tp", "--task-lava-parse", |
| 530 | dest="lava_results", |
| 531 | action="store", |
| 532 | help="Parse provided yaml file, using a configuration" |
| 533 | " as reference to determine the outpcome" |
| 534 | " of testing") |
| 535 | parse_g.add_argument("-ls", "--lava-parse-summary", |
| 536 | dest="lava_summary", |
Minos Galanakis | ea42123 | 2019-06-20 17:11:28 +0100 | [diff] [blame] | 537 | default=False, |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 538 | action="store_true", |
| 539 | help="Print full test summary") |
Minos Galanakis | ea42123 | 2019-06-20 17:11:28 +0100 | [diff] [blame] | 540 | parse_g.add_argument("-or", "--output-report", |
| 541 | dest="output_report", |
| 542 | action="store", |
| 543 | help="Print full test summary") |
| 544 | parser.add_argument("-ef", "--error-if-failed", |
| 545 | dest="eif", |
| 546 | action="store_true", |
| 547 | help="If set will change the script exit code if one " |
| 548 | "or more tests fail") |
| 549 | parser.add_argument('-ic', '--ignore-configs', |
| 550 | dest="ignore_configs", |
| 551 | nargs='+', |
| 552 | help="Pass a space separated list of build" |
| 553 | "configurations which will get ignored when" |
| 554 | "evaluation LAVA results") |
Minos Galanakis | f4ca6ac | 2017-12-11 02:39:21 +0100 | [diff] [blame] | 555 | |
| 556 | # Lava job control commands |
| 557 | disp_g.add_argument("-td", "--task-dispatch", |
| 558 | dest="dispatch", |
| 559 | action="store", |
| 560 | help="Submit yaml file defined job to backend, and " |
| 561 | "wait for it to complete. \nRequires:" |
| 562 | " --lava_url --lava_token_usr/pass/--" |
| 563 | "lava_token_from_environ arguments, with optional" |
| 564 | "\n--lava_rpc_prefix\n--lava-job-results\n" |
| 565 | "parameters. \nIf not set they get RPC2 and " |
| 566 | "lava_job_results.yaml default values.\n" |
| 567 | "The number job id will be stored at lava_job.id") |
| 568 | disp_g.add_argument("-dc", "--dispatch-cancel", |
| 569 | dest="dispatch_cancel", |
| 570 | action="store", |
| 571 | help="Send a cancell request for job with provided id") |
| 572 | disp_g.add_argument("-dt", "--dispatch-timeout", |
| 573 | dest="dispatch_timeout", |
| 574 | default="3600", |
| 575 | action="store", |
| 576 | help="Maximum Time to block for job" |
| 577 | " submission to complete") |
| 578 | disp_g.add_argument("-dl", "--dispatch-lava-url", |
| 579 | dest="lava_url", |
| 580 | action="store", |
| 581 | help="Sets the lava hostname during job dispatch") |
| 582 | disp_g.add_argument("-dr", "--dispatch-lava-rpc-prefix", |
| 583 | dest="lava_rpc", |
| 584 | action="store", |
| 585 | default="RPC2", |
| 586 | help="Application prefix on Backend" |
| 587 | "(i.e www.domain.com/APP)\n" |
| 588 | "By default set to RPC2") |
| 589 | disp_g.add_argument("-du", "--dispatch-lava_token_usr", |
| 590 | dest="token_usr", |
| 591 | action="store", |
| 592 | help="Lava user submitting the job") |
| 593 | disp_g.add_argument("-ds", "--dispatch-lava_token_secret", |
| 594 | dest="token_secret", |
| 595 | action="store", |
| 596 | help="Hash token used to authenticate" |
| 597 | "user during job submission") |
| 598 | disp_g.add_argument("-de", "--dispatch-lava_token_from_environ", |
| 599 | dest="token_from_env", |
| 600 | action="store_true", |
| 601 | help="If set dispatcher will use the enviroment" |
| 602 | "stored $LAVA_USER, $LAVA_TOKEN for credentials") |
| 603 | disp_g.add_argument("-df", "--dispatch-lava-job-results-file", |
| 604 | dest="lava_job_results", |
| 605 | action="store", |
| 606 | default="lava_job_results.yaml", |
| 607 | help="Name of the job results file after job is " |
| 608 | "complete. Default: lava_job_results.yaml") |
| 609 | return parser.parse_args() |
| 610 | |
| 611 | |
| 612 | if __name__ == "__main__": |
| 613 | main(get_cmd_args()) |