Repository: Azure/WALinuxAgent
Pull request #2967 (2023-10-31 19:01:41)

undo get daemon version change (#2951)
* undo daemon change

* pylint

(cherry picked from commit fabe7e5843b796fcdddb303fd724d9d823d65727)

<!-- DO NOT DELETE THIS TEMPLATE -->

## Description

Issue # <!-- if any -->
<!--
Please add an informative description that covers that changes made by the pull request. 
This checklist is used to make sure that common issues in a pull request are addressed.
This will expedite the process of getting your pull request merged and avoid extra work on your part to fix issues discovered during the review process.
-->

---

### PR information
- [ ] The title of the PR is clear and informative.
- [ ] There are a small number of commits, each of which has an informative message. This means that previously merged commits do not appear in the history of the PR. For information on cleaning up the commits in your pull request, [see this page](https://github.com/Azure/azure-powershell/blob/master/documentation/development-docs/cleaning-up-commits.md).
- [ ] If applicable, the PR references the bug/issue that it fixes in the description.
- [ ] New Unit tests were added for the changes made

### Quality of Code and Contribution Guidelines
- [ ] I have read the [contribution guidelines](https://github.com/Azure/WALinuxAgent/blob/master/.github/CONTRIBUTING.md).

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/Azure/WALinuxAgent/pull/2967?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) Report
> Merging [#2967](https://app.codecov.io/gh/Azure/WALinuxAgent/pull/2967?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) (543c315) into [develop](https://app.codecov.io/gh/Azure/WALinuxAgent/commit/5b04dc8db2b8fe2b56dd56fe265072d0c937508b?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) (5b04dc8) will **decrease** coverage by `0.01%`.
> The diff coverage is `100.00%`.

```diff
@@             Coverage Diff             @@
##           develop    #2967      +/-   ##
===========================================
- Coverage    72.01%   72.01%   -0.01%     
===========================================
  Files          106      106              
  Lines        16104    16096       -8     
  Branches      2303     2303              
===========================================
- Hits         11597    11591       -6     
+ Misses        3974     3972       -2     
  Partials       533      533              
```


| [Files](https://app.codecov.io/gh/Azure/WALinuxAgent/pull/2967?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure) | Coverage Δ | |
|---|---|---|
| [azurelinuxagent/common/version.py](https://app.codecov.io/gh/Azure/WALinuxAgent/pull/2967?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Azure#diff-YXp1cmVsaW51eGFnZW50L2NvbW1vbi92ZXJzaW9uLnB5) | `69.64% <100.00%> (-0.25%)` | :arrow_down: |



Patch:
diff --git a/azurelinuxagent/common/version.py b/azurelinuxagent/common/version.py
index f85732da..ff9c903b 100644
--- a/azurelinuxagent/common/version.py
+++ b/azurelinuxagent/common/version.py
@@ -21,7 +21,6 @@ import platform
 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
@@ -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():


Test patch:
diff --git a/tests/common/test_version.py b/tests/common/test_version.py
index 89156f65..156cdf1a 100644
--- a/tests/common/test_version.py
+++ b/tests/common/test_version.py
@@ -136,16 +136,11 @@ class TestAgentVersion(AgentTestCase):
         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):