Skip to content

[BUG] v3003 a salt-master using python 3.7+ using salt-ssh cannot work with a minion using python3.5 or 3.6 #59942

Closed

Description

@bryceml

Setup
install salt-ssh on an ubuntu 20.04 box and use it to control an ubuntu 16.04 box (probably happens with centos 7, 8, debian 9, and ubuntu 18.04 as well)

Steps to Reproduce the behavior

salt-ssh \* test.ping
minion-id:
    ----------
    retcode:
        1
    stderr:
        Traceback (most recent call last):
          File "/var/tmp/.root_d24770_salt/salt-call", line 27, in <module>
            salt_call()
          File "/var/tmp/.root_d24770_salt/pyall/salt/scripts.py", line 437, in salt_call
            import salt.cli.call
          File "/var/tmp/.root_d24770_salt/pyall/salt/cli/call.py", line 6, in <module>
            import salt.cli.caller
          File "/var/tmp/.root_d24770_salt/pyall/salt/cli/caller.py", line 14, in <module>
            import salt.loader
          File "/var/tmp/.root_d24770_salt/pyall/salt/loader.py", line 7, in <module>
            import contextvars
          File "/var/tmp/.root_d24770_salt/py3/contextvars.py", line 1, in <module>
            from _contextvars import Context, ContextVar, Token, copy_context
        ImportError: No module named '_contextvars'
    stdout:

I also tried doing pip3 install contextvars immutables --prefix /usr and pip3 install contextvars immutables on the master and it didn't fix the issue.

Expected behavior

minion-id:
    True

Versions Report

Salt Version:
          Salt: 3003
 
Dependency Versions:
          cffi: Not Installed
      cherrypy: Not Installed
      dateutil: 2.7.3
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.10.1
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 0.6.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: Not Installed
      pycrypto: 2.6.1
  pycryptodome: 3.6.1
        pygit2: Not Installed
        Python: 3.8.5 (default, Jan 27 2021, 15:41:15)
  python-gnupg: 0.4.5
        PyYAML: 5.3.1
         PyZMQ: 18.1.1
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.3.2
 
System Versions:
          dist: ubuntu 20.04 focal
        locale: utf-8
       machine: x86_64
       release: 5.4.0-70-generic
        system: Linux
       version: Ubuntu 20.04 focal
 

Activity

  1. added
    bug
    point-release
    on Mar 31, 2021
  2. added
    severity-high
    Aluminium
    and removed on Mar 31, 2021
  3. added this to the Aluminium milestone on Mar 31, 2021
  4. changed the title [-][BUG] a salt-master using python 3.7+ using salt-ssh cannot work with a minion using python3.5 or 3.6[/-] [+][BUG] v3003 a salt-master using python 3.7+ using salt-ssh cannot work with a minion using python3.5 or 3.6[/+] on Mar 31, 2021
  5. sagetherage commented on Mar 31, 2021

    @sagetherage
    Contributor

    @frogunder @Ch3LL if we don't have a test for this in the packaging tests we should consider adding something see internal slack conversation starting here: https://saltstack.slack.com/archives/C04HEQ97D/p1617221478334300 in releasediscussions

  6. dwoz commented on Mar 31, 2021

    @dwoz
    Contributor

    @frogunder @Ch3LL if we don't have a test for this in the packaging tests we should consider adding something see internal slack conversation starting here: https://saltstack.slack.com/archives/C04HEQ97D/p1617221478334300 in releasediscussions

    Ideally we'd be able to add a test for this in the regular test suite too. With the docker stuff in pytest we should probably be able to come up with something.

  7. bryceml commented on Mar 31, 2021

    @bryceml
    ContributorAuthor

    probably a different issue, but I also see

    [ERROR   ] Pillar override was not passed as a dictionary
    [ERROR   ] Pillar override was not passed as a dictionary
    [ERROR   ] Pillar override was not passed as a dictionary
    [ERROR   ] Pillar override was not passed as a dictionary
    [ERROR   ] Pillar override was not passed as a dictionary
    [ERROR   ] Pillar override was not passed as a dictionary
    [ERROR   ] Pillar override was not passed as a dictionary
    [ERROR   ] Pillar override was not passed as a dictionary
    [ERROR   ] Pillar override was not passed as a dictionary
    

    as well with salt-ssh where I didn't before when running salt-ssh \* state.single pkg.uptodate uptodate refresh=True dist_upgrade=True

    debug output

    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] LazyLoaded jinja.render
    [DEBUG   ] LazyLoaded yaml.render
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] LazyLoaded state.single
    [DEBUG   ] Gathering pillar data for state run
    [ERROR   ] Pillar override was not passed as a dictionary
    [DEBUG   ] Determining pillar cache
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] LazyLoaded jinja.render
    [DEBUG   ] LazyLoaded yaml.render
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] Finished gathering pillar data for state run
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] LazyLoaded jinja.render
    [DEBUG   ] LazyLoaded yaml.render
    [DEBUG   ] LazyLoaded pkg.install
    [DEBUG   ] LazyLoaded pkg.uptodate
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] Using pkg_resources to load entry points
    [DEBUG   ] Using pkg_resources to load entry points
    
  8. danmac-uk commented on Apr 1, 2021

    @danmac-uk

    Can confirm with Debian 10 master, salt-ssh now fails with the contextvars error on Debian 9 target, as of the 3003 update. Debian 10 targets unaffected.

  9. djneades commented on Apr 1, 2021

    @djneades

    This bug also occurs against a Ubuntu 18.04 target.

  10. 41 remaining items

  11. blackzombie87 commented on Nov 4, 2021

    @blackzombie87

    The problem still exist with 3004!
    I've found a workaround, but maybe it's not the right way to "solve" this:

    First, i needed to include typing_extensions into the thin package:

    ~# diff thin.py /usr/local/lib/python3.9/dist-packages/salt/utils/thin.py
    30a31
    > import typing_extensions
    427a429
    >         typing_extensions,
    

    And second, the harder part if running on Python 3.5 (yes, ugly...) is a bug in immutables which can be solved with this:

    ~# diff _protocols.py /usr/local/lib/python3.9/dist-packages/immutables/_protocols.py
    6c6
    < from typing import NoReturn
    ---
    > #from typing import NoReturn
    15a16
    >     from typing import NoReturn
    18a20
    >     from typing_extensions import NoReturn
    

    It will move the import of NoReturn into the section which decides which version of Python is running, as NoReturn is not included in the typing extension of Python 3.5

    Sorry for directly pasting diff's here, but i never did a merge before so maybe someone here is able to do that :)

  12. drigolin commented on Dec 13, 2021

    @drigolin

    Yes is present also in 3004

  13. lastmikoi commented on Jan 24, 2022

    @lastmikoi
    Contributor

    The problem still exist with 3004! I've found a workaround, but maybe it's not the right way to "solve" this:

    First, i needed to include typing_extensions into the thin package:

    ~# diff thin.py /usr/local/lib/python3.9/dist-packages/salt/utils/thin.py
    30a31
    > import typing_extensions
    427a429
    >         typing_extensions,
    

    Thank you VERY much for that workaround, I was able to workaround my issue and start working on my 10-month froze deployment (rockylinux is only supported on >3004 so rolling back to 3002 was impossible), after I remembered to clean my .cache folder.

    I can confirm that, without this workaround, the issue is still here, even with a python 3.6 archlinux virtualenv trying to salt-ssh to a python 3.6 rockylinux 8 target.

  14. OrangeDog commented on Jul 6, 2022

    @OrangeDog
    Contributor

    Reopening due to multiple reports of not being fixed.

  15. added
    Regression
    on Jul 6, 2022
  16. lastmikoi commented on Jul 7, 2022

    @lastmikoi
    Contributor

    Thanks for the re-opening @OrangeDog !

    I've gone ahead and troubleshooted the issue in detail, I've worked on a fix (#62234) which seems to be functional.

    As an excerpt of my troubleshooting, from the PR:

    [...] the contextvars backport makes uses of the immutables module.

    This module went through a typing refactor [...] on August 2021.

    However, that typing refactor added a new dependency, typing_extensions, but only on pre-3.8 deployments

  17. tao-devops commented on Jul 29, 2022

    @tao-devops

    Setup install salt-ssh on an ubuntu 20.04 box and use it to control an ubuntu 16.04 box (probably happens with centos 7, 8, debian 9, and ubuntu 18.04 as well)

    Steps to Reproduce the behavior

    salt-ssh \* test.ping
    minion-id:
        ----------
        retcode:
            1
        stderr:
            Traceback (most recent call last):
              File "/var/tmp/.root_d24770_salt/salt-call", line 27, in <module>
                salt_call()
              File "/var/tmp/.root_d24770_salt/pyall/salt/scripts.py", line 437, in salt_call
                import salt.cli.call
              File "/var/tmp/.root_d24770_salt/pyall/salt/cli/call.py", line 6, in <module>
                import salt.cli.caller
              File "/var/tmp/.root_d24770_salt/pyall/salt/cli/caller.py", line 14, in <module>
                import salt.loader
              File "/var/tmp/.root_d24770_salt/pyall/salt/loader.py", line 7, in <module>
                import contextvars
              File "/var/tmp/.root_d24770_salt/py3/contextvars.py", line 1, in <module>
                from _contextvars import Context, ContextVar, Token, copy_context
            ImportError: No module named '_contextvars'
        stdout:
    

    I also tried doing pip3 install contextvars immutables --prefix /usr and pip3 install contextvars immutables on the master and it didn't fix the issue.

    Expected behavior

    minion-id:
        True
    

    Versions Report

    Salt Version:
              Salt: 3003
     
    Dependency Versions:
              cffi: Not Installed
          cherrypy: Not Installed
          dateutil: 2.7.3
         docker-py: Not Installed
             gitdb: Not Installed
         gitpython: Not Installed
            Jinja2: 2.10.1
           libgit2: Not Installed
          M2Crypto: Not Installed
              Mako: Not Installed
           msgpack: 0.6.2
      msgpack-pure: Not Installed
      mysql-python: Not Installed
         pycparser: Not Installed
          pycrypto: 2.6.1
      pycryptodome: 3.6.1
            pygit2: Not Installed
            Python: 3.8.5 (default, Jan 27 2021, 15:41:15)
      python-gnupg: 0.4.5
            PyYAML: 5.3.1
             PyZMQ: 18.1.1
             smmap: Not Installed
           timelib: Not Installed
           Tornado: 4.5.3
               ZMQ: 4.3.2
     
    System Versions:
              dist: ubuntu 20.04 focal
            locale: utf-8
           machine: x86_64
           release: 5.4.0-70-generic
            system: Linux
           version: Ubuntu 20.04 focal
     
    

    as

  18. fs30000 commented on Dec 16, 2022

    @fs30000

    I had the the "ModuleNotFoundError: No module named 'contextvars'" error when connecting to a centos 7 machine using salt-ssh. Of course doing pip3 install contextvars on the target fixed it.

  19. Reonaydo commented on Mar 9, 2023

    @Reonaydo

    Why Salt puts contextvars.py from Python-3.7+ into archive? If on Python-3.7+ on target system it already has his own contextvars.py. But if target system has lesser version of Python than 3.7, this contextvars.py breaks it.
    loader.py has support for 3.6 and 3.7+ versions in next code

    try:
        # Try the stdlib C extension first
        import _contextvars as contextvars
    except ImportError:
        # Py<3.7
        import contextvars
    

    So I think that salt mustn't put contextvars.py in thin.tgz
    I think there should always be contextvars backport from PyPi instead(but I'm not sure how should it be put inside)
    Python-3.7+ on target system will skip it in loader but legacy version will use this backported contextvars

    I made this fast patch and is works for me for rhel7-based and rhel8-based systems if python3-contextvars is installed on those systems.

    --- /usr/lib64/python3.10/site-packages/salt/utils/thin.py.orig      2023-01-30 12:16:01.000000000 +0300
    +++ /usr/lib64/python3.10/site-packages/salt/utils/thin.py        2023-03-09 20:18:51.527031976 +0300
    @@ -427,12 +427,14 @@
             backports_abc,
         ]
         modules = find_site_modules("contextvars")
    +    contextvars = None
         if modules:
             contextvars = modules[0]
    -    else:
    +    elif py_contextvars.__file__.split('/')[-1] != 'contextvars.py':
             contextvars = py_contextvars
    -    log.debug("Using contextvars %r", contextvars)
    -    mods.append(contextvars)
    +    if contextvars:
    +        log.debug("Using contextvars %r", contextvars)
    +        mods.append(contextvars)
         if has_immutables:
             mods.append(immutables)
         for mod in mods:
    
  20. Reonaydo commented on Mar 9, 2023

    @Reonaydo

    Oh I got it. contextvars exists in dependencies but was removed but my distro maintainers.

  21. dmurphy18 commented on Jul 11, 2023

    @dmurphy18
    Contributor

    Closing this, since it appears to be fixed, please reopen if other points to raise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

AluminiumRegressionSalt-SSHbugcentosdebianpoint-releaseseverity-highubuntu

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions