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

pylxd Connection error on fresh installed LXD from snap #365

Closed
gabrik opened this issue Jun 4, 2019 · 2 comments · Fixed by #366
Closed

pylxd Connection error on fresh installed LXD from snap #365

gabrik opened this issue Jun 4, 2019 · 2 comments · Fixed by #366
Labels

Comments

@gabrik
Copy link
Contributor

gabrik commented Jun 4, 2019

Hi all,

I'm experiencing some issue in using pylxd on a fresh installed machine.

>>> from pylxd import Client
>>> c = Client()
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 560, in urlopen
    body=body, headers=headers)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 354, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.5/http/client.py", line 1106, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1151, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.5/http/client.py", line 1102, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
    self.send(msg)
  File "/usr/lib/python3.5/http/client.py", line 877, in send
    self.connect()
  File "/usr/local/lib/python3.5/dist-packages/requests_unixsocket/adapters.py", line 32, in connect
    sock.connect(socket_path)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 376, in send
    timeout=timeout
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 610, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 247, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/lib/python3/dist-packages/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 560, in urlopen
    body=body, headers=headers)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 354, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.5/http/client.py", line 1106, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1151, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.5/http/client.py", line 1102, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
    self.send(msg)
  File "/usr/lib/python3.5/http/client.py", line 877, in send
    self.connect()
  File "/usr/local/lib/python3.5/dist-packages/requests_unixsocket/adapters.py", line 32, in connect
    sock.connect(socket_path)
requests.packages.urllib3.exceptions.ProtocolError: ('Connection aborted.', ConnectionRefusedError(111, 'Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/pylxd/client.py", line 299, in __init__
    response = self.api.get()
  File "/usr/local/lib/python3.5/dist-packages/pylxd/client.py", line 149, in get
    response = self.session.get(self._api_endpoint, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 480, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 426, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionRefusedError(111, 'Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/pylxd/client.py", line 306, in __init__
    raise exceptions.ClientConnectionFailed()
pylxd.exceptions.ClientConnectionFailed

Ubuntu 16.04
LXD 3.13 from snap
all default lxd init
pylxd 2.2.10

Just for information,
same pylxd and LXD version on Ubuntu 18.04 works

Any idea?

@stgraber
Copy link
Contributor

Who are you running this as?

@ajkavanagh
Copy link
Contributor

Yup, I've reproduced this. It's basically, the "pkg or snap" socket detection software that fails because the socket that the pkg lxd used is still there after the package has been removed and the daemon is no longer running (or exists). The detection behaviour changed to "package first" from "snap first" ... in retrospect, this was a mistake.

Workarounds:

  1. Delete /var/lib/lxd/unix.socket socket after doing snap install lxd and lxd.migrate -yes to ensure that the old socket is removed; OR
  2. Use the LXD_DIR environment variable to override the unix.socket path as LXD_DIR=/var/snap/lxd/common/lxd when running the associated script.

@ajkavanagh ajkavanagh added the bug label Jun 10, 2019
ajkavanagh added a commit to ajkavanagh/pylxd that referenced this issue Jun 10, 2019
A previous change (which added LXD_DIR) switched around the detection of
whether LXD is installed as a snap or a package to "test for packaged
first".  Unfortunately, the LXD pkg leaves behind the unix socket after
it is uninstalled when the snap is installed on xenial and a lxd.migrate
command is issued.  This means that the detection code fails.  This
patch reverts the behaviour to look "test for snapped first".

This is reasonable as the only way that a both unix socket files could
exist is if the snapped version was added to a pkg version default
install (e.g. Xenial).  As running both isn't really a supported
scenario, the default of checking for the snap first is more likely to
work in most default scenarios.  The LXD_DIR environment variable is
still available if it needs overriding for the corner cases.

Fixes: canonical#365
ajkavanagh added a commit to ajkavanagh/pylxd that referenced this issue Jun 10, 2019
A previous change (which added LXD_DIR) switched around the detection of
whether LXD is installed as a snap or a package to "test for packaged
first".  Unfortunately, the LXD pkg leaves behind the unix socket after
it is uninstalled when the snap is installed on xenial and a lxd.migrate
command is issued.  This means that the detection code fails.  This
patch reverts the behaviour to look "test for snapped first".

This is reasonable as the only way that a both unix socket files could
exist is if the snapped version was added to a pkg version default
install (e.g. Xenial).  As running both isn't really a supported
scenario, the default of checking for the snap first is more likely to
work in most default scenarios.  The LXD_DIR environment variable is
still available if it needs overriding for the corner cases.

Fixes: canonical#365
Signed-off-by: Alex Kavanagh <alex.kavanagh@canonical.com>
ajkavanagh added a commit to ajkavanagh/pylxd that referenced this issue Jun 11, 2019
A previous change (which added LXD_DIR) switched around the detection of
whether LXD is installed as a snap or a package to "test for packaged
first".  Unfortunately, the LXD pkg leaves behind the unix socket after
it is uninstalled when the snap is installed on xenial and a lxd.migrate
command is issued.  This means that the detection code fails.  This
patch reverts the behaviour to look "test for snapped first".

This is reasonable as the only way that a both unix socket files could
exist is if the snapped version was added to a pkg version default
install (e.g. Xenial).  As running both isn't really a supported
scenario, the default of checking for the snap first is more likely to
work in most default scenarios.  The LXD_DIR environment variable is
still available if it needs overriding for the corner cases.

Fixes: canonical#365
Signed-off-by: Alex Kavanagh <alex.kavanagh@canonical.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants