From ae4a8eea5f21792de324b58e63815610886ac276 Mon Sep 17 00:00:00 2001 From: Pietro Pasotti Date: Fri, 17 Nov 2023 16:07:19 +0100 Subject: [PATCH] added container fs temporary dir cleanup in Context.clear() --> Context.cleanup() --- scenario/context.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scenario/context.py b/scenario/context.py index ebdecb93..99c8a602 100644 --- a/scenario/context.py +++ b/scenario/context.py @@ -296,7 +296,18 @@ def _get_storage_root(self, name: str, index: int) -> Path: return storage_root def clear(self): - """Cleanup side effects histories.""" + """Deprecated. + + Use cleanup instead. + """ + logger.warning( + "Context.clear() is deprecated and will be nuked in v6. " + "Use Context.cleanup() instead.", + ) + self.cleanup() + + def cleanup(self): + """Cleanup side effects histories and reset the simulated filesystem state.""" self.juju_log = [] self.app_status_history = [] self.unit_status_history = [] @@ -308,6 +319,9 @@ def clear(self): self._action_failure = None self._output_state = None + self._tmp.cleanup() + self._tmp = tempfile.TemporaryDirectory() + def _record_status(self, state: "State", is_app: bool): """Record the previous status before a status change.""" if is_app: