diff options
-rw-r--r-- | yardstick/common/kubernetes_utils.py | 12 | ||||
-rw-r--r-- | yardstick/orchestrator/kubernetes.py | 2 | ||||
-rw-r--r-- | yardstick/tests/unit/common/test_kubernetes_utils.py | 17 |
3 files changed, 26 insertions, 5 deletions
diff --git a/yardstick/common/kubernetes_utils.py b/yardstick/common/kubernetes_utils.py index 4bc1ac27f..f5b0443ea 100644 --- a/yardstick/common/kubernetes_utils.py +++ b/yardstick/common/kubernetes_utils.py @@ -226,14 +226,18 @@ def create_custom_resource_definition(body): action='create', resource='CustomResourceDefinition') -def delete_custom_resource_definition(name): +def delete_custom_resource_definition(name, skip_codes=None): + skip_codes = [] if not skip_codes else skip_codes api = get_extensions_v1beta_api() body_obj = client.V1DeleteOptions() try: api.delete_custom_resource_definition(name, body_obj) - except ApiException: - raise exceptions.KubernetesApiException( - action='delete', resource='CustomResourceDefinition') + except ApiException as e: + if e.status in skip_codes: + LOG.info(e.reason) + else: + raise exceptions.KubernetesApiException( + action='delete', resource='CustomResourceDefinition') def get_custom_resource_definition(kind): diff --git a/yardstick/orchestrator/kubernetes.py b/yardstick/orchestrator/kubernetes.py index cfbeb3fa3..7b1450230 100644 --- a/yardstick/orchestrator/kubernetes.py +++ b/yardstick/orchestrator/kubernetes.py @@ -349,7 +349,7 @@ class CustomResourceDefinitionObject(object): k8s_utils.create_custom_resource_definition(self._template) def delete(self): - k8s_utils.delete_custom_resource_definition(self._name) + k8s_utils.delete_custom_resource_definition(self._name, skip_codes=[404]) class NetworkObject(object): diff --git a/yardstick/tests/unit/common/test_kubernetes_utils.py b/yardstick/tests/unit/common/test_kubernetes_utils.py index 637424f48..42aa9f7e0 100644 --- a/yardstick/tests/unit/common/test_kubernetes_utils.py +++ b/yardstick/tests/unit/common/test_kubernetes_utils.py @@ -121,6 +121,23 @@ class DeleteCustomResourceDefinitionTestCase(base.BaseUnitTestCase): mock_delete_crd.delete_custom_resource_definition.\ assert_called_once_with('name', 'del_obj') + @mock.patch.object(client, 'V1DeleteOptions', return_value='del_obj') + @mock.patch.object(kubernetes_utils, 'get_extensions_v1beta_api') + @mock.patch.object(kubernetes_utils, 'LOG') + def test_execute_skip_exception(self, mock_log, mock_get_api, mock_delobj): + mock_delete_crd = mock.Mock() + mock_delete_crd.delete_custom_resource_definition.side_effect = rest.ApiException( + status=404) + + mock_get_api.return_value = mock_delete_crd + kubernetes_utils.delete_custom_resource_definition('name', skip_codes=[404]) + + mock_delobj.assert_called_once() + mock_delete_crd.delete_custom_resource_definition.assert_called_once_with( + 'name', 'del_obj') + + mock_log.info.assert_called_once() + class GetCustomResourceDefinitionTestCase(base.BaseUnitTestCase): |