diff options
author | Mytnyk, Volodymyr <volodymyrx.mytnyk@intel.com> | 2018-07-17 09:42:47 +0100 |
---|---|---|
committer | Mytnyk, Volodymyr <volodymyrx.mytnyk@intel.com> | 2018-07-18 15:49:40 +0100 |
commit | aac4f607b426cedce7666f826b4037f9f17c4ff0 (patch) | |
tree | 240c6c63555a93043f496e740f130f72d5d92623 | |
parent | f3cae5191bb3c944fd08780d8a8940d2aa60c4d0 (diff) |
kubernetes_utils: avoid 404 error code in delete_pod()
JIRA: YARDSTICK-1320
Change-Id: I5b762d4732440008630093e1d0952f7e41a8a191
Signed-off-by: Mytnyk, Volodymyr <volodymyrx.mytnyk@intel.com>
-rw-r--r-- | yardstick/benchmark/contexts/kubernetes.py | 2 | ||||
-rw-r--r-- | yardstick/common/kubernetes_utils.py | 11 | ||||
-rw-r--r-- | yardstick/tests/unit/common/test_kubernetes_utils.py | 28 |
3 files changed, 37 insertions, 4 deletions
diff --git a/yardstick/benchmark/contexts/kubernetes.py b/yardstick/benchmark/contexts/kubernetes.py index 27a011334..704c4a022 100644 --- a/yardstick/benchmark/contexts/kubernetes.py +++ b/yardstick/benchmark/contexts/kubernetes.py @@ -117,7 +117,7 @@ class KubernetesContext(ctx_base.Context): self._delete_pod(pod) def _delete_pod(self, pod): - k8s_utils.delete_pod(pod) + k8s_utils.delete_pod(pod, skip_codes=[404]) def _create_crd(self): LOG.info('Create Custom Resource Definition elements') diff --git a/yardstick/common/kubernetes_utils.py b/yardstick/common/kubernetes_utils.py index 42267fc41..35e590f2b 100644 --- a/yardstick/common/kubernetes_utils.py +++ b/yardstick/common/kubernetes_utils.py @@ -136,8 +136,10 @@ def delete_replication_controller(name, def delete_pod(name, namespace='default', wait=False, + skip_codes=None, **kwargs): # pragma: no cover # pylint: disable=unused-argument + skip_codes = [] if not skip_codes else skip_codes core_v1_api = get_core_api() body = kwargs.get('body', client.V1DeleteOptions()) kwargs.pop('body', None) @@ -146,9 +148,12 @@ def delete_pod(name, namespace, body, **kwargs) - except ApiException: - LOG.exception('Delete pod failed') - raise + except ApiException as e: + if e.status in skip_codes: + LOG.info(e.reason) + else: + raise exceptions.KubernetesApiException( + action='delete', resource='Pod') def read_pod(name, diff --git a/yardstick/tests/unit/common/test_kubernetes_utils.py b/yardstick/tests/unit/common/test_kubernetes_utils.py index bf9992b57..bdc2c12d5 100644 --- a/yardstick/tests/unit/common/test_kubernetes_utils.py +++ b/yardstick/tests/unit/common/test_kubernetes_utils.py @@ -222,3 +222,31 @@ class DeleteNetworkTestCase(base.BaseUnitTestCase): kubernetes_utils.delete_network( constants.SCOPE_CLUSTER, mock.ANY, mock.ANY, mock.ANY, mock.ANY) + + +class DeletePodTestCase(base.BaseUnitTestCase): + @mock.patch.object(kubernetes_utils, 'get_core_api') + def test_execute_correct(self, mock_get_api): + mock_api = mock.Mock() + mock_get_api.return_value = mock_api + + kubernetes_utils.delete_pod("name", body=None) + mock_api.delete_namespaced_pod.assert_called_once_with( + "name", 'default', None) + + @mock.patch.object(kubernetes_utils, 'get_core_api') + def test_execute_exception(self, mock_get_api): + mock_api = mock.Mock() + mock_api.delete_namespaced_pod.side_effect = rest.ApiException(status=200) + + mock_get_api.return_value = mock_api + with self.assertRaises(exceptions.KubernetesApiException): + kubernetes_utils.delete_pod(mock.ANY, skip_codes=[404]) + + @mock.patch.object(kubernetes_utils, 'get_core_api') + def test_execute_skip_exception(self, mock_get_api): + mock_api = mock.Mock() + mock_api.delete_namespaced_pod.side_effect = rest.ApiException(status=404) + + mock_get_api.return_value = mock_api + kubernetes_utils.delete_pod(mock.ANY, skip_codes=[404]) |