From 503f2fdd14499b46c225ab0ba2f93906636a96c8 Mon Sep 17 00:00:00 2001 From: nnandigam Date: Mon, 23 Oct 2023 10:53:13 -0700 Subject: [PATCH] undo daemon change --- azurelinuxagent/common/version.py | 15 ++------------- tests/common/test_version.py | 15 +++++---------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/azurelinuxagent/common/version.py b/azurelinuxagent/common/version.py index 81ec299771..1b1ff5f74b 100644 --- a/azurelinuxagent/common/version.py +++ b/azurelinuxagent/common/version.py @@ -49,22 +49,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(): diff --git a/tests/common/test_version.py b/tests/common/test_version.py index 89156f65c1..156cdf1ab1 100644 --- a/tests/common/test_version.py +++ b/tests/common/test_version.py @@ -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):