From 7fc2b1055753b283d8bda21cb85adf560e58c476 Mon Sep 17 00:00:00 2001 From: shenxindi Date: Mon, 16 Mar 2020 15:57:51 +0800 Subject: [PATCH] Remove unsupported calls Because kubernetes 11.0.0 deleted the function of 'kubernetes.client.api_client.ApiClient.__del__', which caused an ut error and deleted the relevant mock call. Change-Id: I1ecade75227b3dc37c8fcdf775b7823583faea43 --- karbor/tests/unit/clients/test_k8s_client.py | 5 +---- karbor/tests/unit/plugins/test_pod_protectable_plugin.py | 6 ++---- karbor/tests/unit/plugins/test_volume_protectable_plugin.py | 4 +--- karbor/tests/unit/protection/test_pod_protection_plugin.py | 3 +-- 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/karbor/tests/unit/clients/test_k8s_client.py b/karbor/tests/unit/clients/test_k8s_client.py index 139867b9..a5d3fd46 100644 --- a/karbor/tests/unit/clients/test_k8s_client.py +++ b/karbor/tests/unit/clients/test_k8s_client.py @@ -16,8 +16,6 @@ from karbor.context import RequestContext from karbor.services.protection.clients import k8s from karbor.tests import base -import mock - class KubernetesClientTest(base.TestCase): def setUp(self): @@ -43,8 +41,7 @@ class KubernetesClientTest(base.TestCase): '/etc/provider.d/client-admin.key', 'k8s_client') - @mock.patch('kubernetes.client.api_client.ApiClient.__del__') - def test_create_client(self, mock_k8s_delete): + def test_create_client(self): client = k8s.create(self._context, self.conf) self.assertEqual(client.api_client.configuration.host, self.host_url) diff --git a/karbor/tests/unit/plugins/test_pod_protectable_plugin.py b/karbor/tests/unit/plugins/test_pod_protectable_plugin.py index 34de52fc..7eb605c5 100644 --- a/karbor/tests/unit/plugins/test_pod_protectable_plugin.py +++ b/karbor/tests/unit/plugins/test_pod_protectable_plugin.py @@ -46,10 +46,9 @@ class PodProtectablePluginTest(base.TestCase): self.assertEqual(("OS::Keystone::Project"), plugin.get_parent_resource_types()) - @mock.patch('kubernetes.client.api_client.ApiClient.__del__') @mock.patch('kubernetes.client.apis.core_v1_api.' 'CoreV1Api.list_namespaced_pod') - def test_list_resources(self, mock_pod_list, mock_pod_delete): + def test_list_resources(self, mock_pod_list): plugin = K8sPodProtectablePlugin(self._context, cfg.CONF) pod = V1Pod(api_version="v1", kind="Pod", @@ -66,10 +65,9 @@ class PodProtectablePluginTest(base.TestCase): 'default:busybox-test')], plugin.list_resources(self._context)) - @mock.patch('kubernetes.client.api_client.ApiClient.__del__') @mock.patch('kubernetes.client.apis.core_v1_api.' 'CoreV1Api.read_namespaced_pod') - def test_show_resource(self, mock_pod_get, mock_pod_delete): + def test_show_resource(self, mock_pod_get): plugin = K8sPodProtectablePlugin(self._context, cfg.CONF) pod = V1Pod(api_version="v1", kind="Pod", diff --git a/karbor/tests/unit/plugins/test_volume_protectable_plugin.py b/karbor/tests/unit/plugins/test_volume_protectable_plugin.py index 51cc04b5..4addab44 100644 --- a/karbor/tests/unit/plugins/test_volume_protectable_plugin.py +++ b/karbor/tests/unit/plugins/test_volume_protectable_plugin.py @@ -151,7 +151,6 @@ class VolumeProtectablePluginTest(base.TestCase): {'availability_zone': 'az1'})], plugin.get_dependent_resources(self._context, project)) - @mock.patch('kubernetes.client.api_client.ApiClient.__del__') @mock.patch.object(volumes.VolumeManager, 'list') @mock.patch('kubernetes.client.apis.core_v1_api.' 'CoreV1Api.read_persistent_volume') @@ -162,8 +161,7 @@ class VolumeProtectablePluginTest(base.TestCase): def test_get_pod_dependent_resources(self, mock_pod_read, mock_pvc_read, mock_pv_read, - mock_volume_list, - mock_delete): + mock_volume_list): plugin = VolumeProtectablePlugin(self._context) pod = V1Pod(api_version="v1", kind="Pod", diff --git a/karbor/tests/unit/protection/test_pod_protection_plugin.py b/karbor/tests/unit/protection/test_pod_protection_plugin.py index d76e2748..e94684de 100644 --- a/karbor/tests/unit/protection/test_pod_protection_plugin.py +++ b/karbor/tests/unit/protection/test_pod_protection_plugin.py @@ -131,9 +131,8 @@ class PodProtectionPluginTest(base.TestCase): self.assertEqual(options_schema, pod_plugin_schemas.SAVED_INFO_SCHEMA) - @mock.patch('kubernetes.client.api_client.ApiClient.__del__') @mock.patch('karbor.services.protection.clients.k8s.create') - def test_create_backup(self, mock_k8s_create, mock_k8s_delete): + def test_create_backup(self, mock_k8s_create): self.k8s_client = client_factory.ClientFactory.create_client( "k8s", self.cntxt) resource = Resource(id="c88b92a8-e8b4-504c-bad4-343d92061871",