Skip to content

Commit

Permalink
Remove status file for single-config
Browse files Browse the repository at this point in the history
  • Loading branch information
mgunnala committed Nov 22, 2024
1 parent 86de0c5 commit c3e9b89
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 34 deletions.
34 changes: 4 additions & 30 deletions azurelinuxagent/ga/exthandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions tests/ga/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down

0 comments on commit c3e9b89

Please sign in to comment.