From 2b83c683f8523a527b1815f0896d47c599aa9b09 Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Mon, 8 Apr 2019 12:35:41 +0200 Subject: [PATCH] Fix for a flaky test failing because k8s is slow We create a deployment and do the following: ``` self.assertIsNotNone(dep) ``` Which does not fail, and then the code proceeds to deletion and fails with a 404 execption in 80% of the time, but sometimes it works. The deployment is there, but for some reason not available for deletion. Travis CI also showed inconsitent behaviour on this. Python3.5 passed but all other version failed. With this commit we wait for the deployment to become available for deletion and only then continue. --- kubernetes/e2e_test/test_utils.py | 34 +++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/kubernetes/e2e_test/test_utils.py b/kubernetes/e2e_test/test_utils.py index df387a28a..04eb1f486 100644 --- a/kubernetes/e2e_test/test_utils.py +++ b/kubernetes/e2e_test/test_utils.py @@ -16,6 +16,7 @@ import unittest import yaml from kubernetes import utils, client +from kubernetes.client.rest import ApiException from kubernetes.e2e_test import base @@ -39,9 +40,14 @@ class TestUtils(unittest.TestCase): dep = app_api.read_namespaced_deployment(name="nginx-app", namespace="default") self.assertIsNotNone(dep) - app_api.delete_namespaced_deployment( - name="nginx-app", namespace="default", - body={}) + while True: + try: + app_api.delete_namespaced_deployment( + name="nginx-app", namespace="default", + body={}) + break + except ApiException: + continue def test_create_apps_deployment_from_yaml_string(self): k8s_client = client.api_client.ApiClient(configuration=self.config) @@ -55,9 +61,14 @@ class TestUtils(unittest.TestCase): dep = app_api.read_namespaced_deployment(name="nginx-app", namespace="default") self.assertIsNotNone(dep) - app_api.delete_namespaced_deployment( - name="nginx-app", namespace="default", - body={}) + while True: + try: + app_api.delete_namespaced_deployment( + name="nginx-app", namespace="default", + body={}) + break + except ApiException: + continue def test_create_apps_deployment_from_yaml_obj(self): k8s_client = client.api_client.ApiClient(configuration=self.config) @@ -71,9 +82,14 @@ class TestUtils(unittest.TestCase): dep = app_api.read_namespaced_deployment(name="nginx-app", namespace="default") self.assertIsNotNone(dep) - app_api.delete_namespaced_deployment( - name="nginx-app", namespace="default", - body={}) + while True: + try: + app_api.delete_namespaced_deployment( + name="nginx-app", namespace="default", + body={}) + break + except ApiException: + continue def test_create_extensions_deployment_from_yaml(self): """