slipstream / SlipStreamClient

SlipStream Python client
Apache License 2.0
1 stars 4 forks source link

urllib3 not always packaged with Requests #359

Closed 0xbase12 closed 6 years ago

0xbase12 commented 6 years ago

This issue happen in orchestrator on eo-cloudferro-pl1

2017-10-16 17:50:10,958:CRITICAL:NodeExecutor:Traceback (most recent call last):
  File "/opt/slipstream/client/lib/slipstream/daemonr/DaemonRunner.py", line 35, in __init__
    self.run_action(runnable)
  File "/opt/slipstream/client/lib/slipstream/daemonr/DaemonRunner.py", line 61, in run_action
    self.do_action()
  File "/opt/slipstream/client/lib/daemon/runner.py", line 267, in do_action
    func(self)
  File "/opt/slipstream/client/lib/daemon/runner.py", line 186, in _start
    self.app.run()
  File "/opt/slipstream/client/sbin/slipstream-orchestrator", line 125, in run
    self._executor.do_work()
  File "/opt/slipstream/client/sbin/slipstream-orchestrator", line 93, in do_work
    self._callAndHandleErrorsForCommands(self.doWork.__name__)
  File "/opt/slipstream/client/lib/slipstream/command/CommandBase.py", line 140, in _callAndHandleErrorsForCommands
    res = self.__class__.__dict__[methodName](self, *args, **kw)
  File "/opt/slipstream/client/sbin/slipstream-orchestrator", line 98, in doWork
    orchestrator.execute()
  File "/opt/slipstream/client/lib/slipstream/executors/Machine.py", line 39, in execute
    self._publish_abort_and_fail("Machine executor creation failed", ex)
  File "/opt/slipstream/client/lib/slipstream/executors/Machine.py", line 45, in _publish_abort_and_fail
    AbortExceptionPublisher(self.configHolder).publish(message, sys.exc_info())
  File "/opt/slipstream/client/lib/slipstream/executors/Machine.py", line 71, in __init__
    self.ss_client = SlipStreamHttpClient(config_holder)
  File "/opt/slipstream/client/lib/slipstream/SlipStreamHttpClient.py", line 51, in __init__
    self.httpClient = HttpClient(configHolder=configHolder)
  File "/opt/slipstream/client/lib/slipstream/HttpClient.py", line 136, in __init__
    requests.packages.urllib3.disable_warnings()
AttributeError: 'module' object has no attribute 'packages'
0xbase12 commented 6 years ago

The pythonpath in some ubuntu VMs is not set as properly:

import sys
sys.path
['', '/usr/lib/python2.7/dist-packages', '/opt/slipstream/client/lib', '/opt/openstack', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']
import requests
requests.__file__
'/usr/lib/python2.7/dist-packages/requests/__init__.pyc'

As you can see the /opt/slipstream/client/lib come after /usr/lib/python2.7/dist-packages and so if a VM has already requests and urllib3 installed, python will use them from site packages which will be in different version of our requests and urllib3 embded with SlipStream Client.

To fix that issue we should use virtualenv (SixSq/tasklist#1373) or force the system before importing packages to load from /opt/slipstream/client/lib by priority:

import sys
sys.path.insert(1,'/opt/slipstream/client/lib')
import requests
requests.__file__
'/opt/slipstream/client/lib/requests/__init__.py'