From 60539224ed11284e42b9a0e50b714845c0b4dcf1 Mon Sep 17 00:00:00 2001 From: Luis Pigueiras Date: Fri, 6 Apr 2018 15:40:46 +0200 Subject: [PATCH] Fix k8s APIClient when k8s-client >= 4.0.0 Change-Id: Iaba735c60be7e598080d28354064a776b3473452 --- rally_openstack/scenarios/magnum/utils.py | 7 ++++++- tests/unit/scenarios/magnum/test_utils.py | 13 +++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/rally_openstack/scenarios/magnum/utils.py b/rally_openstack/scenarios/magnum/utils.py index db0dc0ee..a4731bb9 100644 --- a/rally_openstack/scenarios/magnum/utils.py +++ b/rally_openstack/scenarios/magnum/utils.py @@ -172,7 +172,12 @@ class MagnumScenario(scenario.OpenStackScenario): config.ssl_ca_cert = ca_certs config.cert_file = cert_file config.key_file = key_file - client = api_client.ApiClient(config=config) + if hasattr(k8s_config, "ConfigurationObject"): + # k8sclient < 4.0.0 + client = api_client.ApiClient(config=config) + else: + client = api_client.ApiClient(config) + return core_v1_api.CoreV1Api(client) @atomic.action_timer("magnum.k8s_list_v1pods") diff --git a/tests/unit/scenarios/magnum/test_utils.py b/tests/unit/scenarios/magnum/test_utils.py index 18d38b53..bf3975f7 100644 --- a/tests/unit/scenarios/magnum/test_utils.py +++ b/tests/unit/scenarios/magnum/test_utils.py @@ -174,7 +174,12 @@ class MagnumScenarioTestCase(test.ScenarioTestCase): _api_client = mock_api_client.return_value self.scenario._get_k8s_api_client() mock_configuration_object.assert_called_once_with() - mock_api_client.assert_called_once_with(config=config) + if hasattr(kubernetes_client, "ConfigurationObject"): + # k8s-python < 4.0.0 + mock_api_client.assert_called_once_with(config=config) + else: + mock_api_client.assert_called_once_with(config) + mock_core_v1_api.assert_called_once_with(_api_client) @mock.patch("kubernetes.client.api_client.ApiClient") @@ -211,7 +216,11 @@ class MagnumScenarioTestCase(test.ScenarioTestCase): _api_client = mock_api_client.return_value self.scenario._get_k8s_api_client() mock_configuration_object.assert_called_once_with() - mock_api_client.assert_called_once_with(config=config) + if hasattr(kubernetes_client, "ConfigurationObject"): + # k8s-python < 4.0.0 + mock_api_client.assert_called_once_with(config=config) + else: + mock_api_client.assert_called_once_with(config) mock_core_v1_api.assert_called_once_with(_api_client) @mock.patch(MAGNUM_UTILS + ".MagnumScenario._get_k8s_api_client")