[lxc-devel] [pylxd/master] Cache LXD host info
zulcss on Github
lxc-bot at linuxcontainers.org
Tue May 31 18:17:03 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 418 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160531/bb2dfd34/attachment.bin>
-------------- next part --------------
From d240d5abc6b537f3835cc18aa50e8f5245e1ad20 Mon Sep 17 00:00:00 2001
From: Chuck Short <chuck.short at canonical.com>
Date: Tue, 31 May 2016 13:59:34 -0400
Subject: [PATCH] Cache LXD host info
Cache LXD host info so that it can be queried via the API.
Signed-off-by: Chuck Short <chuck.short at canonical.com>
---
pylxd/client.py | 2 ++
pylxd/tests/mock_lxd.py | 3 ++-
pylxd/tests/test_client.py | 14 ++++++++++++--
3 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/pylxd/client.py b/pylxd/client.py
index 9b1d115..bafef29 100644
--- a/pylxd/client.py
+++ b/pylxd/client.py
@@ -130,6 +130,8 @@ def __init__(self, endpoint=None, version='1.0', cert=None, verify=True):
auth = response.json()['metadata']['auth']
if auth != "trusted":
raise exceptions.ClientAuthenticationFailed()
+
+ self.host_info = response.json()['metadata']['environment']
except (requests.exceptions.ConnectionError,
requests.exceptions.InvalidURL):
raise exceptions.ClientConnectionFailed()
diff --git a/pylxd/tests/mock_lxd.py b/pylxd/tests/mock_lxd.py
index 5150503..20e4ec2 100644
--- a/pylxd/tests/mock_lxd.py
+++ b/pylxd/tests/mock_lxd.py
@@ -41,7 +41,8 @@ def profile_GET(request, context):
RULES = [
# General service endpoints
{
- 'text': json.dumps({'metadata': {'auth': 'trusted'}}),
+ 'text': json.dumps({'metadata': {'auth': 'trusted',
+ 'environment': {}}}),
'method': 'GET',
'url': r'^http://pylxd.test/1.0$',
},
diff --git a/pylxd/tests/test_client.py b/pylxd/tests/test_client.py
index 00f12ac..44e3729 100644
--- a/pylxd/tests/test_client.py
+++ b/pylxd/tests/test_client.py
@@ -16,7 +16,10 @@ def setUp(self):
self.get = self.patcher.start()
response = mock.MagicMock(status_code=200)
- response.json.return_value = {'metadata': {'auth': 'trusted'}}
+ response.json.return_value = {'metadata': {
+ 'auth': 'trusted',
+ 'environment': {'storage': 'zfs'},
+ }}
self.get.return_value = response
def tearDown(self):
@@ -67,11 +70,18 @@ def raise_exception():
def test_authentication_failed(self):
"""If the authentication fails, an exception is raised."""
response = mock.MagicMock(status_code=200)
- response.json.return_value = {'metadata': {'auth': 'untrusted'}}
+ response.json.return_value = {'metadata': {'auth': 'untrusted',
+ 'environment': {}
+ }}
self.get.return_value = response
self.assertRaises(exceptions.ClientAuthenticationFailed, client.Client)
+ def test_host_info(self):
+ """Perform a host query """
+ an_client = client.Client()
+ self.assertEqual('zfs', an_client.host_info['storage'])
+
class TestAPINode(unittest.TestCase):
"""Tests for pylxd.client._APINode."""
More information about the lxc-devel
mailing list