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

Avoid changing default endpoint fixes #346 #347

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions pylxd/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,13 @@ def __init__(
endpoint, cert=cert, verify=verify, timeout=timeout)
else:
if 'LXD_DIR' in os.environ:
path = os.path.join(
os.environ.get('LXD_DIR'), 'unix.socket')
path = os.path.join(os.environ.get('LXD_DIR'), 'unix.socket')
elif os.path.exists('/var/lib/lxd/unix.socket'):
path = '/var/lib/lxd/unix.socket'
else:
if os.path.exists('/var/snap/lxd/common/lxd/unix.socket'):
path = '/var/snap/lxd/common/lxd/unix.socket'
else:
path = '/var/lib/lxd/unix.socket'
self.api = _APINode('http+unix://{}'.format(
parse.quote(path, safe='')), timeout=timeout)
path = '/var/snap/lxd/common/lxd/unix.socket'
endpoint = 'http+unix://{}'.format(parse.quote(path, safe=''))
self.api = _APINode(endpoint, timeout=timeout)
self.api = self.api[version]

# Verify the connection is valid.
Expand Down
4 changes: 2 additions & 2 deletions pylxd/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def tearDown(self):
@mock.patch('os.path.exists')
def test_create(self, _path_exists):
"""Client creation sets default API endpoint."""
_path_exists.return_value = False
_path_exists.return_value = True
expected = 'http+unix://%2Fvar%2Flib%2Flxd%2Funix.socket/1.0'

an_client = client.Client()
Expand All @@ -62,7 +62,7 @@ def test_create(self, _path_exists):
@mock.patch('os.environ')
def test_create_with_snap_lxd(self, _environ, _path_exists):
# """Client creation sets default API endpoint."""
_path_exists.return_value = True
_path_exists.return_value = False
expected = ('http+unix://%2Fvar%2Fsnap%2Flxd%2F'
'common%2Flxd%2Funix.socket/1.0')

Expand Down