The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/pylxd/pull/124
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Cache LXD host info so that it can be queried via the API. Signed-off-by: Chuck Short <chuck.sh...@canonical.com>
From d240d5abc6b537f3835cc18aa50e8f5245e1ad20 Mon Sep 17 00:00:00 2001 From: Chuck Short <chuck.sh...@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.sh...@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."""
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel