Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with new version of docker-py which has inpact on docker_image.present state #45292

Closed
kubadawczynski opened this issue Jan 5, 2018 · 33 comments
Labels
Bug broken, incorrect, or confusing behavior cannot-reproduce cannot be replicated with info/context provided P2 Priority 2 severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Milestone

Comments

@kubadawczynski
Copy link

Description of Issue/Question

After new release of docker-py (https://github.com/docker/docker-py/releases/tag/2.7.0), salt is not able
to install docker-py and download docker image during one iteration despite that reload_modules is set to True.

----------
          ID: fetch-mysql_image-image
    Function: docker_image.present
        Name: mysql
      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 1837, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1794, in wrapper
                  return f(*args, **kwargs)
                File "/usr/lib/python2.7/dist-packages/salt/states/docker_image.py", line 174, in present
                  all_tags = __salt__['docker.list_tags']()
                File "/usr/lib/python2.7/dist-packages/salt/modules/dockermod.py", line 1439, in list_tags
                  for item in six.itervalues(images()):
                File "/usr/lib/python2.7/dist-packages/salt/modules/dockermod.py", line 1228, in images
                  response = _client_wrapper('images', all=kwargs.get('all', False))
                File "/usr/lib/python2.7/dist-packages/salt/modules/dockermod.py", line 404, in wrapper
                  ret = wrapped(*args, **kwargs)
                File "/usr/lib/python2.7/dist-packages/salt/modules/dockermod.py", line 637, in _client_wrapper
                  raise CommandExecutionError(msg)
              CommandExecutionError: Unable to perform images: cannot import name universaldetector
     Started: 14:03:08.798976
    Duration: 3.59 ms
     Changes:   

second iteration:

----------
          ID: fetch-mysql_image-image
    Function: docker_image.present
        Name: mysql
      Result: True
     Comment: Image 'mysql' was pulled
     Started: 14:03:51.264695
    Duration: 45582.392 ms
     Changes:   
              ----------
              Layers:
                  ----------
                  Pulled:
                      - 78032de49d65
                      - 837546b20bc4
                      - 9b8316af6cc6
                      - 86f3913b029a
                      - 4cbbfc9aebab
                      - 1056cf29b9f1
                      - 45d90f823f97
                      - ca2a791aeb35
                      - f49cf87b52c1
                      - 8ffd0352f6a8
              Status:
                  Downloaded newer image for mysql:latest
              Time_Elapsed:
                  45.5688691139

On older version of docker-py (2.6.1)

install-docker-python-package:
  pip.installed:
    - name: docker < 2.7
    - reload_modules: true
    - require:
      - pkg: python-pip
Salt Version:
           Salt: 2017.7.1
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.4.2
      docker-py: 2.6.1
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Nov 20 2017, 18:23:56)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

Salt is downloading images during first try

Setup

State which can reproduce issue

install-docker:
  pkg.installed:
    - name: docker-engine
    - version: 1.12.6*

enable-docker-service:
  service.running:
    - name: docker
    - enable: True

install-python-pip:
  pkg.installed:
    - name: python-pip
  pip.installed:
    - name: pip
    - upgrade: True

install-docker-python-package:
  pip.installed:
    - name: docker
    - reload_modules: true
    - require:
      - pkg: python-pip

fetch-mysql_image-image:
  docker_image.present:
    - name: mysql
    - require:
      - install-docker-python-package

Steps to Reproduce Issue

Add repo for docker and run state

Versions Report

Salt Version:
           Salt: 2017.7.1
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.4.2
      docker-py: 2.7.0
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Nov 20 2017, 18:23:56)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4
 
System Versions:
           dist: Ubuntu 16.04 xenial
         locale: ANSI_X3.4-1968
        machine: x86_64
        release: 4.4.0-104-generic
         system: Linux
        version: Ubuntu 16.04 xenial
@garethgreenaway garethgreenaway added this to the Approved milestone Jan 5, 2018
@garethgreenaway garethgreenaway added Bug broken, incorrect, or confusing behavior severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around P2 Priority 2 labels Jan 5, 2018
@garethgreenaway
Copy link
Contributor

@terminalmage Have you seen this?

@terminalmage terminalmage self-assigned this Feb 2, 2018
@terminalmage
Copy link
Contributor

The only way we get to that traceback is if an unexpected exception is raised within docker-py. When docker-py catches API (or other) errors, it will raise its own custom exception class. Looking at docker-py's commit history, they did make a change involving the minimum version of requests a few weeks before releasing 2.7.0, and that's where the universaldetector bit comes from (requests bundles chardet).

On Salt's end, the only thing I can think of is that when we reload the modules, we still may have a cached docker client stored in the __context__ dunder. Can you try editing dockermod.py and putting the following line as the first line in the __virtual__() function?

__context__.pop('docker.client', None)

Then repeat the steps you took to reproduce. Also, it's important to note whether or not the act of installing docker-py 2.7.0 resulted in upgrading requests, since this commit new to docker-py 2.7.0 modifies the requirements so that the minimum supported version is raised. What I am guessing happened is that you had an older version of requests, and so the pip install caused requests to also be upgraded, but there was already a cached instance of the docker client in the __context__ dunder which had the old requests module loaded in memory, and then some code in requests tried to import something that no longer exists in newer versions.

@terminalmage
Copy link
Contributor

Actually, that theory of mine may be negated if you didn't actually have docker-py installed when you ran those states, because we wouldn't have had the cached client in memory.

@terminalmage
Copy link
Contributor

I actually can't reproduce this either way, I tried locally and it "just works" whether or not I had 2.6.1 installed prior to installing 2.7.0, and it does this irrespective of the prior version of requests. I tried with requests 2.18.4 already installed, as well as by downgrading it to requests 2.6 before running the salt states. In all cases, docker-py 2.7.0 was installed (I had to pin the version in my pip.installed state to 2.7.0 since they've had a version bump to 3.x recently), and the docker_image.present state successfully pulled an image for me.

@terminalmage terminalmage added the cannot-reproduce cannot be replicated with info/context provided label May 12, 2018
@hemebond
Copy link
Contributor

hemebond commented Sep 26, 2018

In trying to narrow down a similar issue, I've also hit this message/bug.

testminion:
    Salt Version:
               Salt: 2017.7.7
     
    Dependency Versions:
               cffi: Not Installed
           cherrypy: Not Installed
           dateutil: 2.2
          docker-py: 3.5.0
              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: Not Installed
           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.7 
             locale: ANSI_X3.4-1968
            machine: x86_64
            release: 3.16.0-4-amd64
             system: Linux
            version: debian 8.7
install pip2:
  pkg.purged:
    - name: python-pip
  cmd.script:
    - name: salt://pip/files/get-pip2.py
    - unless: pip --version
    - require:
      - pkg: install pip2
    - reload_modules: True

docker-repo:
  pkgrepo.managed:
    - name: deb https://apt.dockerproject.org/repo {{ grains["os"]|lower }}-{{ grains["oscodename"] }} main
    - humanname: {{ grains["os"] }} {{ grains["oscodename"]|capitalize }} Docker Package Repository
    - keyid: 58118E89F3A912897C070ADBF76221572C52609D
    - keyserver: hkp://p80.pool.sks-keyservers.net:80
    - refresh_db: True

docker-engine:
  pkg.installed:
    - require:
      - pkgrepo: docker-repo

docker:
  pip.installed:
    - reload_modules: True
    - require:
      - pkg: docker-engine

container:
  docker_container.running:
    - name: nginx
    - image: nginx:latest
    - require:
      - pip: docker
    - restart_policy: unless-stopped

Tested with that __context__ line added and there was no difference.

2018-09-26 02:21:27,876 [salt.state       :939 ][DEBUG   ][8025] Refreshing modules...
2018-09-26 02:21:27,893 [salt.state       :905 ][INFO    ][8025] Loading fresh modules for state activity

@dawidmalina
Copy link

@terminalmage i have exactly same issue. But the problem is that it's working with 2nd round. So looks like first round did not refresh modules even if reload_modules: True is provided.

@terminalmage
Copy link
Contributor

@hemebond the two log lines show that modules are being reloaded.

@dawidmalina I know for a fact that module reloading works, because we have exhaustive integration tests that make sure it does.

Unless I can get a reproducible test case, there's not much I can do. I tried to reproduce pretty extensively and was not able to.

I'm not denying that the problem exists, but I don't have enough information on the edge case we're hitting here to be able to move forward.

@dawidmalina
Copy link

Wired, it started to work when i change from:

install-docker:
  pip.installed:
    - name: docker
    - reload_modules: True

to

install-docker-compose:
  pip.installed:
    - name: docker-compose
    - reload_modules: True

It must be somehow related dependencies.

@hemebond
Copy link
Contributor

hemebond commented Oct 3, 2018

I'm no longer able to reproduce this particular error message.

@kubadawczynski
Copy link
Author

@terminalmage this is state which can reproduce error

add-docker-ce-repo:
  pkgrepo.managed:
    - name: deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable
    - file: /etc/apt/sources.list.d/docker-ce.list
    - key_url: https://download.docker.com/linux/ubuntu/gpg
    - clean_file: true
    - refresh: False

install-docker-ce:
  pkg.installed:
    - name: docker-ce
    - version: 18.06.1*
    - hold: True

enable-docker-service:
  service.running:
    - name: docker
    - enable: True

install-python-pip:
  pkg.installed:
    - name: python-pip
  pip.installed:
    - name: pip ==18.0
    - upgrade: True
    - reload_modules: True

install-docker-package:
  pip.installed:
    - name: docker
    - reload_modules: True

fetch-mysql_image-image:
  docker_image.present:
    - name: mysql

and we have

...
----------
          ID: install-docker-package
    Function: pip.installed
        Name: docker
      Result: True
     Comment: All packages were successfully installed
     Started: 20:47:14.170534
    Duration: 4579.596 ms
     Changes:   
              ----------
              docker==3.5.0:
                  Installed
----------
          ID: fetch-alpine_image-image
    Function: docker_image.present
        Name: alpine
      Result: False
     Comment: Encountered error pulling alpine: Unable to perform images: cannot import name universaldetector
     Started: 20:47:18.777293
    Duration: 2.831 ms
     Changes: 

and second try

----------
          ID: install-docker-package
    Function: pip.installed
        Name: docker
      Result: True
     Comment: Python package docker was already installed
              All specified packages are already installed
     Started: 20:48:17.335664
    Duration: 588.353 ms
     Changes:   
----------
          ID: fetch-alpine_image-image
    Function: docker_image.present
        Name: alpine
      Result: True
     Comment: Image 'alpine' was pulled
     Started: 20:48:17.925325
    Duration: 20876.294 ms
     Changes:   
              ----------
              Layers:
                  ----------
                  Pulled:
                      - 2a3ebcb7fbcc
                      - 4dea34575ff3
                      - 745c22e975cc
                      - 2fa564ffa894
                      - 3a1c32d5b278
                      - d6a5679aa3cf
                      - 24cc62de2ac9
                      - 3489d1c4660e
                      - c67f3896b22c
                      - 4fe2ade4980c
                      - a0e0ef996968
              Status:
                  Downloaded newer image for alpine
              Time_Elapsed:
                  1.98710298538
              retcode:
                  0

@dawidmalina is right when we are installing docker-compose instead of docker package

add-docker-ce-repo:
  pkgrepo.managed:
    - name: deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable
    - file: /etc/apt/sources.list.d/docker-ce.list
    - key_url: https://download.docker.com/linux/ubuntu/gpg
    - clean_file: true
    - refresh: False

install-docker-ce:
  pkg.installed:
    - name: docker-ce
    - version: 18.06.1*
    - hold: True

enable-docker-service:
  service.running:
    - name: docker
    - enable: True

install-python-pip:
  pkg.installed:
    - name: python-pip
  pip.installed:
    - name: pip ==18.0
    - upgrade: True
    - reload_modules: True

install-docker-compose:
  pip.installed:
    - name: docker-compose == 1.21.2
    - reload_modules: True

fetch-alpine_image-image:
  docker_image.present:
    - name: alpine

fetch works on first iteration

everything tested on salt 2018.3.2 and ubuntu 16.04

Salt Version:
           Salt: 2018.3.2
 
Dependency Versions:
           cffi: Not Installed
       cherrypy: 3.5.0
       dateutil: 2.4.2
      docker-py: 3.5.0
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Dec  4 2017, 14:50:18)
   python-gnupg: 0.3.8
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4
 
System Versions:
           dist: Ubuntu 16.04 xenial
         locale: ANSI_X3.4-1968
        machine: x86_64
        release: 4.4.0-135-generic
         system: Linux
        version: Ubuntu 16.04 xenial

@diepes
Copy link
Contributor

diepes commented Oct 11, 2018

I just triggered the "Unable to perform images: cannot import name universaldetector" salt error.

ID: pull down docker_image xxx
Comment: Encountered error pulling xxx.io/xxx.service.xx:latest: Unable to perform images: cannot import name universaldetector

pip freeze | grep docker

docker==3.5.0
docker-pycreds==0.3.0

salt-call --versions-report

Salt Version:
Salt: 2018.3.2

Dependency Versions:
cffi: 1.11.5
cherrypy: Not Installed
dateutil: 2.4.2
docker-py: 3.5.0
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.8
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: 1.0.3
msgpack-pure: Not Installed
msgpack-python: 0.4.6
mysql-python: 1.3.7
pycparser: 2.19
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 2.7.12 (default, Dec 4 2017, 14:50:18)
python-gnupg: 0.3.8
PyYAML: 3.11
PyZMQ: 15.2.0
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.1.4

System Versions:
dist: Ubuntu 16.04 xenial
locale: UTF-8
machine: x86_64
release: 4.15.0-1018-azure
system: Linux
version: Ubuntu 16.04 xenial

@diepes
Copy link
Contributor

diepes commented Nov 23, 2018

Also hit this bug now

Looking at vm without the error i down-graded two pip packages
httplib2==0.12.0 -> 0.11.3
requests==2.20.1 -> 2.20.0

Still got the error below, restart salt-minion, the error is gone.

Upgrade both back to original versions
httplib2==0.12.0
requests==2.20.1

restart salt-minion, problem still gone :(

Here is what the error looked like before it disappeared, tried multiple times got the same error.

----------
          ID: pull down docker_image for xxx
    Function: docker_image.present
        Name: xxx.xxx/xxx:latest
      Result: False
     Comment: Encountered error pulling xxx.xxx/xxx:latest: Unable to perform images: cannot import name universaldetector
     Started: 04:43:16.175522
    Duration: 5.978 ms
     Changes:   
----------

$ sudo pip freeze | grep "docker|request|urllib|salt"
docker==3.5.1
docker-pycreds==0.3.0
requests==2.20.1
salt==2018.3.3
urllib3==1.24.1

$ sudo salt-call --versions-report
Salt Version:
Salt: 2018.3.3

Dependency Versions:
cffi: 1.11.5
cherrypy: Not Installed
dateutil: 2.4.2
docker-py: 3.5.1
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.8
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: 1.0.3
msgpack-pure: Not Installed
msgpack-python: 0.4.6
mysql-python: Not Installed
pycparser: 2.19
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 2.7.12 (default, Nov 12 2018, 14:36:49)
python-gnupg: 0.3.8
PyYAML: 3.11
PyZMQ: 15.2.0
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.1.4

System Versions:
dist: Ubuntu 16.04 xenial
locale: UTF-8
machine: x86_64
release: 4.15.0-1030-azure
system: Linux
version: Ubuntu 16.04 xenial

@diepes
Copy link
Contributor

diepes commented Nov 26, 2018

One more vm with the error.

    Function: docker_image.present
        Name: xxx:latest
      Result: False
     Comment: Encountered error pulling xxx:latest: Unable to perform images: cannot import name universaldetector

Tried multiple times from salt-master, gave the same error.

Fix/work around was to restart the salt-minion

@martinm82
Copy link

martinm82 commented Dec 17, 2018

I am hitting the same error as well. After moving from docker-py (1.10.x) to docker (3.5.1) I constantly hit this issue when provisioning a node from scratch.

The second run is always successful.

Any insights on this issue? Should we use the old docker-py module instead? If yes, then maybe the docs should be updated?

@terminalmage
Copy link
Contributor

I've never been able to reproduce it... Are you making sure to uninstall docker-py when you install the docker Python package?

@hemebond
Copy link
Contributor

hemebond commented Dec 17, 2018

@terminalmage Do you have an example of the states you use for testing as well as the test.versions and pip.freeze before you highstate?

Edit 1: running each step manually using execution modules works fine.
Edit 2: I can't find any combination that works in a single run. Even using the old Docker state module fails with the universaldetector error.

@terminalmage
Copy link
Contributor

terminalmage commented Dec 18, 2018

@hemebond https://gist.github.com/terminalmage/b4e8c5998d1d6304ce1ce4bd9946aef2

I'm running this on the head of the 2018.3 branch, on Arch Linux. Version 1.10.6 of docker-py was installed prior to running the states. The pip freeze output is in the debug logging included in the gist.

Perhaps the reason some of you are seeing this error is because you're not uninstalling docker-py? Both the docker-py and docker modules are installed to the same location, so having the old files present when you install docker may cause problems. This is why our docs are quite explicit about the need to remove the old module if upgrading to the newer module.

@hemebond
Copy link
Contributor

hemebond commented Dec 18, 2018

Version 1.10.6 of docker-py was installed prior to running the states.

Does it still work if you have never had docker and docker-py (and their dependencies) installed? I'm testing with a completely new server.

@terminalmage
Copy link
Contributor

Yes, it still works. I recreated the virtualenv I have been using for testing, deleted the image, and re-ran the SLS file. The result was the same.

@martinm82
Copy link

martinm82 commented Dec 19, 2018

I am using kitchen ci with a bento/ubuntu-16.04 vagrant box. The vm does not contain at the beginning neither python nor any pip modules. After creating the initial vm I ran pip freeze which just failed since I haven't installed yet anything on it.

Our salt setup installed before the docker-py module which I changed to docker. So I am 100% sure that I always use a fresh vm without anything on it.

As said already by others, right after the failure if I run a salt run again it works.

EDIT: I am using a masterless workflow via kitchen-salt

@terminalmage
Copy link
Contributor

If you can share the Vagrantfile and steps to reproduce, I can try to do so.

@martinm82
Copy link

Hi @terminalmage,

after playing a bit around I have now a combination that works:

  • pip: 18.0
  • docker: 2.6.1

I get the universaldetector error with

  • pip 18.0 and docker 3.5.1 and
  • pip 9.0.1 and docker 2.6.1 or 3.5.1

This is the vagrantfile generated by kitchen-vagrant:

Vagrant.configure("2") do |c|
  c.berkshelf.enabled = false if Vagrant.has_plugin?("vagrant-berkshelf")
  c.vm.box = "bento/ubuntu-16.04"
  c.vm.hostname = "ubuntu-1604"
  c.vm.synced_folder ".", "/vagrant", disabled: true
  c.vm.provider :virtualbox do |p|
    p.customize ["modifyvm", :id, "--memory", "2048"]
    p.customize ["modifyvm", :id, "--cpus", "2"]
    p.customize ["modifyvm", :id, "--audio", "none"]
  end
end

For the reproduction steps I will need to extract the important pieces from our setup. I will get back to it tomorrow.

@hemebond
Copy link
Contributor

I still get the universaldetector error with the 18.0/2.6.1 combo 😞

@terminalmage
Copy link
Contributor

@martinm82 thanks!

@martinm82
Copy link

@terminalmage The sls file could be probably made smaller but at least I can use it to reproduce the issue:

https://gist.github.com/martinm82/f3a31d011ed765ccc9101d0fc4614dca

@terminalmage
Copy link
Contributor

@martinm82 where are the files in your salt fileserver coming from? Also, salt isn't installed using the Vagrantfile you provided, so did you simply use salt-bootstrap? If so, please provide the bootstrap command you used so that I can get this as close as possible to your setup.

@martinm82
Copy link

martinm82 commented Dec 21, 2018

@terminalmage I am using just salt-bootstrap.

BTW, I think I might know what the problem is. I figured out that the salt modules are stored inside /usr/lib/python2.7/dist-packages whereas the docker module under /usr/local/lib/python2.7/dist-package.
I will dig deeper why I have this difference.

EDIT: Seems to be caused by the fact I am installing pip with easy_install

@terminalmage
Copy link
Contributor

That might be a problem. What happens if you delete pip from /usr/local/lib and install it from your apt sources?

@martinm82
Copy link

martinm82 commented Dec 21, 2018

I am using now the python-pip package of ubuntu xenial which is pretty old version 8.1.1 and you won't believe it but it works.

The problem is, the docker package is still installed under /usr/local/lib/python27 whereas there is a whole bunch of other packages installed in /usr/lib/python27/. So apparently this cannot be the problem.

Before changing to system pip package I as well dumped in Salt the sys.path to see whether both /usr/lib/python27 and /usr/local/lib/python27 are in the path and yes, they are.

@martinm82
Copy link

The location where the custom pip packages are installed is not the problem. I am using now python-pip 8.1.1 from xenial and it still installs the packages to /usr/local/lib/python27 but I am not facing any issue when running a docker container in salt.

So the only reliable solution right now is to use a pretty old version from xenial. Any approach to update pip (with pip --upgrade or with uninstalling pip and installing it with easy_install) results in failures in salt when trying to run a container.

@hemebond
Copy link
Contributor

hemebond commented Feb 25, 2019

I've upgraded to 2018.3.3 on Debian Jessie and it's still an issue.

          ID: Service Container
    Function: docker_container.running
        Name: my-service
      Result: False
     Comment: Failed to pull xxxxxxxxxxxxxxxxxxx: Unable to perform images: cannot import name universaldetector
     Started: 22:52:18.604940
    Duration: 4.509 ms
     Changes:   

A similar issue happens on Debian Stretch but it's a different module (within idna) that can't be imported.

An exception occurred in this state: Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1913, in call
    **cdata['kwargs'])
  File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1898, in wrapper
    return f(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/states/docker_container.py", line 1676, in running
    image_id = _resolve_image(ret, image, client_timeout)
  File "/usr/lib/python2.7/dist-packages/salt/states/docker_container.py", line 193, in _resolve_image
    image_id = __salt__['docker.resolve_image_id'](image)
  File "/usr/lib/python2.7/dist-packages/salt/modules/dockermod.py", line 1896, in resolve_image_id
    inspect_result = inspect_image(name)
  File "/usr/lib/python2.7/dist-packages/salt/modules/dockermod.py", line 1828, in inspect_image
    ret = _client_wrapper('inspect_image', name)
  File "/usr/lib/python2.7/dist-packages/salt/modules/dockermod.py", line 414, in wrapper
    __context__['docker.client'] = _get_client(timeout=timeout, **kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/modules/dockermod.py", line 378, in _get_client
    ret = docker.APIClient(**client_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/docker/api/client.py", line 185, in __init__
    self._version = self._retrieve_server_version()
  File "/usr/local/lib/python2.7/dist-packages/docker/api/client.py", line 210, in _retrieve_server_version
    'Error while fetching server API version: {0}'.format(e)
DockerException: Error while fetching server API version: No module named uts46data

Again, restarting the minion allows it to work.

@sagetherage
Copy link
Contributor

closing this issue as that the Open Core Team won't fix for now since it is Python 2.7 which we will stop supporting in the Sodium release this month, and given the age of the issue. if this issue still exists with Python 3 please open a new issue. With the many changes in Salt and Docker it will help to have a updated details on the existing problem.

@terminalmage
Copy link
Contributor

@sagetherage It seems that you have misunderstood the nature of this issue. There is nothing Python 2-specific about it.

I still don't think this is a Salt bug, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior cannot-reproduce cannot be replicated with info/context provided P2 Priority 2 severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Projects
None yet
Development

No branches or pull requests

8 participants