From 5835cc46c942b80d3becdec5a563b8a5183def08 Mon Sep 17 00:00:00 2001 From: Itzik Brown Date: Tue, 22 Mar 2022 11:21:59 +0200 Subject: [PATCH] Check that pod is deleted in delete_pod Instead of sleeping after deletion - check that the pod is deleted for a period of 30 seconds Change-Id: Iaa88f8d851430b19e09b3fbe2b4bc070a93a3a93 --- kuryr_tempest_plugin/tests/scenario/base.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/kuryr_tempest_plugin/tests/scenario/base.py b/kuryr_tempest_plugin/tests/scenario/base.py index bafead00..0278deaf 100644 --- a/kuryr_tempest_plugin/tests/scenario/base.py +++ b/kuryr_tempest_plugin/tests/scenario/base.py @@ -219,13 +219,22 @@ class BaseKuryrScenarioTest(manager.NetworkScenarioTest): 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: + if e.status != 404: 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) + LOG.debug("Pod %s was not found.", pod_name) + retries = 6 + while retries > 0: + try: + cls.k8s_client.CoreV1Api().read_namespaced_pod( + pod_name, + namespace) + time.sleep(5) + except kubernetes.client.exceptions.ApiException as e: + if e.status != 404: + LOG.warning("An exception occured: %s", e) + break + else: + LOG.debug("Timeout - Pod %s has not been deleted yet.", pod_name) @classmethod def wait_for_pod_status(cls, pod_name, namespace="default",