Skip to content

Commit

Permalink
rsm changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nagworld9 committed Jun 17, 2024
1 parent d610d22 commit d73cef5
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 10 deletions.
3 changes: 2 additions & 1 deletion azurelinuxagent/common/agent_supported_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,14 @@ class _GAVersioningGovernanceFeature(AgentSupportedFeature):
"""
CRP would drive the RSM update if agent reports that it does support RSM upgrades with this flag otherwise CRP fallback to largest version.
Agent doesn't report supported feature flag if auto update is disabled or old version of agent running that doesn't understand GA versioning.
or if explicitly support for versioning is disabled in agent
Note: Especially Windows need this flag to report to CRP that GA doesn't support the updates. So linux adopted same flag to have a common solution.
"""

__NAME = SupportedFeatureNames.GAVersioningGovernance
__VERSION = "1.0"
__SUPPORTED = conf.get_auto_update_to_latest_version()
__SUPPORTED = conf.get_auto_update_to_latest_version() and conf.get_enable_ga_versioning()

def __init__(self):
super(_GAVersioningGovernanceFeature, self).__init__(name=self.__NAME,
Expand Down
20 changes: 20 additions & 0 deletions azurelinuxagent/ga/agent_update_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
from azurelinuxagent.ga.self_update_version_updater import SelfUpdateVersionUpdater


class UpdateMode(object):
"""
Enum for Update modes
"""
RSM = "RSM"
SelfUpdate = "SelfUpdate"


def get_agent_update_handler(protocol):
return AgentUpdateHandler(protocol)

Expand Down Expand Up @@ -138,6 +146,15 @@ def _get_agent_family_manifest(self, goal_state):
family, self._gs_id))
return agent_family_manifests[0]

def get_current_update_mode(self):
"""
Returns current update mode whether RSM or Self-Update
"""
if isinstance(self._updater, RSMVersionUpdater):
return UpdateMode.RSM
else:
return UpdateMode.SelfUpdate

def run(self, goal_state, ext_gs_updated):

try:
Expand Down Expand Up @@ -180,6 +197,9 @@ def run(self, goal_state, ext_gs_updated):
self._updater.retrieve_agent_version(agent_family, goal_state)

if not self._updater.is_retrieved_version_allowed_to_update(agent_family):
# Reset the last error report msg since when this condition met there is no issue with update, either requested
# version is same as current version or below than daemon version. In that case, we shouldn't report any error msg in the status report
self._last_attempted_update_error_msg = ""
return
self._updater.log_new_agent_update_message()
agent = self._updater.download_and_get_new_agent(self._protocol, agent_family, goal_state)
Expand Down
15 changes: 8 additions & 7 deletions azurelinuxagent/ga/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def run(self, debug=False):
self._check_daemon_running(debug)
self._check_threads_running(all_thread_handlers)
self._process_goal_state(exthandlers_handler, remote_access_handler, agent_update_handler)
self._send_heartbeat_telemetry(protocol)
self._send_heartbeat_telemetry(protocol, agent_update_handler)
self._check_agent_memory_usage()
time.sleep(self._goal_state_period)

Expand Down Expand Up @@ -1036,22 +1036,23 @@ def _write_pid_file(self):

return pid_files, pid_file

def _send_heartbeat_telemetry(self, protocol):
def _send_heartbeat_telemetry(self, protocol, agent_update_handler):
if self._last_telemetry_heartbeat is None:
self._last_telemetry_heartbeat = datetime.utcnow() - UpdateHandler.TELEMETRY_HEARTBEAT_PERIOD

if datetime.utcnow() >= (self._last_telemetry_heartbeat + UpdateHandler.TELEMETRY_HEARTBEAT_PERIOD):
dropped_packets = self.osutil.get_firewall_dropped_packets(protocol.get_endpoint())
auto_update_enabled = 1 if conf.get_autoupdate_enabled() else 0
auto_update_enabled = 1 if conf.get_auto_update_to_latest_version() else 0
update_mode = agent_update_handler.get_current_update_mode()

telemetry_msg = "{0};{1};{2};{3};{4}".format(self._heartbeat_counter, self._heartbeat_id, dropped_packets,
telemetry_msg = "{0};{1};{2};{3};{4};{5}".format(self._heartbeat_counter, self._heartbeat_id, dropped_packets,
self._heartbeat_update_goal_state_error_count,
auto_update_enabled)
auto_update_enabled, update_mode)
debug_log_msg = "[DEBUG HeartbeatCounter: {0};HeartbeatId: {1};DroppedPackets: {2};" \
"UpdateGSErrors: {3};AutoUpdate: {4}]".format(self._heartbeat_counter,
"UpdateGSErrors: {3};AutoUpdate: {4};UpdateMode: {5}]".format(self._heartbeat_counter,
self._heartbeat_id, dropped_packets,
self._heartbeat_update_goal_state_error_count,
auto_update_enabled)
auto_update_enabled, update_mode)

# Write Heartbeat events/logs
add_event(name=AGENT_NAME, version=CURRENT_VERSION, op=WALAEventOperation.HeartBeat, is_success=True,
Expand Down
23 changes: 23 additions & 0 deletions tests/ga/test_agent_update_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,29 @@ def test_it_should_report_update_status_with_error_on_download_fail(self):
self.assertEqual("9.9.9.10", vm_agent_update_status.expected_version)
self.assertIn("Failed to download agent package from all URIs", vm_agent_update_status.message)

def test_it_should_not_report_error_status_if_new_rsm_version_is_same_as_current_after_last_update_attempt_failed(self):
data_file = DATA_FILE.copy()
data_file["ext_conf"] = "wire/ext_conf_rsm_version.xml"

with self._get_agent_update_handler(test_data=data_file, protocol_get_error=True) as (agent_update_handler, _):
agent_update_handler.run(agent_update_handler._protocol.get_goal_state(), True)
vm_agent_update_status = agent_update_handler.get_vmagent_update_status()
self.assertEqual(VMAgentUpdateStatuses.Error, vm_agent_update_status.status)
self.assertEqual(1, vm_agent_update_status.code)
self.assertEqual("9.9.9.10", vm_agent_update_status.expected_version)
self.assertIn("Failed to download agent package from all URIs", vm_agent_update_status.message)

# Send same version GS after last update attempt failed
agent_update_handler._protocol.mock_wire_data.set_version_in_agent_family(
str(CURRENT_VERSION))
agent_update_handler._protocol.mock_wire_data.set_incarnation(2)
agent_update_handler._protocol.client.update_goal_state()
agent_update_handler.run(agent_update_handler._protocol.get_goal_state(), True)
vm_agent_update_status = agent_update_handler.get_vmagent_update_status()
self.assertEqual(VMAgentUpdateStatuses.Success, vm_agent_update_status.status)
self.assertEqual(0, vm_agent_update_status.code)
self.assertEqual(str(CURRENT_VERSION), vm_agent_update_status.expected_version)

def test_it_should_report_update_status_with_missing_rsm_version_error(self):
data_file = DATA_FILE.copy()
data_file['ext_conf'] = "wire/ext_conf_version_missing_in_agent_family.xml"
Expand Down
4 changes: 2 additions & 2 deletions tests/ga/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -2440,9 +2440,9 @@ def test_telemetry_heartbeat_creates_event(self, patch_add_event, patch_info, *_

with mock_wire_protocol(wire_protocol_data.DATA_FILE) as mock_protocol:
update_handler = get_update_handler()

agent_update_handler = Mock()
update_handler.last_telemetry_heartbeat = datetime.utcnow() - timedelta(hours=1)
update_handler._send_heartbeat_telemetry(mock_protocol)
update_handler._send_heartbeat_telemetry(mock_protocol, agent_update_handler)
self.assertEqual(1, patch_add_event.call_count)
self.assertTrue(any(call_args[0] == "[HEARTBEAT] Agent {0} is running as the goal state agent {1}"
for call_args in patch_info.call_args), "The heartbeat was not written to the agent's log")
Expand Down

0 comments on commit d73cef5

Please sign in to comment.