salt icon indicating copy to clipboard operation
salt copied to clipboard

pip.installed with custom index_url cause failed

Open xyoun opened this issue 8 years ago • 12 comments

Description of Issue/Question

Setup

sls:

Ensure Pip Packages installed:
  pip.installed:
    - name: consulchk
    - upgrade: True
    - index_url: https://mirror.in.xxx.com/simple   # private repo
    - trusted_host: mirror.in.xxx.com

result:

      Name: consulchk
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1851, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1795, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python2.7/dist-packages/salt/states/pip_state.py", line 686, in installed
                  upgrade, user, cwd, bin_env)
                File "/usr/lib/python2.7/dist-packages/salt/states/pip_state.py", line 240, in _check_if_installed
                  desired_version = available_versions[-1]
              TypeError: 'NoneType' object has no attribute '__getitem__'
     Started: 12:28:40.633624
    Duration: 1870.31 ms

it seems that pip.list_all_versions (new in 2017.7.3) not read the index_url.

Steps to Reproduce Issue

(Include debug logs if possible and relevant.)

Versions Report

Salt Version:
           Salt: 2017.7.3

Dependency Versions:
           cffi: 0.8.6
       cherrypy: Not Installed
       dateutil: 2.2
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.9.4
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.2
   mysql-python: 1.2.3
      pycparser: 2.10
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.9 (default, Jun 29 2016, 13:08:31)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 14.4.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5

System Versions:
           dist: debian 8.2
         locale: UTF-8
        machine: x86_64
        release: 4.9.0-0.bpo.5-amd64
         system: Linux
        version: debian 8.2

xyoun avatar Feb 08 '18 04:02 xyoun

Please note that we've encountered the same issue with find_links instead of index_url, e.g.:

mypackage:
  pip.installed:
    - use_wheel: True
    - no_index: True
    - pre_releases: True
    - no_deps: True
    - find_links: "file:///shared/wheels/"

virlos avatar Feb 20 '18 15:02 virlos

I'm having the same issues when using the - find_links: option.

Currently running Salt salt 2017.7.4 (Nitrogen)

install_pip_packages:
  pip.installed:
    - pkgs:       
      - pip_pkg_1
      - pip_pkg_2
      - pip_pkg_3
    - upgrade:    true
    - no_index:   true
    - find_links: file:///shared/repo/pip/

Results:

          ID: install_pip_packages
    Function: pip.installed
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python2.7/site-packages/salt/state.py", line 1851, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/site-packages/salt/loader.py", line 1795, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python2.7/site-packages/salt/states/pip_state.py", line 686, in installed
                  upgrade, user, cwd, bin_env)
                File "/usr/lib/python2.7/site-packages/salt/states/pip_state.py", line 240, in _check_if_installed
                  desired_version = available_versions[-1]
              TypeError: 'NoneType' object has no attribute '__getitem__'
     Started: 14:06:38.395280
    Duration: 9244.588 ms
     Changes:

dgmorrisjr avatar Mar 12 '18 18:03 dgmorrisjr

@dgmorrisjr @virlos I'm going to update this function to support kwargs, it should fix the problems.

xyoun avatar Mar 13 '18 03:03 xyoun

@xyoun Thanks!

dgmorrisjr avatar Mar 13 '18 13:03 dgmorrisjr

Hi @xyoun, just wanted to check in on the status of this issue. This is a blocker for us being able to upgrade to the latest version of saltstack. is there a fix/workaround that we can implement until it's been merged into a release?

dgmorrisjr avatar May 01 '18 14:05 dgmorrisjr

@dgmorrisjr sorry, being busy these days, here is a workaround you can use for a temporary fix, I'll fix it asap:

mypackage:
    cmd.run:
        - name: pip install xxx xxx2 --find_links=file:///shared/repo/pip/

xyoun avatar May 02 '18 02:05 xyoun

Thanks! Appreciate it!

Thanks! Dan Morris

On May 1, 2018, at 10:45 PM, xyoun [email protected] wrote:

@dgmorrisjr sorry, being busy these days, here is a workaround you can use for a temporary fix, I'll fix it asap:

mypackage: cmd.run: - name: pip install xxx xxx2 --find_links=file:///shared/repo/pip/ — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

dgmorrisjr avatar May 02 '18 03:05 dgmorrisjr

Is there any progress on this (or some points on where to start to fix it myself)? It is still an issue in 2018.3.4

nigelsim avatar Mar 21 '19 09:03 nigelsim

I’ll need to test.

Thanks! Dan Morris

On Mar 21, 2019, at 5:19 AM, nigelsim [email protected] wrote:

Is there any progress on this (or some points on where to start to fix it myself)? It is still an issue in 2018.3.4

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

dgmorrisjr avatar Mar 21 '19 13:03 dgmorrisjr

I just tested this in 2019.2.0.

I am still having issues.

Here is my current versions report

Salt Version:
           Salt: 2019.2.0

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: 2.0.3
      gitpython: 2.1.10
          ioflo: Not Installed
         Jinja2: 2.8.1
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: 1.2.3
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.15 (default, Aug 17 2018, 10:06:43)
   python-gnupg: 0.4.3
         PyYAML: 3.11
          PyZMQ: 14.5.0
           RAET: Not Installed
          smmap: 2.0.3
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5

System Versions:
           dist: centos 6.10 Final
         locale: UTF-8
        machine: x86_64
        release: 2.6.32-754.12.1.el6.centos.plus.x86_64
         system: Linux
        version: CentOS 6.10 Final

If I run this state:

install_pip_packages:
  pip.installed:
    - pkgs:
      - pyinotify
      - python-dateutil
      - requests
      - supervisor
    - upgrade:    true
    - no_index:   true
    - find_links: file:///mnt/repo/pip/

then I receive an error as follows:

local:
----------
          ID: install_pip_packages
    Function: pip.installed
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python2.7/site-packages/salt/state.py", line 1933, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/site-packages/salt/loader.py", line 1939, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python2.7/site-packages/salt/states/pip_state.py", line 765, in installed
                  **kwargs)
                File "/usr/lib/python2.7/site-packages/salt/states/pip_state.py", line 274, in _check_if_installed
                  desired_version = available_versions[-1]
              TypeError: 'NoneType' object has no attribute '__getitem__'

However, if I run the state as:

install_pip_packages:
  pip.installed:
    - name: pyinotify
    - upgrade:    true
    - no_index:   true
    - find_links: file:///mnt/repo/pip/

Then it runs successfully if that package is already installed.

However, if the package is not already installed, then I receive this error:

          ID: install_pip_package_urllib3
    Function: pip.installed
        Name: urllib3
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python2.7/site-packages/salt/state.py", line 1933, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/site-packages/salt/loader.py", line 1939, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python2.7/site-packages/salt/states/pip_state.py", line 765, in installed
                  **kwargs)
                File "/usr/lib/python2.7/site-packages/salt/states/pip_state.py", line 274, in _check_if_installed
                  desired_version = available_versions[-1]
              TypeError: 'NoneType' object has no attribute '__getitem__'
     Started: 14:35:22.776918
    Duration: 8920.497 ms
     Changes:

dgmorrisjr avatar Apr 26 '19 18:04 dgmorrisjr

same problem here on 3002.2

silenius avatar Dec 03 '20 11:12 silenius

Fixed twice: PR #45945 (2018, shipped v2018.11) added the index_url kwarg to pip.list_all_versions; regressed by a later refactor and re-fixed in PR #61645 (2023, shipped v3006.3) which moves --index-url/--extra-index-url after the subcommand selection. Verified on 3006.x/3007.x/3008.x/master HEAD: list_all_versions honours index_url and pip_state._check_if_installed forwards it. Functional regression test: tests/pytests/functional/modules/test_pip.py::test_list_available_packages_with_index_url.

dwoz avatar Jun 29 '26 02:06 dwoz