Fix support for k8s-client 4.0

The new release of kubernetes python client improved the validation,
so we need to ediot our test to create the right fake objects.
As well, kubernetes.client.ConnectionObject was renamed to just `Connection`
and we should handle this.

Change-Id: I1a3275a8a5a3d729ce507689ab38e3c3d54d3c77
This commit is contained in:
Andrey Kurilin 2018-02-19 19:14:12 +02:00
parent 386777598f
commit 36402266ff
4 changed files with 42 additions and 20 deletions

View File

@ -163,7 +163,11 @@ class MagnumScenario(scenario.OpenStackScenario):
cert_file = os.path.join(dir, cert_file)
ca_certs = cluster_uuid + "_ca.crt"
ca_certs = os.path.join(dir, ca_certs)
config = k8s_config.ConfigurationObject()
if hasattr(k8s_config, "ConfigurationObject"):
# k8sclient < 4.0.0
config = k8s_config.ConfigurationObject()
else:
config = k8s_config.Configuration()
config.host = cluster.api_address
config.ssl_ca_cert = ca_certs
config.cert_file = cert_file

View File

@ -30,4 +30,4 @@ python-swiftclient>=3.2.0 # Apache Software License
python-troveclient>=2.2.0 # Apache Software License
python-watcherclient>=1.1.0 # Apache Software License
python-zaqarclient>=1.0.0 # Apache Software License
kubernetes>1.0.0,<4.0.0 # Apache License Version 2.0
kubernetes>1.0.0 # Apache License Version 2.0

View File

@ -16,6 +16,7 @@ import os
import mock
from kubernetes import client as kubernetes_client
from kubernetes.client import api_client
from kubernetes.client.rest import ApiException
from rally import exceptions
@ -135,9 +136,18 @@ class MagnumScenarioTestCase(test.ScenarioTestCase):
@mock.patch("kubernetes.client.api_client.ApiClient")
@mock.patch("kubernetes.client.apis.core_v1_api.CoreV1Api")
@mock.patch("kubernetes.client.ConfigurationObject")
def test_get_k8s_api_client_using_tls(self, mock_configuration_object,
mock_core_v1_api, mock_api_client):
def test_get_k8s_api_client_using_tls(self, mock_core_v1_api,
mock_api_client):
if hasattr(kubernetes_client, "ConfigurationObject"):
# it is k8s-client < 4.0.0
m = mock.patch("kubernetes.client.ConfigurationObject")
else:
m = mock.patch("kubernetes.client.Configuration")
mock_configuration_object = m.start()
self.addCleanup(m.stop)
self.context.update({
"ca_certs_directory": "/home/stack",
"tenant": {
@ -169,9 +179,17 @@ class MagnumScenarioTestCase(test.ScenarioTestCase):
@mock.patch("kubernetes.client.api_client.ApiClient")
@mock.patch("kubernetes.client.apis.core_v1_api.CoreV1Api")
@mock.patch("kubernetes.client.ConfigurationObject")
def test_get_k8s_api_client(self, mock_configuration_object,
mock_core_v1_api, mock_api_client):
def test_get_k8s_api_client(self, mock_core_v1_api, mock_api_client):
if hasattr(kubernetes_client, "ConfigurationObject"):
# it is k8s-client < 4.0.0
m = mock.patch("kubernetes.client.ConfigurationObject")
else:
m = mock.patch("kubernetes.client.Configuration")
mock_configuration_object = m.start()
self.addCleanup(m.stop)
self.context.update({
"tenant": {
"id": "rally_tenant_id",
@ -227,16 +245,17 @@ class MagnumScenarioTestCase(test.ScenarioTestCase):
almost_ready_status.phase = "almost_ready"
almost_ready_pod.status = almost_ready_status
ready_pod = api_client.models.V1Pod()
ready_condition = api_client.models.V1PodCondition()
ready_condition.status = "True"
ready_condition.type = "Ready"
ready_condition = api_client.models.V1PodCondition(status="True",
type="Ready")
ready_status = api_client.models.V1PodStatus()
ready_status.phase = "Running"
ready_status.conditions = [ready_condition]
ready_pod_metadata = api_client.models.V1ObjectMeta()
ready_pod_metadata.uid = "123456789"
ready_pod_spec = api_client.models.V1PodSpec()
ready_pod_spec.node_name = "host_abc"
ready_pod_spec = api_client.models.V1PodSpec(
node_name="host_abc",
containers=[]
)
ready_pod.status = ready_status
ready_pod.metadata = ready_pod_metadata
ready_pod.spec = ready_pod_spec
@ -309,12 +328,12 @@ class MagnumScenarioTestCase(test.ScenarioTestCase):
k8s_api.create_namespaced_replication_controller.return_value = rc
not_ready_rc = api_client.models.V1ReplicationController()
not_ready_rc_status = (
api_client.models.V1ReplicationControllerStatus())
not_ready_rc_status.replicas = 0
api_client.models.V1ReplicationControllerStatus(replicas=0))
not_ready_rc.status = not_ready_rc_status
ready_rc = api_client.models.V1ReplicationController()
ready_rc_status = api_client.models.V1ReplicationControllerStatus()
ready_rc_status.replicas = manifest["spec"]["replicas"]
ready_rc_status = api_client.models.V1ReplicationControllerStatus(
replicas=manifest["spec"]["replicas"]
)
ready_rc_metadata = api_client.models.V1ObjectMeta()
ready_rc_metadata.uid = "123456789"
ready_rc_metadata.name = rcname
@ -352,8 +371,7 @@ class MagnumScenarioTestCase(test.ScenarioTestCase):
k8s_api.create_namespaced_replication_controller.return_value = rc
not_ready_rc = api_client.models.V1ReplicationController()
not_ready_rc_status = (
api_client.models.V1ReplicationControllerStatus())
not_ready_rc_status.replicas = 0
api_client.models.V1ReplicationControllerStatus(replicas=0))
not_ready_rc_metadata = api_client.models.V1ObjectMeta()
not_ready_rc_metadata.uid = "123456789"
not_ready_rc.status = not_ready_rc_status

View File

@ -5,7 +5,7 @@ gnocchiclient===7.0.1
Jinja2===2.10
jsonschema===2.6.0
keystoneauth1===3.4.0
kubernetes===3.0.0
kubernetes===4.0.0
morph===0.1.2
netaddr===0.7.19
os-faults===0.1.17