From 5d0e744da62c8680ef81fd5f51f59559cbd2b590 Mon Sep 17 00:00:00 2001 From: Sergii Tkachenko Date: Mon, 8 Aug 2022 18:38:57 -0700 Subject: [PATCH] xDS interop: override retriable cleanup instead of tearDown (#30540) Some tests override unittest's `tearDown()`, which is not wrong, but less resilient than overriding custom `cleanup()` that is being retried in framework's `tearDown()`. --- .../xds_k8s_test_driver/framework/xds_k8s_testcase.py | 4 ++-- .../tests/change_backend_service_test.py | 7 ++++--- tools/run_tests/xds_k8s_test_driver/tests/failover_test.py | 7 ++++--- .../run_tests/xds_k8s_test_driver/tests/remove_neg_test.py | 7 ++++--- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tools/run_tests/xds_k8s_test_driver/framework/xds_k8s_testcase.py b/tools/run_tests/xds_k8s_test_driver/framework/xds_k8s_testcase.py index 3b5f7f6f92d..5730e0e34d7 100644 --- a/tools/run_tests/xds_k8s_test_driver/framework/xds_k8s_testcase.py +++ b/tools/run_tests/xds_k8s_test_driver/framework/xds_k8s_testcase.py @@ -452,11 +452,11 @@ class IsolatedXdsKubernetesTestCase(XdsKubernetesBaseTestCase, attempts=3, log_level=logging.INFO) try: - retryer(self._cleanup) + retryer(self.cleanup) except retryers.RetryError: logger.exception('Got error during teardown') - def _cleanup(self): + def cleanup(self): self.td.cleanup(force=self.force_cleanup) self.client_runner.cleanup(force=self.force_cleanup) self.server_runner.cleanup(force=self.force_cleanup, diff --git a/tools/run_tests/xds_k8s_test_driver/tests/change_backend_service_test.py b/tools/run_tests/xds_k8s_test_driver/tests/change_backend_service_test.py index 78e1940a40b..8c382a44ff6 100644 --- a/tools/run_tests/xds_k8s_test_driver/tests/change_backend_service_test.py +++ b/tools/run_tests/xds_k8s_test_driver/tests/change_backend_service_test.py @@ -48,10 +48,11 @@ class ChangeBackendServiceTest(xds_k8s_testcase.RegularXdsKubernetesTestCase): debug_use_port_forwarding=self.debug_use_port_forwarding, reuse_namespace=True) - def tearDown(self): + def cleanup(self): + super().cleanup() if hasattr(self, 'alternate_server_runner'): - self.alternate_server_runner.cleanup() - super().tearDown() + self.alternate_server_runner.cleanup( + force=self.force_cleanup, force_namespace=self.force_cleanup) def test_change_backend_service(self) -> None: with self.subTest('00_create_health_check'): diff --git a/tools/run_tests/xds_k8s_test_driver/tests/failover_test.py b/tools/run_tests/xds_k8s_test_driver/tests/failover_test.py index e7e68a1b3e6..f9388c2280d 100644 --- a/tools/run_tests/xds_k8s_test_driver/tests/failover_test.py +++ b/tools/run_tests/xds_k8s_test_driver/tests/failover_test.py @@ -49,10 +49,11 @@ class FailoverTest(xds_k8s_testcase.RegularXdsKubernetesTestCase): debug_use_port_forwarding=self.debug_use_port_forwarding, reuse_namespace=True) - def tearDown(self): + def cleanup(self): + super().cleanup() if hasattr(self, 'secondary_server_runner'): - self.secondary_server_runner.cleanup() - super().tearDown() + self.secondary_server_runner.cleanup( + force=self.force_cleanup, force_namespace=self.force_cleanup) def test_failover(self) -> None: with self.subTest('00_create_health_check'): diff --git a/tools/run_tests/xds_k8s_test_driver/tests/remove_neg_test.py b/tools/run_tests/xds_k8s_test_driver/tests/remove_neg_test.py index 67f56514422..9fb44088e99 100644 --- a/tools/run_tests/xds_k8s_test_driver/tests/remove_neg_test.py +++ b/tools/run_tests/xds_k8s_test_driver/tests/remove_neg_test.py @@ -47,10 +47,11 @@ class RemoveNegTest(xds_k8s_testcase.RegularXdsKubernetesTestCase): debug_use_port_forwarding=self.debug_use_port_forwarding, reuse_namespace=True) - def tearDown(self): + def cleanup(self): + super().cleanup() if hasattr(self, 'alternate_server_runner'): - self.alternate_server_runner.cleanup() - super().tearDown() + self.alternate_server_runner.cleanup( + force=self.force_cleanup, force_namespace=self.force_cleanup) def test_remove_neg(self) -> None: with self.subTest('00_create_health_check'):