From c3e9b89df5977688c113096e2d0b9391c4824485 Mon Sep 17 00:00:00 2001 From: mgunnala Date: Fri, 22 Nov 2024 13:08:52 -0500 Subject: [PATCH] Remove status file for single-config --- azurelinuxagent/ga/exthandlers.py | 34 ++++--------------------------- tests/ga/test_extension.py | 18 ++++++++++++---- 2 files changed, 18 insertions(+), 34 deletions(-) diff --git a/azurelinuxagent/ga/exthandlers.py b/azurelinuxagent/ga/exthandlers.py index cb7726fa52..eb3479d016 100644 --- a/azurelinuxagent/ga/exthandlers.py +++ b/azurelinuxagent/ga/exthandlers.py @@ -502,8 +502,8 @@ def handle_ext_handlers(self, goal_state_id): ExtensionRequestedState.Enabled: ('enable', ExtensionErrorCodes.PluginEnableProcessingFailed), # Note: currently, when uninstall is requested for an extension, CRP polls until the agent does not # report status for that extension, or until timeout is reached. In the case of a policy error, the - # agent reports failed status on behalf of the extension, which will cause CRP to for the full timeout, - # instead of failing fast. + # agent reports failed status on behalf of the extension, which will cause CRP to poll for the full + # timeout, instead of failing fast. # # TODO: CRP does not currently have a terminal error code for uninstall. Once this code is added, use # it instead of PluginDisableProcessingFailed below. @@ -513,7 +513,7 @@ def handle_ext_handlers(self, goal_state_id): policy_op, policy_err_code = policy_err_map.get(ext_handler.state) if policy_error is not None: err = ExtensionPolicyError(msg="", inner=policy_error, code=policy_err_code) - self.__handle_and_report_policy_error(handler_i, err, report_op=handler_i.operation, message=ustr(err), + self.__handle_and_report_ext_handler_errors(handler_i, err, report_op=handler_i.operation, message=ustr(err), extension=extension, report=True) continue @@ -524,7 +524,7 @@ def handle_ext_handlers(self, goal_state_id): ext_handler.name, conf.get_policy_file_path()) err = ExtensionPolicyError(msg, code=policy_err_code) - self.__handle_and_report_policy_error(handler_i, err, report_op=handler_i.operation, message=ustr(err), + self.__handle_and_report_ext_handler_errors(handler_i, err, report_op=handler_i.operation, message=ustr(err), extension=extension, report=True) # In case of extensions disabled, we skip processing extensions. But CRP is still waiting for some status @@ -737,32 +737,6 @@ def __handle_and_report_ext_handler_errors(ext_handler_i, error, report_op, mess add_event(name=name, version=handler_version, op=report_op, is_success=False, log_event=True, message=message) - @staticmethod - def __handle_and_report_policy_error(ext_handler_i, error, report_op, message, report=True, extension=None): - # TODO: Consider merging this function with __handle_and_report_ext_handler_errors() above, after investigating - # the impact of this change. - # - # CRP will poll for extension status for extensions with settings until timeout. In the case of policy errors, - # extensions are not processed so no extension status file is created. Extensions should still fail fast, so the - # agent should write a .status file on behalf of any extension with settings. - # __handle_and_report_ext_handler_errors() does not create the file for single-config extensions, but changing - # it will require additional testing/investigation. As a temporary workaround, this separate function was created - # to write a status file for single-config extensions. - - # Set handler status for all extensions (with and without settings) - ext_handler_i.set_handler_status(message=message, code=error.code) - - # Create status file for extensions with settings (single and multi config). - if extension is not None: - ext_handler_i.create_status_file_if_not_exist(extension, status=ExtensionStatusValue.error, code=error.code, - operation=report_op, message=message) - - if report: - name = ext_handler_i.get_extension_full_name(extension) - handler_version = ext_handler_i.ext_handler.version - add_event(name=name, version=handler_version, op=report_op, is_success=False, log_event=True, - message=message) - def handle_enable(self, ext_handler_i, extension): """ 1- Ensure the handler is installed diff --git a/tests/ga/test_extension.py b/tests/ga/test_extension.py index c2f554239a..f6410d7bdb 100644 --- a/tests/ga/test_extension.py +++ b/tests/ga/test_extension.py @@ -3650,16 +3650,26 @@ def test_should_fail_enable_if_dependent_extension_disallowed(self): handler.name == dep_ext_level_2.name).settings[0].dependencyLevel) def test_enable_should_succeed_if_extension_allowed(self): - policy = \ + policy_cases = [ { "policyVersion": "0.1.0", "extensionPolicies": { "allowListedExtensionsOnly": False, } + }, + { + "policyVersion": "0.1.0", + "extensionPolicies": { + "allowListedExtensionsOnly": True, + "extensions": { + "OSTCExtensions.ExampleHandlerLinux": {} + } + } } - self._test_policy_case(policy=policy, op=ExtensionRequestedState.Enabled, - expected_status_code=0, - expected_handler_status='Ready', expected_ext_count=1) + ] + for policy in policy_cases: + self._test_policy_case(policy=policy, op=ExtensionRequestedState.Enabled, expected_status_code=0, + expected_handler_status='Ready', expected_ext_count=1) if __name__ == '__main__':