Skip to content

Commit

Permalink
control agent updates in e2e tests and fix uts (#2743)
Browse files Browse the repository at this point in the history
* disable agent updates in dcr and fix uts

* address comments

* fix uts
  • Loading branch information
nagworld9 authored Jan 26, 2023
1 parent 06f8439 commit 4c7dc3f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
9 changes: 9 additions & 0 deletions azurelinuxagent/common/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def load_conf_from_file(conf_file_path, conf=__conf__):
"ResourceDisk.EnableSwapEncryption": False,
"AutoUpdate.Enabled": True,
"EnableOverProvisioning": True,
"GAUpdates.Enabled": True,
#
# "Debug" options are experimental and may be removed in later
# versions of the Agent.
Expand Down Expand Up @@ -502,6 +503,14 @@ def get_monitor_network_configuration_changes(conf=__conf__):
return conf.get_switch("Monitor.NetworkConfigurationChanges", False)


def get_ga_updates_enabled(conf=__conf__):
"""
If True, the agent go through update logic to look for new agents otherwise it will stop agent updates.
NOTE: This option is needed in e2e tests to control agent updates.
"""
return conf.get_switch("GAUpdates.Enabled", True)


def get_cgroup_check_period(conf=__conf__):
"""
How often to perform checks on cgroups (are the processes in the cgroups as expected,
Expand Down
4 changes: 2 additions & 2 deletions azurelinuxagent/ga/agent_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ def __log_event(level, msg_, success_=True):

def run(self, goal_state):
try:
# Ignore new agents if update is disabled
if not self._autoupdate_enabled:
# Ignore new agents if update is disabled. The latter flag only used in e2e tests.
if not self._autoupdate_enabled or not conf.get_ga_updates_enabled():
return

self._gs_id = goal_state.extensions_goal_state.id
Expand Down
10 changes: 5 additions & 5 deletions tests/ga/test_agent_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def test_it_should_not_agent_update_if_last_attempted_update_time_not_elapsed(se
with self.__get_agent_update_handler(test_data=data_file, autoupdate_frequency=10) as (agent_update_handler, mock_telemetry):
agent_update_handler._protocol.mock_wire_data.set_extension_config_requested_version(version)
agent_update_handler._protocol.mock_wire_data.set_incarnation(2)
agent_update_handler._protocol.update_goal_state()
agent_update_handler._protocol.client.update_goal_state()
agent_update_handler.run(agent_update_handler._protocol.get_goal_state())

self.__assert_agent_requested_version_in_goal_state(mock_telemetry, inc=2, version=version)
Expand Down Expand Up @@ -151,7 +151,7 @@ def test_it_should_not_agent_update_if_requested_version_is_same_as_current_vers
agent_update_handler._protocol.mock_wire_data.set_extension_config_requested_version(
str(CURRENT_VERSION))
agent_update_handler._protocol.mock_wire_data.set_incarnation(2)
agent_update_handler._protocol.update_goal_state()
agent_update_handler._protocol.client.update_goal_state()
agent_update_handler.run(agent_update_handler._protocol.get_goal_state())
self.assertEqual(0, len([kwarg['message'] for _, kwarg in mock_telemetry.call_args_list if
"requesting a new agent version" in kwarg['message'] and kwarg[
Expand Down Expand Up @@ -187,7 +187,7 @@ def test_it_should_downgrade_agent_if_requested_version_is_available_less_than_c
with self.__get_agent_update_handler(test_data=data_file) as (agent_update_handler, mock_telemetry):
agent_update_handler._protocol.mock_wire_data.set_extension_config_requested_version(downgraded_version)
agent_update_handler._protocol.mock_wire_data.set_incarnation(2)
agent_update_handler._protocol.update_goal_state()
agent_update_handler._protocol.client.update_goal_state()
with self.assertRaises(AgentUpgradeExitException) as context:
agent_update_handler.run(agent_update_handler._protocol.get_goal_state())
self.__assert_agent_requested_version_in_goal_state(mock_telemetry, inc=2, version=downgraded_version)
Expand All @@ -208,7 +208,7 @@ def test_handles_if_requested_version_not_found_in_pkgs_to_download(self):
with self.__get_agent_update_handler(test_data=data_file) as (agent_update_handler, mock_telemetry):
agent_update_handler._protocol.mock_wire_data.set_extension_config_requested_version(version)
agent_update_handler._protocol.mock_wire_data.set_incarnation(2)
agent_update_handler._protocol.update_goal_state()
agent_update_handler._protocol.client.update_goal_state()
agent_update_handler.run(agent_update_handler._protocol.get_goal_state())

self.__assert_agent_requested_version_in_goal_state(mock_telemetry, inc=2, version=version)
Expand Down Expand Up @@ -245,7 +245,7 @@ def test_it_should_report_update_status_with_success(self):
agent_update_handler._protocol.mock_wire_data.set_extension_config_requested_version(
str(CURRENT_VERSION))
agent_update_handler._protocol.mock_wire_data.set_incarnation(2)
agent_update_handler._protocol.update_goal_state()
agent_update_handler._protocol.client.update_goal_state()
agent_update_handler.run(agent_update_handler._protocol.get_goal_state())
vm_agent_update_status = agent_update_handler.get_vmagent_update_status()
self.assertEqual(VMAgentUpdateStatuses.Success, vm_agent_update_status.status)
Expand Down
1 change: 1 addition & 0 deletions tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
Extensions.Enabled = True
Extensions.GoalStatePeriod = 6
Extensions.InitialGoalStatePeriod = 6
GAUpdates.Enabled = True
HttpProxy.Host = None
HttpProxy.Port = None
Lib.Dir = /var/lib/waagent
Expand Down

0 comments on commit 4c7dc3f

Please sign in to comment.