saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.19k stars 5.48k forks source link

[BUG] salt-master will not run on Python 3.10.5 (Debian Bookworm) - AttributeError: 'PathDistribution' object has no attribute '_normalized_name' #62229

Open victorhooi opened 2 years ago

victorhooi commented 2 years ago

Description

Salt-master will not start on latest Debian testing (Bookworm), due to a Python error:

Setting up salt-master (3004.2+ds-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/salt-master.service → /lib/systemd/system/salt-master.service.
Job for salt-master.service failed because the control process exited with error code.
See "systemctl status salt-master.service" and "journalctl -xeu salt-master.service" for details.
invoke-rc.d: initscript salt-master, action "start" failed.
× salt-master.service - The Salt Master Server
     Loaded: loaded (/lib/systemd/system/salt-master.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Tue 2022-06-28 07:53:59 AEST; 7ms ago
       Docs: man:salt-master(1)
             file:///usr/share/doc/salt/html/contents.html
             https://docs.saltproject.io/en/latest/contents.html
    Process: 1546 ExecStart=/usr/bin/salt-master (code=exited, status=64)
   Main PID: 1546 (code=exited, status=64)
        CPU: 222ms

Jun 28 07:53:59 saltmaster salt-master[1546]:   File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 459, in load
Jun 28 07:53:59 saltmaster salt-master[1546]:     ordered = sorted(eps, key=by_group)
Jun 28 07:53:59 saltmaster salt-master[1546]:   File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 1006, in <genexpr>
Jun 28 07:53:59 saltmaster salt-master[1546]:     eps = itertools.chain.from_iterable(
Jun 28 07:53:59 saltmaster salt-master[1546]:   File "/usr/lib/python3.10/importlib/metadata/_itertools.py", line 16, in unique_everseen
Jun 28 07:53:59 saltmaster salt-master[1546]:     k = key(element)
Jun 28 07:53:59 saltmaster salt-master[1546]: AttributeError: 'PathDistribution' object has no attribute '_normalized_name'
Jun 28 07:53:59 saltmaster systemd[1]: salt-master.service: Main process exited, code=exited, status=64/USAGE
Jun 28 07:53:59 saltmaster systemd[1]: salt-master.service: Failed with result 'exit-code'.
Jun 28 07:53:59 saltmaster systemd[1]: Failed to start The Salt Master Server.
dpkg: error processing package salt-master (--configure):
 installed salt-master package post-installation script subprocess returned error exit status 1
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.33-7) ...
Errors were encountered while processing:
 salt-master
E: Sub-process /usr/bin/dpkg returned an error code (1)

This appears similar to https://github.com/saltstack/salt/issues/61819 - however, that issue claimed the issue was fixed in Python 3.10.1+.

However, I am running Python 3.10.5, and the issue still appears to exist:

$ python3 --version
Python 3.10.5

Setup

Steps to Reproduce the behavior

Install Debian Testing, with Python 3.10.5. Install SaltStack per https://repo.saltproject.io/#debian

sudo curl -fsSL -o /usr/share/keyrings/salt-archive-keyring.gpg https://repo.saltproject.io/py3/debian/11/amd64/latest/salt-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/salt-archive-keyring.gpg arch=amd64] https://repo.saltproject.io/py3/debian/11/amd64/latest bullseye main" | sudo tee /etc/apt/sources.list.d/salt.list
sudo apt update
sudo apt install salt-master

Expected behavior Salt-master should be able to successfully run after installation.

OrangeDog commented 2 years ago

Please provide the output from salt --versions.

victorhooi commented 2 years ago

This is the output from salt --versions - I seem to get the same Python error?

$ salt --versions
Traceback (most recent call last):
  File "/usr/bin/salt", line 33, in <module>
    sys.exit(load_entry_point('salt==3004.2', 'console_scripts', 'salt')())
  File "/usr/lib/python3/dist-packages/salt/scripts.py", line 521, in salt_main
    client.run()
  File "/usr/lib/python3/dist-packages/salt/cli/salt.py", line 35, in run
    self.parse_args()
  File "/usr/lib/python3/dist-packages/salt/utils/parsers.py", line 177, in parse_args
    self.print_versions_report()
  File "/usr/lib/python3/dist-packages/salt/utils/parsers.py", line 246, in print_versions_report
    print("\n".join(version.versions_report()), file=file, flush=True)
  File "/usr/lib/python3/dist-packages/salt/version.py", line 874, in versions_report
    ver_info = versions_information(
  File "/usr/lib/python3/dist-packages/salt/version.py", line 864, in versions_information
    extensions_info = extensions_information()
  File "/usr/lib/python3/dist-packages/salt/version.py", line 840, in extensions_information
    for entry_point in salt.utils.entrypoints.iter_entry_points("salt.loader"):
  File "/usr/lib/python3/dist-packages/salt/utils/entrypoints.py", line 43, in _wrapped
    return f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/salt/utils/entrypoints.py", line 55, in iter_entry_points
    entry_points = importlib.metadata.entry_points()
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 1009, in entry_points
    return SelectableGroups.load(eps).select(**params)
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 459, in load
    ordered = sorted(eps, key=by_group)
  File "/usr/lib/python3.10/importlib/metadata/__init__.py", line 1006, in <genexpr>
    eps = itertools.chain.from_iterable(
  File "/usr/lib/python3.10/importlib/metadata/_itertools.py", line 16, in unique_everseen
    k = key(element)
AttributeError: 'PathDistribution' object has no attribute '_normalized_name'

I did run with --version on some of the salt commands, in case that helps - output below:

$ salt-master --version
salt-master 3004.2
$ salt --version
salt 3004.2
TheUbuntuGuy commented 2 years ago

Not just the master, but the minion as well. This is also broken on Ubuntu Jammy or any other distro using Python 3.10.
This is due to the inclusion of importlib_metadata with salt, which conflicts with the version installed with newer Python.

If you need to get salt working, I have made this patch which seems to get everything working normally. This will have to do until salt officially supports newer Python.

Edit /usr/lib/python3/dist-packages/salt/ext/importlib_metadata/__init__.py with:

--- /usr/lib/python3/dist-packages/salt/ext/importlib_metadata/__init__.py.old 2022-07-14 22:05:51.475525329 -0400
+++ /usr/lib/python3/dist-packages/salt/ext/importlib_metadata/__init__.py 2022-07-14 22:07:13.627100769 -0400
@@ -243,6 +243,11 @@
 class Distribution:
     """A Python distribution package."""

+    # FIXME hack for Python 3.10 support
+    @property
+    def _normalized_name(self):
+        return Prepared.normalize(self.name)
+
     @abc.abstractmethod
     def read_text(self, filename):
         """Attempt to load metadata file given by the name.
cdalvaro commented 2 years ago

This issues seems to be fixed on salt 3005rc1

OrangeDog commented 2 years ago

This issues seems to be fixed on salt 3005rc1

Are you using the Tiamat build? That's because it uses Python 3.9.

cdalvaro commented 2 years ago

This issues seems to be fixed on salt 3005rc1

Are you using the Tiamat build? That's because it uses Python 3.9.

I'm using my own custom salt-master docker image:

docker pull ghcr.io/cdalvaro/docker-salt-master:3005rc1

PR: https://github.com/cdalvaro/docker-salt-master/pull/152

One of the CI tests checks exactly your command: https://github.com/cdalvaro/docker-salt-master/runs/7406672767?check_suite_focus=true

salt-master --versions
==> Checking salt-master version ...
Salt Version:
          Salt: 3005rc1

Dependency Versions: cffi: Not Installed cherrypy: 18.6.1 dateutil: 2.8.1 docker-py: Not Installed gitdb: 4.0.9 gitpython: 3.1.24 Jinja2: 3.1.2 libgit2: 1.1.0 M2Crypto: Not Installed Mako: 1.1.3 msgpack: 1.0.4 msgpack-pure: Not Installed mysql-python: 1.4.6 pycparser: Not Installed pycrypto: Not Installed pycryptodome: 3.15.0 pygit2: 1.6.1 Python: 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0] python-gnupg: 0.4.8 PyYAML: 6.0 PyZMQ: 20.0.0 smmap: 5.0.0 timelib: Not Installed Tornado: 4.5.3 ZMQ: 4.3.3
System Versions: dist: ubuntu 22.04 Jammy Jellyfish locale: utf-8 machine: x86_64 release: 5.15.0-1014-azure system: Linux version: Ubuntu 22.04 Jammy Jellyfish
Foorack commented 2 years ago

3005 has now been released! 🎉

This means this bug should be fixed in latest version.