From 2f03b85bfcf2ede29471aa3a9ba0c3c588b12c47 Mon Sep 17 00:00:00 2001 From: Przemek Wirkus Date: Thu, 23 Oct 2014 17:14:18 +0100 Subject: [PATCH] Host test plugins: Added generic error printing to host test plugin base class --- .../host_tests_plugins/host_test_plugins.py | 19 +++++++++---- .../host_tests_plugins/module_copy_firefox.py | 2 +- .../host_tests_plugins/module_copy_mbed.py | 2 +- .../host_tests_plugins/module_reset_mps2.py | 28 ++++++++----------- workspace_tools/test_api.py | 8 ------ 5 files changed, 28 insertions(+), 31 deletions(-) diff --git a/workspace_tools/host_tests/host_tests_plugins/host_test_plugins.py b/workspace_tools/host_tests/host_tests_plugins/host_test_plugins.py index db71293e5c..3119b49405 100644 --- a/workspace_tools/host_tests/host_tests_plugins/host_test_plugins.py +++ b/workspace_tools/host_tests/host_tests_plugins/host_test_plugins.py @@ -52,14 +52,23 @@ class HostTestPluginBase: ########################################################################### # Interface helper methods - overload only if you need to have custom behaviour ########################################################################### + def print_plugin_error(self, text): + """ Function prints error in console and exits always with False + """ + print "Plugin error: %s::%s: %s"% (self.name, self.type, text) + return False + def check_parameters(self, capabilitity, *args, **kwargs): """ This function should be ran each time we call execute() to check if none of the required parameters is missing. """ + missing_parameters = [] for parameter in self.required_parameters: if parameter not in kwargs: - print "%s::%s: Plugin parameter '%s' missing!"% (self.name, self.type, parameter) - return False + missing_parameters.append(parameter) + if len(missing_parameters) > 0: + self.print_plugin_error("execute parameter(s) '%s' missing!"% (', '.join(parameter))) + return False return True def run_command(self, cmd, shell=True): @@ -69,9 +78,9 @@ class HostTestPluginBase: try: ret = call(cmd, shell=shell) if ret: - print "%s::%s: [ret=%d] Command: %s"% (self.name, self.type, ret, " ".join(cmd)) + self.print_plugin_error("[ret=%d] Command: %s"% (self.name, self.type, ret, ' '.join(cmd))) except Exception, e: result = False - print "%s::%s: [ret=%d] Command: %s"% (self.name, self.type, ret, " ".join(cmd)) - print "%s::%s: " + str(e) + self.print_plugin_error("[ret=%d] Command: %s"% (self.name, self.type, ret, " ".join(cmd))) + self.print_plugin_error("%s::%s: " + str(e)) return result diff --git a/workspace_tools/host_tests/host_tests_plugins/module_copy_firefox.py b/workspace_tools/host_tests/host_tests_plugins/module_copy_firefox.py index 6f917277b7..360835e498 100644 --- a/workspace_tools/host_tests/host_tests_plugins/module_copy_firefox.py +++ b/workspace_tools/host_tests/host_tests_plugins/module_copy_firefox.py @@ -49,7 +49,7 @@ class HostTestPluginCopyMethod_Firefox(HostTestPluginBase): try: from selenium import webdriver except ImportError, e: - print "Error: firefox copy method requires selenium library. %s"% e + self.print_plugin_error("Error: firefox copy method requires selenium library. %s"% e) return False return True diff --git a/workspace_tools/host_tests/host_tests_plugins/module_copy_mbed.py b/workspace_tools/host_tests/host_tests_plugins/module_copy_mbed.py index 2532071918..f0d050b6a0 100644 --- a/workspace_tools/host_tests/host_tests_plugins/module_copy_mbed.py +++ b/workspace_tools/host_tests/host_tests_plugins/module_copy_mbed.py @@ -32,7 +32,7 @@ class HostTestPluginCopyMethod_Mbed(HostTestPluginBase): try: copy(image_path, destination_disk) except Exception, e: - print str(e) + self.print_plugin_error("shutil.copy(%s, %s) failed: %s"% (image_path, destination_disk, str(e))) result = False return result diff --git a/workspace_tools/host_tests/host_tests_plugins/module_reset_mps2.py b/workspace_tools/host_tests/host_tests_plugins/module_reset_mps2.py index 7263e6051d..22938090bb 100644 --- a/workspace_tools/host_tests/host_tests_plugins/module_reset_mps2.py +++ b/workspace_tools/host_tests/host_tests_plugins/module_reset_mps2.py @@ -51,26 +51,22 @@ class HostTestPluginResetMethod_MPS2(HostTestPluginBase): Each capability may directly just call some command line program or execute building pythonic function """ - for parameter in self.required_parameters: - if parameter not in kwargs: - print "%s. Plugin parameter '%s' missing"% (self.name, parameter) - return False + result = False + if self.check_parameters(capabilitity, *args, **kwargs) is True: - if capabilitity == 'reboot.txt': - # TODO: Implement touch file for reboot - pass + if capabilitity == 'reboot.txt': + # TODO: Implement touch file for reboot + pass - elif capabilitity == 'shutdown.txt': - # TODO: Implement touch file for shutdown - pass + elif capabilitity == 'shutdown.txt': + # TODO: Implement touch file for shutdown + pass - elif capabilitity == 'reset.txt': - # TODO: Implement touch file for reset - pass + elif capabilitity == 'reset.txt': + # TODO: Implement touch file for reset + pass - else: - return False - return True + return result def load_plugin(): """ Returns plugin available in this module diff --git a/workspace_tools/test_api.py b/workspace_tools/test_api.py index 5402864e13..73e41db8a0 100644 --- a/workspace_tools/test_api.py +++ b/workspace_tools/test_api.py @@ -600,14 +600,6 @@ class SingleTestRunner(object): """ image_dest = image_dest if image_dest is not None else '' _copy_res, _err_msg, _copy_method = self.file_copy_method_selector(image_path, disk, copy_method, image_dest=image_dest, verbose=verbose) - - if images_config is not None: - # For different targets additional configuration file has to be changed - # Here we select target and proper function to handle configuration change - if target_name == 'ARM_MPS2': - images_cfg_path = images_config - image0file_path = os.path.join(disk, image_dest, basename(image_path)) - mps2_set_board_image_file(disk, images_cfg_path, image0file_path) return _copy_res, _err_msg, _copy_method def file_copy_method_selector(self, image_path, disk, copy_method, image_dest='', verbose=False):