Skip to content

Commit a61f794

Browse files
author
vshepard
committed
Fix node cleanup - rmdirs
1 parent a07f106 commit a61f794

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

testgres/node.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ def cleanup(self, max_attempts=3):
932932
else:
933933
rm_dir = self.data_dir # just data, save logs
934934

935-
self.os_ops.rmdirs(rm_dir, ignore_errors=True)
935+
self.os_ops.rmdirs(rm_dir, ignore_errors=False)
936936

937937
return self
938938

testgres/operations/local_ops.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import stat
55
import subprocess
66
import tempfile
7+
import time
78

89
import psutil
910

@@ -147,8 +148,25 @@ def makedirs(self, path, remove_existing=False):
147148
except FileExistsError:
148149
pass
149150

150-
def rmdirs(self, path, ignore_errors=True):
151-
return rmtree(path, ignore_errors=ignore_errors)
151+
def rmdirs(self, path, ignore_errors=True, retries=3, delay=1):
152+
"""
153+
Removes a directory and its contents, retrying on failure.
154+
155+
:param path: Path to the directory.
156+
:param ignore_errors: If True, ignore errors.
157+
:param retries: Number of attempts to remove the directory.
158+
:param delay: Delay between attempts in seconds.
159+
"""
160+
for attempt in range(retries):
161+
try:
162+
rmtree(path, ignore_errors=ignore_errors)
163+
if not os.path.exists(path):
164+
return True
165+
except Exception as e:
166+
print(f"Error: Failed to remove directory {path} on attempt {attempt + 1}: {e}")
167+
time.sleep(delay)
168+
print(f"Error: Failed to remove directory {path} after {retries} attempts.")
169+
return False
152170

153171
def listdir(self, path):
154172
return os.listdir(path)

0 commit comments

Comments
 (0)