Skip to content

[BUG] 3003 fails to load extensions from entry point if loader function is a generator #59961

Closed

Description

@jgraichen

Description

Existing salt extensions that are loaded via entry points in python packages and had loader functions that yielded, fail to load at all in salt 3003.

Setup

Existing loader function in the python package:

import os

PKG_DIR = os.path.abspath(os.path.dirname(__file__))

def pillar_dirs():
    yield os.path.join(PKG_DIR, "pillar")

Entry point definition:

[salt.loader]
pillar_dirs = "module.loader:pillar_dirs"

Steps to Reproduce the behavior

Try to load the plugin using the existing loader function above.

Expected behavior

I would have expected to have old plugins working with previous versions to be loaded with 3003 too.

Versions Report

salt --versions-report
Salt Version:
          Salt: 3003
 
Dependency Versions:
          cffi: Not Installed
      cherrypy: Not Installed
      dateutil: Not Installed
     docker-py: Not Installed
         gitdb: 4.0.7
     gitpython: 3.1.14
        Jinja2: 2.11.3
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: Not Installed
      pycrypto: Not Installed
  pycryptodome: 3.10.1
        pygit2: Not Installed
        Python: 3.9.2 (default, Feb 28 2021, 17:03:44)
  python-gnupg: Not Installed
        PyYAML: 5.4.1
         PyZMQ: 22.0.3
         smmap: 4.0.0
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.4
 
Salt Extensions:
    salt-tower: 1.6.0
 
System Versions:
          dist: debian testing bullseye
        locale: utf-8
       machine: x86_64
       release: 5.10.0-5-amd64
        system: Linux
       version: Debian GNU/Linux testing bullseye

Additional context

Before #58943 the result from loader functions were processed in a loop, in #58943 this was changed to type checking conditions on the return values. A generator functions worked fine in the loop but is not covered in the type conditions handling the return value now, because it is neither a list nor a dict, but a <class 'generator'>.

This can of course be fixed in the extension as well, but also affects every existing release, every published package, that cannot be loaded with 3003 now. Maybe it is possible to change the code to first handle the newly supported dict format, and otherwise fall back to a loop?

Instead of

if isinstance(loaded_entry_point_value, list):
    # ...
    for path in loaded_entry_point_value:
        loaded_entry_point_paths.add(path)
elif isinstance(loaded_entry_point_value, dict):
    # ...

do it like this:

if isinstance(loaded_entry_point_value, dict):
    # ...
else:
    # must be *like* a list here
    # ...
    for path in loaded_entry_point_value:
        loaded_entry_point_paths.add(path)

Activity

  1. added
    bug
    on Apr 3, 2021
  2. jgraichen commented on Apr 6, 2021

    @jgraichen
    Author
  3. assigned and unassigned on Apr 30, 2021
  4. dwoz commented on Apr 30, 2021

    @dwoz
    Contributor

    @s0undt3ch do you have time to look at this one?

  5. added
    Regression
    on Apr 30, 2021
  6. added
    severity-critical
    Aluminium
    on Apr 30, 2021
  7. 5 remaining items

  8. added a commit that references this issue on May 13, 2021
    fa6becd
  9. s0undt3ch commented on May 13, 2021

    @s0undt3ch
    Contributor

    The fix has been merged into the frozen branch and will be on the next point release.

  10. added a commit that references this issue on May 13, 2021
    ed650b4
  11. unpinned this issue on May 18, 2021
  12. added 3 commits that reference this issue on Jun 8, 2021
    86e490b
    11fe6f2
    69088fe
  13. added a commit that references this issue on Jun 23, 2021
    90ed886
  14. added a commit that references this issue on Aug 10, 2021
    ba3d2c2
  15. added a commit that references this issue on Sep 23, 2021
    fb10707
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

AluminiumRegressionbugpoint-releaseseverity-critical

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions