Skip to content

Commit 2b83c68

Browse files
committed
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.
1 parent 0779fc9 commit 2b83c68

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

kubernetes/e2e_test/test_utils.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import yaml
1818
from kubernetes import utils, client
19+
from kubernetes.client.rest import ApiException
1920
from kubernetes.e2e_test import base
2021

2122

@@ -39,9 +40,14 @@ def test_create_apps_deployment_from_yaml(self):
3940
dep = app_api.read_namespaced_deployment(name="nginx-app",
4041
namespace="default")
4142
self.assertIsNotNone(dep)
42-
app_api.delete_namespaced_deployment(
43-
name="nginx-app", namespace="default",
44-
body={})
43+
while True:
44+
try:
45+
app_api.delete_namespaced_deployment(
46+
name="nginx-app", namespace="default",
47+
body={})
48+
break
49+
except ApiException:
50+
continue
4551

4652
def test_create_apps_deployment_from_yaml_string(self):
4753
k8s_client = client.api_client.ApiClient(configuration=self.config)
@@ -55,9 +61,14 @@ def test_create_apps_deployment_from_yaml_string(self):
5561
dep = app_api.read_namespaced_deployment(name="nginx-app",
5662
namespace="default")
5763
self.assertIsNotNone(dep)
58-
app_api.delete_namespaced_deployment(
59-
name="nginx-app", namespace="default",
60-
body={})
64+
while True:
65+
try:
66+
app_api.delete_namespaced_deployment(
67+
name="nginx-app", namespace="default",
68+
body={})
69+
break
70+
except ApiException:
71+
continue
6172

6273
def test_create_apps_deployment_from_yaml_obj(self):
6374
k8s_client = client.api_client.ApiClient(configuration=self.config)
@@ -71,9 +82,14 @@ def test_create_apps_deployment_from_yaml_obj(self):
7182
dep = app_api.read_namespaced_deployment(name="nginx-app",
7283
namespace="default")
7384
self.assertIsNotNone(dep)
74-
app_api.delete_namespaced_deployment(
75-
name="nginx-app", namespace="default",
76-
body={})
85+
while True:
86+
try:
87+
app_api.delete_namespaced_deployment(
88+
name="nginx-app", namespace="default",
89+
body={})
90+
break
91+
except ApiException:
92+
continue
7793

7894
def test_create_extensions_deployment_from_yaml(self):
7995
"""

0 commit comments

Comments
 (0)