summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-02-14 22:56:58 +0000
committerGerrit Code Review <review@openstack.org>2017-02-14 22:56:58 +0000
commitcc40e473352b34f19ce8a169715f3e8a3108ad52 (patch)
tree42a98915d5aaefb0fe05c79ff5469e3fe7349362
parent08c4b3ed728a0b21ca2921e9a149d458157488e2 (diff)
parente634b55637093c1d791f31ed0e0945bffe55e4b8 (diff)
Merge "Switch to kubernetes upstream python client"
-rw-r--r--magnum/conductor/k8s_api.py18
-rw-r--r--magnum/drivers/common/k8s_monitor.py2
-rw-r--r--magnum/tests/functional/python_client_base.py31
-rw-r--r--magnum/tests/unit/conductor/test_monitors.py2
-rw-r--r--requirements.txt2
5 files changed, 32 insertions, 23 deletions
diff --git a/magnum/conductor/k8s_api.py b/magnum/conductor/k8s_api.py
index aa036ff..78e5ffe 100644
--- a/magnum/conductor/k8s_api.py
+++ b/magnum/conductor/k8s_api.py
@@ -14,8 +14,9 @@
14 14
15import tempfile 15import tempfile
16 16
17from k8sclient.client import api_client 17from kubernetes import client as k8s_config
18from k8sclient.client.apis import apiv_api 18from kubernetes.client import api_client
19from kubernetes.client.apis import core_v1_api
19from oslo_log import log as logging 20from oslo_log import log as logging
20 21
21from magnum.conductor.handlers.common.cert_manager import create_client_files 22from magnum.conductor.handlers.common.cert_manager import create_client_files
@@ -24,7 +25,7 @@ from magnum.i18n import _LE
24LOG = logging.getLogger(__name__) 25LOG = logging.getLogger(__name__)
25 26
26 27
27class K8sAPI(apiv_api.ApivApi): 28class K8sAPI(core_v1_api.CoreV1Api):
28 29
29 def _create_temp_file_with_content(self, content): 30 def _create_temp_file_with_content(self, content):
30 """Creates temp file and write content to the file. 31 """Creates temp file and write content to the file.
@@ -50,11 +51,14 @@ class K8sAPI(apiv_api.ApivApi):
50 (self.ca_file, self.key_file, 51 (self.ca_file, self.key_file,
51 self.cert_file) = create_client_files(cluster, context) 52 self.cert_file) = create_client_files(cluster, context)
52 53
54 config = k8s_config.ConfigurationObject()
55 config.host = cluster.api_address
56 config.ssl_ca_cert = self.ca_file.name
57 config.cert_file = self.cert_file.name
58 config.key_file = self.key_file.name
59
53 # build a connection with Kubernetes master 60 # build a connection with Kubernetes master
54 client = api_client.ApiClient(cluster.api_address, 61 client = api_client.ApiClient(config=config)
55 key_file=self.key_file.name,
56 cert_file=self.cert_file.name,
57 ca_certs=self.ca_file.name)
58 62
59 super(K8sAPI, self).__init__(client) 63 super(K8sAPI, self).__init__(client)
60 64
diff --git a/magnum/drivers/common/k8s_monitor.py b/magnum/drivers/common/k8s_monitor.py
index c15cd9e..c6ac147 100644
--- a/magnum/drivers/common/k8s_monitor.py
+++ b/magnum/drivers/common/k8s_monitor.py
@@ -40,7 +40,7 @@ class K8sMonitor(monitors.MonitorBase):
40 40
41 def pull_data(self): 41 def pull_data(self):
42 k8s_api = k8s.create_k8s_api(self.context, self.cluster) 42 k8s_api = k8s.create_k8s_api(self.context, self.cluster)
43 nodes = k8s_api.list_namespaced_node() 43 nodes = k8s_api.list_node()
44 self.data['nodes'] = self._parse_node_info(nodes) 44 self.data['nodes'] = self._parse_node_info(nodes)
45 pods = k8s_api.list_namespaced_pod('default') 45 pods = k8s_api.list_namespaced_pod('default')
46 self.data['pods'] = self._parse_pod_info(pods) 46 self.data['pods'] = self._parse_pod_info(pods)
diff --git a/magnum/tests/functional/python_client_base.py b/magnum/tests/functional/python_client_base.py
index 37de75d..855d3b6 100644
--- a/magnum/tests/functional/python_client_base.py
+++ b/magnum/tests/functional/python_client_base.py
@@ -26,9 +26,10 @@ import fixtures
26from six.moves import configparser 26from six.moves import configparser
27 27
28from heatclient import client as heatclient 28from heatclient import client as heatclient
29from k8sclient.client import api_client
30from k8sclient.client.apis import apiv_api
31from keystoneclient.v3 import client as ksclient 29from keystoneclient.v3 import client as ksclient
30from kubernetes import client as k8s_config
31from kubernetes.client import api_client
32from kubernetes.client.apis import core_v1_api
32 33
33from magnum.common.utils import rmtree_without_raise 34from magnum.common.utils import rmtree_without_raise
34import magnum.conf 35import magnum.conf
@@ -386,26 +387,30 @@ class BaseK8sTest(ClusterTest):
386 def setUpClass(cls): 387 def setUpClass(cls):
387 super(BaseK8sTest, cls).setUpClass() 388 super(BaseK8sTest, cls).setUpClass()
388 cls.kube_api_url = cls.cs.clusters.get(cls.cluster.uuid).api_address 389 cls.kube_api_url = cls.cs.clusters.get(cls.cluster.uuid).api_address
389 k8s_client = api_client.ApiClient(cls.kube_api_url, 390 config = k8s_config.ConfigurationObject()
390 key_file=cls.key_file, 391 config.host = cls.kube_api_url
391 cert_file=cls.cert_file, 392 config.ssl_ca_cert = cls.ca_file
392 ca_certs=cls.ca_file) 393 config.cert_file = cls.cert_file
393 cls.k8s_api = apiv_api.ApivApi(k8s_client) 394 config.key_file = cls.key_file
395 k8s_client = api_client.ApiClient(config=config)
396 cls.k8s_api = core_v1_api.CoreV1Api(k8s_client)
394 397
395 def setUp(self): 398 def setUp(self):
396 super(BaseK8sTest, self).setUp() 399 super(BaseK8sTest, self).setUp()
397 self.kube_api_url = self.cs.clusters.get(self.cluster.uuid).api_address 400 self.kube_api_url = self.cs.clusters.get(self.cluster.uuid).api_address
398 k8s_client = api_client.ApiClient(self.kube_api_url, 401 config = k8s_config.ConfigurationObject()
399 key_file=self.key_file, 402 config.host = self.kube_api_url
400 cert_file=self.cert_file, 403 config.ssl_ca_cert = self.ca_file
401 ca_certs=self.ca_file) 404 config.cert_file = self.cert_file
402 self.k8s_api = apiv_api.ApivApi(k8s_client) 405 config.key_file = self.key_file
406 k8s_client = api_client.ApiClient(config=config)
407 self.k8s_api = core_v1_api.CoreV1Api(k8s_client)
403 # TODO(coreypobrien) https://bugs.launchpad.net/magnum/+bug/1551824 408 # TODO(coreypobrien) https://bugs.launchpad.net/magnum/+bug/1551824
404 utils.wait_for_condition(self._is_api_ready, 5, 600) 409 utils.wait_for_condition(self._is_api_ready, 5, 600)
405 410
406 def _is_api_ready(self): 411 def _is_api_ready(self):
407 try: 412 try:
408 self.k8s_api.list_namespaced_node() 413 self.k8s_api.list_node()
409 self.LOG.info(_LI("API is ready.")) 414 self.LOG.info(_LI("API is ready."))
410 return True 415 return True
411 except Exception: 416 except Exception:
diff --git a/magnum/tests/unit/conductor/test_monitors.py b/magnum/tests/unit/conductor/test_monitors.py
index ef63a61..16e69f1 100644
--- a/magnum/tests/unit/conductor/test_monitors.py
+++ b/magnum/tests/unit/conductor/test_monitors.py
@@ -137,7 +137,7 @@ class MonitorsTestCase(base.TestCase):
137 mock_node.status = mock.MagicMock() 137 mock_node.status = mock.MagicMock()
138 mock_node.status.capacity = {'memory': '2000Ki', 'cpu': '1'} 138 mock_node.status.capacity = {'memory': '2000Ki', 'cpu': '1'}
139 mock_nodes.items = [mock_node] 139 mock_nodes.items = [mock_node]
140 mock_k8s_api.return_value.list_namespaced_node.return_value = ( 140 mock_k8s_api.return_value.list_node.return_value = (
141 mock_nodes) 141 mock_nodes)
142 mock_pods = mock.MagicMock() 142 mock_pods = mock.MagicMock()
143 mock_pod = mock.MagicMock() 143 mock_pod = mock.MagicMock()
diff --git a/requirements.txt b/requirements.txt
index 9a29e38..ccd2934 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -20,6 +20,7 @@ iso8601>=0.1.11 # MIT
20jsonpatch>=1.1 # BSD 20jsonpatch>=1.1 # BSD
21keystoneauth1>=2.18.0 # Apache-2.0 21keystoneauth1>=2.18.0 # Apache-2.0
22keystonemiddleware>=4.12.0 # Apache-2.0 22keystonemiddleware>=4.12.0 # Apache-2.0
23kubernetes>=1.0.0b1 # Apache-2.0
23marathon>=0.8.6 # MIT 24marathon>=0.8.6 # MIT
24netaddr!=0.7.16,>=0.7.13 # BSD 25netaddr!=0.7.16,>=0.7.13 # BSD
25oslo.concurrency>=3.8.0 # Apache-2.0 26oslo.concurrency>=3.8.0 # Apache-2.0
@@ -43,7 +44,6 @@ python-barbicanclient>=4.0.0 # Apache-2.0
43python-glanceclient>=2.5.0 # Apache-2.0 44python-glanceclient>=2.5.0 # Apache-2.0
44python-heatclient>=1.6.1 # Apache-2.0 45python-heatclient>=1.6.1 # Apache-2.0
45python-neutronclient>=5.1.0 # Apache-2.0 46python-neutronclient>=5.1.0 # Apache-2.0
46python-k8sclient>=0.2.0 # Apache-2.0
47python-novaclient>=7.1.0 # Apache-2.0 47python-novaclient>=7.1.0 # Apache-2.0
48python-keystoneclient>=3.8.0 # Apache-2.0 48python-keystoneclient>=3.8.0 # Apache-2.0
49requests!=2.12.2,!=2.13.0,>=2.10.0 # Apache-2.0 49requests!=2.12.2,!=2.13.0,>=2.10.0 # Apache-2.0