Skip to content

Commit

Permalink
Merge branch 'develop' into agent_log
Browse files Browse the repository at this point in the history
  • Loading branch information
narrieta authored Jul 27, 2023
2 parents 5dab301 + bde5b40 commit d663e9a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions azurelinuxagent/ga/agent_update_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ def __should_update_agent(self, requested_version):
largest version update(self-update):
update is allowed once per (as specified in the conf.get_hotfix_upgrade_frequency() or conf.get_normal_upgrade_frequency())
return false when we don't allow updates.
Note: Downgrades are not allowed for self-update.
"""

if not self.__check_if_downgrade_is_requested_and_allowed(requested_version):
return False

now = datetime.datetime.now()

if self._is_requested_version_update:
Expand Down Expand Up @@ -261,6 +266,19 @@ def __get_all_agents_on_disk():
path = os.path.join(conf.get_lib_dir(), "{0}-*".format(AGENT_NAME))
return [GuestAgent.from_installed_agent(path=agent_dir) for agent_dir in glob.iglob(path) if os.path.isdir(agent_dir)]

def __check_if_downgrade_is_requested_and_allowed(self, requested_version):
"""
Don't allow downgrades for self-update version
Note: The intention of this check is to keep the original behavior of self-update as it is.
"""
if not self._is_requested_version_update:
if requested_version < CURRENT_VERSION:
msg = "Downgrade requested in the GoalState, but downgrades are not supported for self-update version:{0}, " \
"skipping agent update".format(requested_version)
self.__log_event(LogLevel.INFO, msg)
return False
return True

@staticmethod
def __log_event(level, msg, success=True):
if level == LogLevel.INFO:
Expand Down
8 changes: 8 additions & 0 deletions tests/ga/test_agent_update_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ def test_it_should_update_to_largest_version_if_time_window_elapsed(self):
self.__assert_agent_directories_exist_and_others_dont_exist(versions=[str(CURRENT_VERSION), "99999.0.0.0"])
self.assertIn("Agent update found, exiting current process", ustr(context.exception.reason))

def test_it_should_not_allow_update_if_largest_version_below_current_version(self):
self.prepare_agents(count=1)
data_file = DATA_FILE.copy()
data_file["ga_manifest"] = "wire/ga_manifest_no_upgrade.xml"
with self.__get_agent_update_handler(test_data=data_file) as (agent_update_handler, _):
agent_update_handler.run(agent_update_handler._protocol.get_goal_state())
self.__assert_agent_directories_exist_and_others_dont_exist(versions=[str(CURRENT_VERSION)])

def test_it_should_not_agent_update_if_last_attempted_update_time_not_elapsed(self):
self.prepare_agents(count=1)
data_file = DATA_FILE.copy()
Expand Down

0 comments on commit d663e9a

Please sign in to comment.