From 8d41478ed87145af480ccd0cc5863d3ed8ce2ca8 Mon Sep 17 00:00:00 2001 From: Oz Tiram Date: Mon, 8 Apr 2019 13:54:26 +0200 Subject: [PATCH] Explicitly use other deployment names for test Using `nginx-app` deployment multiple times, is problematic because we get conflicts or not found error. Instead of trying to handle all cases, explicit different names are used now. The tests now runs more reliably --- kubernetes/e2e_test/test_utils.py | 24 ++++++++----------- .../e2e_test/test_yaml/apps-deployment-2.yaml | 21 ++++++++++++++++ 2 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 kubernetes/e2e_test/test_yaml/apps-deployment-2.yaml diff --git a/kubernetes/e2e_test/test_utils.py b/kubernetes/e2e_test/test_utils.py index 04eb1f486..58bb57bb5 100644 --- a/kubernetes/e2e_test/test_utils.py +++ b/kubernetes/e2e_test/test_utils.py @@ -51,20 +51,20 @@ class TestUtils(unittest.TestCase): def test_create_apps_deployment_from_yaml_string(self): k8s_client = client.api_client.ApiClient(configuration=self.config) - with open(self.path_prefix + "apps-deployment.yaml") as f: + with open(self.path_prefix + "apps-deployment-2.yaml") as f: yaml_str = f.read() utils.create_from_yaml( k8s_client, yaml_str) app_api = client.AppsV1beta1Api(k8s_client) - dep = app_api.read_namespaced_deployment(name="nginx-app", + dep = app_api.read_namespaced_deployment(name="nginx-app-2", namespace="default") self.assertIsNotNone(dep) while True: try: app_api.delete_namespaced_deployment( - name="nginx-app", namespace="default", + name="nginx-app-2", namespace="default", body={}) break except ApiException: @@ -75,21 +75,17 @@ class TestUtils(unittest.TestCase): with open(self.path_prefix + "apps-deployment.yaml") as f: yml_obj = yaml.safe_load(f) - utils.create_from_dict( - k8s_client, yml_obj) + yml_obj["metadata"]["name"] = "nginx-app-3" + + utils.create_from_dict(k8s_client, yml_obj) app_api = client.AppsV1beta1Api(k8s_client) - dep = app_api.read_namespaced_deployment(name="nginx-app", + dep = app_api.read_namespaced_deployment(name="nginx-app-3", namespace="default") self.assertIsNotNone(dep) - while True: - try: - app_api.delete_namespaced_deployment( - name="nginx-app", namespace="default", - body={}) - break - except ApiException: - continue + app_api.delete_namespaced_deployment( + name="nginx-app-3", namespace="default", + body={}) def test_create_extensions_deployment_from_yaml(self): """ diff --git a/kubernetes/e2e_test/test_yaml/apps-deployment-2.yaml b/kubernetes/e2e_test/test_yaml/apps-deployment-2.yaml new file mode 100644 index 000000000..b2acb92f8 --- /dev/null +++ b/kubernetes/e2e_test/test_yaml/apps-deployment-2.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1beta1 +kind: Deployment +metadata: + name: nginx-app-2 + labels: + app: nginx +spec: + replicas: 3 + selector: + matchLabels: + app: nginx + template: + metadata: + labels: + app: nginx + spec: + containers: + - name: nginx + image: nginx:1.15.4 + ports: + - containerPort: 80