Azure / WALinuxAgent

Microsoft Azure Linux Guest Agent

Home Page:http://azure.microsoft.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] Python 3.8.13 Platform module does not have supported_dists attribute

serefacet opened this issue · comments

Describe the bug: A clear and concise description of what the bug is.
walinuxagent.service (2.2.45) can't run with Python 3.8.13

Note: Please add some context which would help us understand the problem better

  1. Section of the log where the error occurs.
  2. Serial console output
/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/lib/python3/dist-packages/azurelinuxagent/common/future.py", line 43, in get_linux_distribution
    supported = platform._supported_dists + (supported_dists,)
AttributeError: module 'platform' has no attribute '_supported_dists'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/sbin/waagent", line 31, in <module>
    import azurelinuxagent.agent as agent
  File "/usr/lib/python3/dist-packages/azurelinuxagent/agent.py", line 34, in <module>
    import azurelinuxagent.common.event as event
  File "/usr/lib/python3/dist-packages/azurelinuxagent/common/event.py", line 34, in <module>
    from azurelinuxagent.common.version import CURRENT_VERSION, CURRENT_AGENT
  File "/usr/lib/python3/dist-packages/azurelinuxagent/common/version.py", line 144, in <module>
    __distro__ = get_distro()
  File "/usr/lib/python3/dist-packages/azurelinuxagent/common/version.py", line 84, in get_distro
    osinfo = get_linux_distribution(0, 'alpine')
  File "/usr/lib/python3/dist-packages/azurelinuxagent/common/future.py", line 61, in get_linux_distribution
    return get_linux_distribution_from_distro(get_full_name)
  File "/usr/lib/python3/dist-packages/azurelinuxagent/common/future.py", line 72, in get_linux_distribution_from_distro
    distro.linux_distribution(
NameError: name 'distro' is not defined
  1. Steps to reproduce the behavior.
  • Install Ubuntu LTS (18.04.1) from Azure and upgrade Python version from 3.6 to 3.8.13

Distro and WALinuxAgent details (please complete the following information):

  • Distro and Version: Ubuntu 18.04.1
  • WALinuxAgent version 2.2.45

Additional context
Add any other context about the problem here.

Log file attached

It seems that UbuntuLTS image comes with WALinuxAgent 2.2.45. I tried to upgrade to 2.7.0.6 but no luck.

The problematic line is here: https://github.com/Azure/WALinuxAgent/blob/master/azurelinuxagent/common/future.py#L77

@serefacet thanks for reporting this. We will add support for Python 3.8 at a later date. In the meanwhile, as a workaround, you could set the python version to use in the service file:

# cat /lib/systemd/system/walinuxagent.service
[Unit]
Description=Azure Linux Agent

After=network-online.target cloud-init.service
Wants=network-online.target sshd.service sshd-keygen.service

ConditionFileIsExecutable=/usr/sbin/waagent
ConditionPathExists=/etc/waagent.conf

[Service]
Type=simple
ExecStart=/usr/bin/python3 -u /usr/sbin/waagent -daemon <===========
Restart=always

[Install]
WantedBy=multi-user.target

root@nam-canary:/var/lib/waagent#

Had the same on 22.04, which comes with python 3.10. The code in future.py already handles this. As an alternative, it will use the distro library, which you don't seem to have installed.

Flow is, 1) it tries to use supported_dists:

During handling of the above exception, another exception occurred:

The exception is caught. But then it fails with 2) it tries to use distro instead:

NameError: name 'distro' is not defined

Solution:

sudo apt install python3-distro

Similar issue on Fedora Core OS Fedora CoreOS 36.20220618.3.1

python3 --version Python 3.10.5

Fixed by installing python-distro package.

Not sure if that should be a dependency of the RPM?