From 5c6cf2bf9c09f379cca28947fe6af0ec413c1fc4 Mon Sep 17 00:00:00 2001 From: Loys Ollivier Date: Wed, 27 Dec 2017 13:59:42 +0100 Subject: utils: Verify that callback options are correct When using callbacks, the user must specify '--callback-to' and '--callback-from'. Make these two arguments mutually dependant. If one is specified, the other becomes mandatory as well. Edit exceptions returns so they give meaningful information to the user in case something went wrong while reading from the callback configuration file. Change-Id: Iaa0de0b6f01ba605407db2f37c3da97aa0cacbc2 Signed-off-by: Loys Ollivier --- utils/agljobtemplate.py | 16 ++++++++-------- utils/create-jobs.py | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'utils') diff --git a/utils/agljobtemplate.py b/utils/agljobtemplate.py index 90bad13..c2e0b4a 100644 --- a/utils/agljobtemplate.py +++ b/utils/agljobtemplate.py @@ -30,14 +30,14 @@ def parse_callback_file(template_path, lava_callback, kci_callback): kci_callback = cfg.get('default', 'section') cb_data = dict(cfg.items(kci_callback)) return cb_data - except ConfigParser.NoSectionError: - str_err = "Please make sure: --callback-to " + kci_callback - str_err += " is correct and corresponds to a section in: " - str_err += lava_callback + ".cfg" - raise ConfigParser.NoSectionError, str_err - except IOError: - raise IOError, "Unable to read from file {}".format(callback_file_path) - + except (ConfigParser.NoSectionError) as err: + str_err = "'--callback-to {}': must correspond to a section [{}] in the file '{}.cfg'".format( + kci_callback, kci_callback, lava_callback) + raise ConfigParser.NoSectionError(str_err) + except (IOError) as err: + str_err = "\n'--callback-from {}': must correspond to a file located in: ".format(lava_callback) + str_err += "[releng-scripts]/templates/callback/{}.cfg".format(lava_callback) + raise IOError(err, str_err) class Agljobtemplate(object): diff --git a/utils/create-jobs.py b/utils/create-jobs.py index 5a146c4..83ee922 100755 --- a/utils/create-jobs.py +++ b/utils/create-jobs.py @@ -49,6 +49,9 @@ def parse_cmdline(machines, tests, rfs_types): args = parser.parse_args() + if (bool(args.callback_from) ^ bool(args.callback_to)): + parser.error("To specify callbacks both '--callback-to' and '--callback-from' are mandatory.") + if (args.url == 'release'): if (args.url_branch is None) and (args.url_version is None): args.url = 'default' -- cgit 1.2.3-korg