[BUG] WALinuxAgent should not use raw 'python' to execute itself
hideishi-m opened this issue · 1 comments
Describe the bug: A clear and concise description of what the bug is.
https://github.com/Azure/WALinuxAgent/blob/master/azurelinuxagent/ga/update.py#L216
Above source code uses raw 'python' to execute itself to update the environment. It should use absolute path or python that executed itself (sys.argv[0]).
However, there are environment (in particular CentOS 7 based environments) where operating system uses python2.7 and WALinuxAgent RPM is installed under python2.7's site-packages, BUT python in the PATH may not be python2.7.
If intentionally "python" is targeted by PATH to python other than python2.7, waagent fails to start.
Distro and WALinuxAgent details (please complete the following information):
- Distro and Version: CentOS Linux release 7.9.2009 (Core)
- WALinuxAgent version WALinuxAgent-2.2.46
Additional context
You can reproduce to create a symlink of python3 to /usr/local/bin/python (also add /usr/local/bin to PATH) and start WALinuxAgent.
Suppose you have:
- /usr/bin/python (symlink to /usr/bin/python2)
- /usr/bin/python2 (provided by the operating system)
- /usr/bin/python3 (installed via yum)
- /usr/local/bin/python (symlink to /usr/bin/python3)
In /usr/lib/system/systemd/waagent.service, it uses /usr/bin/python (i.e. /usr/bin/python2) to start the agent.
So WALinuxAgent starts with python2 but, inside the ga/update.py it calls raw "python". This may be /usr/bin/python2 or /usr/bin/python3 depending on the PATH. If symlink of python3 has precedence, since python3 site-package does not contain WAAgentLinux, start up of the agent fails.
Log file attached
2023-04-12T09:19:12.861038Z INFO Daemon Azure Linux Agent Version:2.2.46
2023-04-12T09:19:12.861549Z INFO Daemon OS: centos 7.9.2009
2023-04-12T09:19:12.863166Z INFO Daemon Python: 2.7.5
2023-04-12T09:19:12.864539Z INFO Daemon CGroups Status: The cgroup filesystem is ready to use
2023-04-12T09:19:12.865921Z WARNING Daemon [PERIODIC] Too many files under: /var/lib/waagent/events, current count: 1000, removing oldest event files
2023-04-12T09:19:12.867092Z INFO Daemon Run daemon
2023-04-12T09:19:12.875190Z INFO Daemon cloud-init is enabled: True
2023-04-12T09:19:12.876422Z INFO Daemon Using cloud-init for provisioning
2023-04-12T09:19:12.877321Z INFO Daemon Activate resource disk
2023-04-12T09:19:12.877656Z INFO Daemon Searching gen1 prefix 00000000-0001 or gen2 f8b3781a-1e82-4818-a1c3-63d806ec15bb
2023-04-12T09:19:12.881986Z INFO Daemon Found device: sdb
2023-04-12T09:19:12.888058Z INFO Daemon Resource disk [/dev/sdb1] is already mounted [/mnt/resource]
2023-04-12T09:19:12.888674Z INFO Daemon Enable swap
2023-04-12T09:19:12.893408Z INFO Daemon Swap already enabled
2023-04-12T09:19:12.894600Z INFO Daemon Clean protocol and wireserver endpoint
2023-04-12T09:19:12.895642Z INFO Daemon Provisioning already completed, skipping.
2023-04-12T09:19:12.895786Z INFO Daemon RDMA capabilities are not enabled, skipping
2023-04-12T09:19:12.897853Z INFO Daemon Installed Agent WALinuxAgent-2.2.46 is the most current agent
/usr/sbin/waagent:27: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
Traceback (most recent call last):
File "/usr/sbin/waagent", line 31, in <module>
import azurelinuxagent.agent as agent
ModuleNotFoundError: No module named 'azurelinuxagent'
2023-04-12T09:19:13.907011Z WARNING Daemon Agent WALinuxAgent-2.2.46 launched with command 'python -u /usr/sbin/waagent -run-exthandlers' failed with return code: 1
2023-04-12T09:19:13.907953Z ERROR Daemon Event: name=WALinuxAgent, op=Enable, message=eJw1zDEOgzAMQNGreGMKURFi6JadvbNLTBMpGOTYAm4PrdTxS18vfIgVXmHMbEf4huvaru0HKGg8JYqwZ00wrcuCHKHZTk0rgzPwVsXXd2a/I/4YJ8aODk33WUhqAzPm8ieE1IRvKdITHhcEmCqB, duration=0
2023-04-12T09:19:13.910244Z WARNING Daemon Agent WALinuxAgent-2.2.46 launched with command 'python -u /usr/sbin/waagent -run-exthandlers' returned code: 1
2023-04-12T09:19:13.912931Z INFO Daemon Installed Agent WALinuxAgent-2.2.46 is the most current agent
/usr/sbin/waagent:27: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
Traceback (most recent call last):
File "/usr/sbin/waagent", line 31, in <module>
import azurelinuxagent.agent as agent
ModuleNotFoundError: No module named 'azurelinuxagent'
2023-04-12T09:19:14.919029Z WARNING Daemon Agent WALinuxAgent-2.2.46 launched with command 'python -u /usr/sbin/waagent -run-exthandlers' failed with return code: 1
(and, continues forever)
A few lines below, 'python' is replaced with sys.executable
https://github.com/Azure/WALinuxAgent/blob/master/azurelinuxagent/ga/update.py#L235