From 655a37199c8d28741b2a86e537e8b956b08b087e Mon Sep 17 00:00:00 2001 From: Ashley Watt Date: Wed, 29 Mar 2023 14:11:09 -0700 Subject: [PATCH 1/2] chg user errors to return nonzero values --- Diagnostic/Utils/misc_helpers.py | 20 ++++++++------------ Diagnostic/diagnostic.py | 9 ++++----- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/Diagnostic/Utils/misc_helpers.py b/Diagnostic/Utils/misc_helpers.py index d082b9c72..24e04128b 100644 --- a/Diagnostic/Utils/misc_helpers.py +++ b/Diagnostic/Utils/misc_helpers.py @@ -150,14 +150,12 @@ def log_and_report_failed_config_generation(self, ext_event_type, config_invalid secrets in the protected settings. This is for logging to Geneva for diagnostic purposes. :return: None """ - config_invalid_log = "Invalid config settings given: " + config_invalid_reason + \ - ". Can't proceed, although this install/enable operation is reported as successful so " \ - "the VM can complete successful startup." - self._logger_log(config_invalid_log) - self._status_reporter(ext_event_type, 'success', '0', config_invalid_log) + config_invalid_log = "Invalid config settings given: {0}".format(config_invalid_reason) + self._logger_error(config_invalid_log) + self._status_reporter(ext_event_type, 'error', '1', config_invalid_log) self._waagent_event_adder(name=self._ext_name, op=ext_event_type, - isSuccess=True, # Note this is True, because it is a user error. + isSuccess=False, version=self._ext_ver, message="Invalid handler settings encountered: {0}".format(redacted_handler_settings)) @@ -169,14 +167,12 @@ def log_and_report_invalid_mdsd_cfg(self, ext_event_type, config_validate_cmd_ms :param mdsd_cfg_xml: Content of xmlCfg.xml to be sent to Geneva :return: None """ - message = "Problem(s) detected in generated mdsd configuration. Can't enable, although this install/enable " \ - "operation is reported as successful so the VM can complete successful startup. Linux Diagnostic " \ - "Extension will exit. Config validation message: {0}".format(config_validate_cmd_msg) - self._logger_log(message) - self._status_reporter(ext_event_type, 'success', '0', message) + message = "Problem(s) detected in generated mdsd configuration. Config validation message: {0}".format(config_validate_cmd_msg) + self._logger_error(message) + self._status_reporter(ext_event_type, 'error', '1', message) self._waagent_event_adder(name=self._ext_name, op=ext_event_type, - isSuccess=True, # Note this is True, because it is a user error. + isSuccess=False, version=self._ext_ver, message="Problem(s) detected in generated mdsd configuration: {0}".format(mdsd_cfg_xml)) diff --git a/Diagnostic/diagnostic.py b/Diagnostic/diagnostic.py index 2a9680d9b..4e4c96d23 100755 --- a/Diagnostic/diagnostic.py +++ b/Diagnostic/diagnostic.py @@ -258,13 +258,12 @@ def check_for_supported_waagent_and_distro_version(): return False if g_dist_config is None: - msg = ("LAD does not support distro/version ({0}); not installed. This extension install/enable operation is " - "still considered a success as it's an external error.").format(str(platform.dist())) + msg = ("LAD does not support distro/version ({0}); not installed.").format(str(platform.dist())) hutil.log(msg) - hutil.do_status_report(g_ext_op_type, "success", '0', msg) + hutil.do_status_report(g_ext_op_type, 'error', '1', msg) waagent.AddExtensionEvent(name=hutil.get_name(), op=g_ext_op_type, - isSuccess=True, + isSuccess=False, version=hutil.get_extension_version(), message="Can't be installed on this OS " + str(platform.dist())) return False @@ -499,7 +498,7 @@ def start_mdsd(configurator): g_mdsd_bin_path, xml_file, g_ext_dir) config_validate_cmd_status, config_validate_cmd_msg = RunGetOutput(config_validate_cmd) if config_validate_cmd_status is not 0: - # Invalid config. Log error and report success. + # Invalid config, return error. g_lad_log_helper.log_and_report_invalid_mdsd_cfg(g_ext_op_type, config_validate_cmd_msg, read_file_to_string(xml_file)) return From 50d9f529f1c53dab6bf4c86d76f7663e09e1abb7 Mon Sep 17 00:00:00 2001 From: Ashley Watt Date: Mon, 1 May 2023 13:40:01 -0700 Subject: [PATCH 2/2] chg user-generated errors to return 2 --- Diagnostic/Utils/misc_helpers.py | 4 ++-- Diagnostic/diagnostic.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Diagnostic/Utils/misc_helpers.py b/Diagnostic/Utils/misc_helpers.py index 24e04128b..2d2723627 100644 --- a/Diagnostic/Utils/misc_helpers.py +++ b/Diagnostic/Utils/misc_helpers.py @@ -152,7 +152,7 @@ def log_and_report_failed_config_generation(self, ext_event_type, config_invalid """ config_invalid_log = "Invalid config settings given: {0}".format(config_invalid_reason) self._logger_error(config_invalid_log) - self._status_reporter(ext_event_type, 'error', '1', config_invalid_log) + self._status_reporter(ext_event_type, 'error', '2', config_invalid_log) self._waagent_event_adder(name=self._ext_name, op=ext_event_type, isSuccess=False, @@ -169,7 +169,7 @@ def log_and_report_invalid_mdsd_cfg(self, ext_event_type, config_validate_cmd_ms """ message = "Problem(s) detected in generated mdsd configuration. Config validation message: {0}".format(config_validate_cmd_msg) self._logger_error(message) - self._status_reporter(ext_event_type, 'error', '1', message) + self._status_reporter(ext_event_type, 'error', '2', message) self._waagent_event_adder(name=self._ext_name, op=ext_event_type, isSuccess=False, diff --git a/Diagnostic/diagnostic.py b/Diagnostic/diagnostic.py index 4e4c96d23..c470f20ae 100755 --- a/Diagnostic/diagnostic.py +++ b/Diagnostic/diagnostic.py @@ -260,7 +260,7 @@ def check_for_supported_waagent_and_distro_version(): if g_dist_config is None: msg = ("LAD does not support distro/version ({0}); not installed.").format(str(platform.dist())) hutil.log(msg) - hutil.do_status_report(g_ext_op_type, 'error', '1', msg) + hutil.do_status_report(g_ext_op_type, 'error', '2', msg) waagent.AddExtensionEvent(name=hutil.get_name(), op=g_ext_op_type, isSuccess=False,