From f6f77354b1cc424009b718517c338d5fc7669917 Mon Sep 17 00:00:00 2001 From: Itzik Brown Date: Wed, 16 Mar 2022 16:47:04 +0200 Subject: [PATCH] Use one pod to check connectivity in kuryr_restart In test_kuryr_restart use one pod to check connectivity to the created pods from this pod instead of assigning a fip for each created pod. This can solve problems when there is shortage of floating ips. Also, Don't fail on deletion of a pod in cleanup if it's not found Change-Id: I55a33f88356ff3d1ef6ed0ce83bb102172e46023 --- kuryr_tempest_plugin/tests/scenario/base.py | 14 ++++++++++---- .../tests/scenario/test_kuryr_restart.py | 19 +++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/kuryr_tempest_plugin/tests/scenario/base.py b/kuryr_tempest_plugin/tests/scenario/base.py index 3df1d859..bafead00 100644 --- a/kuryr_tempest_plugin/tests/scenario/base.py +++ b/kuryr_tempest_plugin/tests/scenario/base.py @@ -213,10 +213,16 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest): def delete_pod(cls, pod_name, body=None, namespace="default"): if body is None: body = {} - cls.k8s_client.CoreV1Api().delete_namespaced_pod( - name=pod_name, - body=body, - namespace=namespace) + try: + cls.k8s_client.CoreV1Api().delete_namespaced_pod( + name=pod_name, + body=body, + namespace=namespace) + except kubernetes.client.exceptions.ApiException as e: + if e.status == 404: + LOG.debug(f"Pod {pod_name} was not found.") + else: + raise # TODO(apuimedo) This sleep to be replaced with a polling with # timeout for the pod object to be gone from k8s api. time.sleep(30) diff --git a/kuryr_tempest_plugin/tests/scenario/test_kuryr_restart.py b/kuryr_tempest_plugin/tests/scenario/test_kuryr_restart.py index e08a9587..5c64ab5a 100644 --- a/kuryr_tempest_plugin/tests/scenario/test_kuryr_restart.py +++ b/kuryr_tempest_plugin/tests/scenario/test_kuryr_restart.py @@ -18,8 +18,8 @@ from tempest import config from tempest.lib import decorators from tempest.lib import exceptions as lib_exc - from kuryr_tempest_plugin.tests.scenario import base +from kuryr_tempest_plugin.tests.scenario import consts CONF = config.CONF @@ -39,6 +39,9 @@ class TestKuryrRestartScenario(base.BaseKuryrScenarioTest): def test_kuryr_pod_delete(self): # find kuryr CNI and controller pods, delete them one by one and create # a regular pod just after removal + client_pod_name, pod = self.create_pod() + self.addCleanup(self.delete_pod, client_pod_name) + kube_system_pods = self.get_pod_name_list( namespace=CONF.kuryr_kubernetes.kube_system_namespace) for kuryr_pod_name in kube_system_pods: @@ -65,11 +68,15 @@ class TestKuryrRestartScenario(base.BaseKuryrScenarioTest): # Check once for controller kuryr pod and once for CNI pod pod_name, pod = self.create_pod() self.addCleanup(self.delete_pod, pod_name) - pod_fip = self.assign_fip_to_pod(pod_name) - self.assertIsNotNone(pod_fip['floatingip'][ - 'floating_ip_address']) - self.assertTrue(self.ping_ip_address(pod_fip[ - 'floatingip']['floating_ip_address'])) + dst_pod_ip = self.get_pod_ip(pod_name) + curl_tmpl = self.get_curl_template(dst_pod_ip, + extra_args='-m 10', + port=8080) + cmd = ["/bin/sh", "-c", curl_tmpl.format(dst_pod_ip, ':8080')] + self.assertIn(consts.POD_OUTPUT, self.exec_command_in_pod( + client_pod_name, cmd), + "Connectivity from %s to pod with ip %s failed." % ( + client_pod_name, dst_pod_ip)) # Check that both kuryr-pods are up and running # The newly created pods are running because create_pod is written