Skip to content

Commit

Permalink
deamom version fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
nagworld9 committed Jun 23, 2023
1 parent 6666833 commit 75d7264
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
8 changes: 6 additions & 2 deletions azurelinuxagent/common/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ def get_daemon_version():
The value indicates the version of the daemon that started the current agent process or, if the current
process is the daemon, the version of the current process.
If the variable is not set (because the agent is < 2.2.53, or the process was not started by the daemon and
the process is not the daemon itself) the function returns "0.0.0.0"
the process is not the daemon itself) the function returns version of agent which installed with image
"""
if __DAEMON_VERSION_ENV_VARIABLE in os.environ:
return FlexibleVersion(os.environ[__DAEMON_VERSION_ENV_VARIABLE])
return FlexibleVersion("0.0.0.0")
else:
# sys.executable provides the python running the agent so the version would be agent which comes with image
cmd = "{0} -c 'from azurelinuxagent.common.version import AGENT_VERSION; print(AGENT_VERSION)".format(sys.executable)
version = shellutil.run_command(cmd)
return FlexibleVersion(version)


def get_f5_platform():
Expand Down
13 changes: 2 additions & 11 deletions azurelinuxagent/ga/agent_update_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from azurelinuxagent.common.future import ustr
from azurelinuxagent.common.logger import LogLevel
from azurelinuxagent.common.protocol.extensions_goal_state import GoalStateSource
from azurelinuxagent.common.protocol.restapi import VERSION_0, VMAgentUpdateStatuses, VMAgentUpdateStatus
from azurelinuxagent.common.protocol.restapi import VMAgentUpdateStatuses, VMAgentUpdateStatus
from azurelinuxagent.common.utils import fileutil, textutil
from azurelinuxagent.common.utils.flexible_version import FlexibleVersion
from azurelinuxagent.common.version import get_daemon_version, CURRENT_VERSION, AGENT_NAME, AGENT_DIR_PATTERN
Expand Down Expand Up @@ -243,15 +243,6 @@ 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)]

@staticmethod
def __get_daemon_version_for_update():
daemon_version = get_daemon_version()
if daemon_version != FlexibleVersion(VERSION_0):
return daemon_version
# We return 0.0.0.0 if daemon version is not specified. In that case,
# use the min version as 2.2.53 as we started setting the daemon version starting 2.2.53.
return FlexibleVersion("2.2.53")

@staticmethod
def __log_event(level, msg, success=True):
if level == LogLevel.INFO:
Expand Down Expand Up @@ -299,7 +290,7 @@ def run(self, goal_state):
self.__log_event(LogLevel.WARNING, warn_msg)

try:
daemon_version = self.__get_daemon_version_for_update()
daemon_version = get_daemon_version()
if requested_version < daemon_version:
# Don't process the update if the requested version is less than daemon version,
# as historically we don't support downgrades below daemon versions. So daemon will not pickup that requested version rather start with
Expand Down
18 changes: 11 additions & 7 deletions tests/ga/test_agent_update_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from azurelinuxagent.common.protocol.restapi import VMAgentUpdateStatuses

from azurelinuxagent.common.protocol.util import ProtocolUtil
from azurelinuxagent.common.utils.flexible_version import FlexibleVersion
from azurelinuxagent.common.version import CURRENT_VERSION
from azurelinuxagent.ga.agent_update_handler import get_agent_update_handler
from azurelinuxagent.ga.guestagent import GAUpdateReportState
Expand Down Expand Up @@ -55,9 +56,10 @@ def put_handler(url, *args, **_):
with patch("azurelinuxagent.common.conf.get_autoupdate_frequency", return_value=autoupdate_frequency):
with patch("azurelinuxagent.common.conf.get_autoupdate_gafamily", return_value="Prod"):
with patch("azurelinuxagent.ga.agent_update_handler.add_event") as mock_telemetry:
agent_update_handler = get_agent_update_handler(protocol)
agent_update_handler._protocol = protocol
yield agent_update_handler, mock_telemetry
with patch("azurelinuxagent.ga.agent_update_handler.get_daemon_version", return_value=FlexibleVersion("2.2.53")):
agent_update_handler = get_agent_update_handler(protocol)
agent_update_handler._protocol = protocol
yield agent_update_handler, mock_telemetry

def __assert_agent_directories_available(self, versions):
for version in versions:
Expand Down Expand Up @@ -327,8 +329,9 @@ def get_handler(url, **kwargs):
with patch("azurelinuxagent.common.conf.get_autoupdate_enabled", return_value=True):
with patch("azurelinuxagent.common.conf.get_autoupdate_frequency", return_value=0.001):
with patch("azurelinuxagent.common.conf.get_autoupdate_gafamily", return_value="Prod"):
agent_update_handler_local = get_agent_update_handler(protocol)
yield agent_update_handler_local
with patch("azurelinuxagent.ga.agent_update_handler.get_daemon_version", return_value=FlexibleVersion("2.2.53")):
agent_update_handler_local = get_agent_update_handler(protocol)
yield agent_update_handler_local

with mock_agent_update_handler(test_data=data_file) as (agent_update_handler):
GAUpdateReportState.report_error_msg = ""
Expand Down Expand Up @@ -356,8 +359,9 @@ def get_handler(url, **kwargs):
with patch("azurelinuxagent.common.conf.get_autoupdate_enabled", return_value=True):
with patch("azurelinuxagent.common.conf.get_autoupdate_frequency", return_value=0.001):
with patch("azurelinuxagent.common.conf.get_autoupdate_gafamily", return_value="Prod"):
agent_update_handler_local = get_agent_update_handler(protocol)
yield agent_update_handler_local
with patch("azurelinuxagent.ga.agent_update_handler.get_daemon_version", return_value=FlexibleVersion("2.2.53")):
agent_update_handler_local = get_agent_update_handler(protocol)
yield agent_update_handler_local

with mock_agent_update_handler(test_data=data_file) as (agent_update_handler):
GAUpdateReportState.report_error_msg = ""
Expand Down
4 changes: 3 additions & 1 deletion tests/ga/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ def setUp(self):
self.update_handler._goal_state = Mock()
self.update_handler._goal_state.extensions_goal_state = Mock()
self.update_handler._goal_state.extensions_goal_state.source = "Fabric"
self.deamon_version_patch = patch("azurelinuxagent.common.version.get_daemon_version")

# Since ProtocolUtil is a singleton per thread, we need to clear it to ensure that the test cases do not reuse
# a previous state
Expand Down Expand Up @@ -1434,7 +1435,8 @@ def create_conf_mocks(self, autoupdate_frequency, hotfix_frequency, normal_frequ
with patch("azurelinuxagent.common.conf.get_hotfix_upgrade_frequency", return_value=hotfix_frequency):
with patch("azurelinuxagent.common.conf.get_normal_upgrade_frequency", return_value=normal_frequency):
with patch("azurelinuxagent.common.conf.get_autoupdate_gafamily", return_value="Prod"):
yield
with patch("azurelinuxagent.ga.agent_update_handler.get_daemon_version", return_value=FlexibleVersion("2.2.53")):
yield

@contextlib.contextmanager
def __get_update_handler(self, iterations=1, test_data=None,
Expand Down

0 comments on commit 75d7264

Please sign in to comment.