Skip to content

Commit

Permalink
undo get daemon version change (#2951)
Browse files Browse the repository at this point in the history
* undo daemon change

* pylint
  • Loading branch information
nagworld9 authored Oct 23, 2023
1 parent f15e6ef commit fabe7e5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
16 changes: 2 additions & 14 deletions azurelinuxagent/common/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import sys

import azurelinuxagent.common.conf as conf
from azurelinuxagent.common import logger
import azurelinuxagent.common.utils.shellutil as shellutil
from azurelinuxagent.common.utils.flexible_version import FlexibleVersion
from azurelinuxagent.common.future import ustr, get_linux_distribution
Expand Down Expand Up @@ -49,22 +48,11 @@ 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 version of agent which started by the python
the process is not the daemon itself) the function returns "0.0.0.0"
"""
if __DAEMON_VERSION_ENV_VARIABLE in os.environ:
return FlexibleVersion(os.environ[__DAEMON_VERSION_ENV_VARIABLE])
else:
# The agent process which execute the extensions can have different version(after upgrades) and importing version from that process may provide wrong version for daemon.
# so launching new process with sys.executable python provides the correct version for daemon which preinstalled in the image.
daemon_version = "0.0.0.0"
try:
cmd = ["{0}".format(sys.executable), "-c", "from azurelinuxagent.common.version import AGENT_VERSION; print(AGENT_VERSION)"]
daemon_version = shellutil.run_command(cmd)
except Exception as e: # Make the best effort to get the daemon version, otherwise default to 0.0.0.0(unknown)
logger.info("Failed to get the daemon version. The error is: {0} \n[This error can be ignored since it has no impact on customer. So we return as unknown version: 0.0.0.0]", ustr(e))
# set the daemon version to the environment variable to cache it for future calls.
set_daemon_version(daemon_version)
return FlexibleVersion(os.environ[__DAEMON_VERSION_ENV_VARIABLE])
return FlexibleVersion("0.0.0.0")


def get_f5_platform():
Expand Down
15 changes: 5 additions & 10 deletions tests/common/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,11 @@ def test_get_daemon_version_should_return_the_version_that_was_previously_set(se
finally:
os.environ.pop(DAEMON_VERSION_ENV_VARIABLE)

def test_get_daemon_version_from_fallback_when_the_version_has_not_been_set(self):
with patch("azurelinuxagent.common.utils.shellutil.run_command", return_value="2.3.53") as mock_run_command:
self.assertEqual(
FlexibleVersion("2.3.53"), get_daemon_version(),
"The daemon version should be defined. Environment={0}".format(os.environ)
)
self.assertEqual(FlexibleVersion("2.3.53"), get_daemon_version(), "The daemon version should be 2.3.53")
self.assertEqual(1, mock_run_command.call_count, "The daemon version should be read from env value on second time")

os.environ.pop(DAEMON_VERSION_ENV_VARIABLE)
def test_get_daemon_version_should_return_zero_when_the_version_has_not_been_set(self):
self.assertEqual(
FlexibleVersion("0.0.0.0"), get_daemon_version(),
"The daemon version should not be defined. Environment={0}".format(os.environ)
)


class TestCurrentAgentName(AgentTestCase):
Expand Down

0 comments on commit fabe7e5

Please sign in to comment.