From 24415af3bbf93c91f38e1953136d838ed65deef6 Mon Sep 17 00:00:00 2001 From: Fabricio Brunetti Date: Mon, 25 Nov 2019 14:10:55 -0300 Subject: [PATCH] Python execution framework fix: use any value type (#691) * Python execution framework fix: use any value type This change removes the function convert_to_right_type. Currently whenever a new parameter type is added (i.e. T1058 uses type "registry"), Python script runner crashes with "An error occurred while running the suite. Value type registry does not exist!". This wouldn't be a problem if the convert_to_right_type function did some real validation but as it stands today the function convert_to_right_type doesn't really do anything (except for casting integers into strings). If a type that needs some serious validation/conversion ever comes up the function may be reinstated. * Deleting convert_to_right_type function --- execution-frameworks/contrib/python/runner.py | 41 ++----------------- 1 file changed, 4 insertions(+), 37 deletions(-) diff --git a/execution-frameworks/contrib/python/runner.py b/execution-frameworks/contrib/python/runner.py index 53b16fed..b9cc14d1 100644 --- a/execution-frameworks/contrib/python/runner.py +++ b/execution-frameworks/contrib/python/runner.py @@ -169,8 +169,8 @@ def executor_get_input_arguments(input_arguments): if not answer: answer = values["default"] - # Convert to right type - parameters[name] = convert_to_right_type(answer, values["type"]) + # Cast parameter to string + parameters[name] = str(answer) return parameters @@ -228,9 +228,9 @@ def set_parameters(executor_input_arguments, given_arguments): # to the given params. final_parameters = {**default_parameters, **given_arguments} - # Convert to right type + # Cast parameters to string for name, value in final_parameters.items(): - final_parameters[name] = convert_to_right_type(value, executor_input_arguments[name]["type"]) + final_parameters[name] = str(value) return final_parameters @@ -350,39 +350,6 @@ def build_command(launcher, command, parameters): #pylint: disable=unused-argume return command -def convert_to_right_type(value, t): - """We need to convert the entered argument to the right type, based on the YAML - file's indications.""" - - # Make sure that type is easy to parse. - t = t.lower() - - if t == "string": - # Can't really validate this otherwise. - pass - - elif t == "path": - # Validating this type doesn't seem to make sense most of the time... - pass - #value = os.path.normcase(os.path.normpath(value)) - ## Make sure that the path exists, or that the base directory does (creating a new file, for example) - #if not os.path.exists(value) and not os.path.exists(os.path.dirname(value)): - # raise Exception("Path {} does not exist!".format(value)) - - elif t == "url": - # We'll assume the URL is well-formatted. That's the user's problem. :) - pass - - elif t == "integer" or t == "int": - # We'll assume that the int it's actually an int - value = str(value) - - else: - raise Exception("Value type {} does not exist!".format(t)) - - return value - - def execute_command(launcher, command, cwd): """Executes a command with the given launcher."""