From 9b6f572b752ae0f77437ff3018fbf3db41591b4b Mon Sep 17 00:00:00 2001 From: Steve Milner Date: Wed, 7 Dec 2016 15:15:25 -0500 Subject: [PATCH] containermgr: Added get_node_status to kubernetes handler. --- src/commissaire/containermgr/kubernetes/__init__.py | 12 +++++++----- test/test_containermgr_kubernetes.py | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/commissaire/containermgr/kubernetes/__init__.py b/src/commissaire/containermgr/kubernetes/__init__.py index 1cf24bb..5a3081e 100644 --- a/src/commissaire/containermgr/kubernetes/__init__.py +++ b/src/commissaire/containermgr/kubernetes/__init__.py @@ -262,7 +262,7 @@ def node_registered(self, name): return True return False - def get_host_status(self, address, raw=False): + def get_node_status(self, address, raw=False): """ Returns the node status. @@ -275,10 +275,12 @@ def get_host_status(self, address, raw=False): """ part = '/nodes/{}'.format(address) resp = self._get(part) - data = resp.json() - if raw: - data = data['status'] - return (resp.status_code, data) + if resp.status_code == 200: + data = resp.json() + if raw: + data = data['status'] + return data + return False #: Common name for the class diff --git a/test/test_containermgr_kubernetes.py b/test/test_containermgr_kubernetes.py index 13b5586..115fd47 100644 --- a/test/test_containermgr_kubernetes.py +++ b/test/test_containermgr_kubernetes.py @@ -126,9 +126,9 @@ def test_remove_node(self): self.instance.con.delete.assert_called_once_with( CONTAINER_MGR_CONFIG['server_url'] + 'api/v1/nodes/test') - def test_get_host_status(self): + def test_get_node_status(self): """ - Verify get_host_status makes the proper remote call. + Verify get_node_status makes the proper remote call. """ data = {'data': 'data', 'status': 'status'} for raw, result in ((True, 'status'), (False, data)): @@ -136,7 +136,7 @@ def test_get_host_status(self): resp = mock.MagicMock(json=mock.MagicMock(return_value=data)) self.instance.con.get.return_value = resp self.instance.con.get().status_code = 200 - self.assertEquals((200, result), self.instance.get_host_status('test', raw)) + self.assertEquals(result, self.instance.get_node_status('test', raw)) self.instance.con.get.assert_called_with( CONTAINER_MGR_CONFIG['server_url'] + 'api/v1/nodes/test')