diff --git a/ocp_resources/node_network_configuration_policy.py b/ocp_resources/node_network_configuration_policy.py index d8a93a62dc..42a00457d9 100644 --- a/ocp_resources/node_network_configuration_policy.py +++ b/ocp_resources/node_network_configuration_policy.py @@ -185,7 +185,7 @@ def deploy(self): return self except Exception as e: LOGGER.error(e) - self.clean_up() + super().__exit__(exception_type=None, exception_value=None, traceback=None) raise @property diff --git a/ocp_resources/resource.py b/ocp_resources/resource.py index fd0d013ace..84b419cd69 100644 --- a/ocp_resources/resource.py +++ b/ocp_resources/resource.py @@ -411,6 +411,16 @@ def __enter__(self): return self.deploy() def __exit__(self, exception_type, exception_value, traceback): + # For debug, export kind (class name) + NOTEARDOWN to skip resource teardown. + # For example:export VirtualMachineInstanceNOTEARDOWN=True + skip_teardown_env = f"{self.kind}NOTEARDOWN" + no_teardown_from_environment = os.environ.get(skip_teardown_env) + if no_teardown_from_environment: + LOGGER.warning( + f"Skip teardown. Got {skip_teardown_env}={no_teardown_from_environment}" + ) + return + if self.teardown: self.clean_up()