10000 Fix node cleanup by demonolock · Pull Request #135 · postgrespro/testgres · GitHub
[go: up one dir, main page]

Skip to content

Fix node cleanup #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add cleanup parameter - clean full dir
  • Loading branch information
vshepard committed Jul 1, 2024
commit e5184a4166228d1db842e20c42bd1320be9f9648
8 changes: 4 additions & 4 deletions testgres/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,13 +912,14 @@ def free_port(self):
self._should_free_port = False
release_port(self.port)

def cleanup(self, max_attempts=3):
def cleanup(self, max_attempts=3, full=False):
"""
Stop node if needed and remove its data/logs directory.
NOTE: take a look at TestgresConfig.node_cleanup_full.

Args:
max_attempts: how many times should we try to stop()?
full: clean full base dir

Returns:
This instance of :class:`.PostgresNode`.
Expand All @@ -927,7 +928,7 @@ def cleanup(self, max_attempts=3):
self._try_shutdown(max_attempts)

# choose directory to be removed
if testgres_config.node_cleanup_full:
if testgres_config.node_cleanup_full or full:
rm_dir = self.base_dir # everything
else:
rm_dir = self.data_dir # just data, save logs
8000 Expand Down Expand Up @@ -1655,8 +1656,7 @@ def upgrade_from(self, old_node, options=None, expect_error=False):
"--old-datadir", old_node.data_dir,
"--new-datadir", self.data_dir,
"--old-port", str(old_node.port),
"--new-port", str(self.port),
"--copy"
"--new-port", str(self.port)
]
upgrade_command += options

Expand Down
2 changes: 2 additions & 0 deletions testgres/operations/local_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ def rmdirs(self, path, ignore_errors=True, retries=3, delay=1):
rmtree(path, ignore_errors=ignore_errors)
if not os.path.exists(path):
return True
except FileNotFoundError:
return True
except Exception as e:
print(f"Error: Failed to remove directory {path} on attempt {attempt + 1}: {e}")
time.sleep(delay)
Expand Down
0