Skip to content
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

Add some more ctdb related hacks #124

Merged
merged 4 commits into from
Jul 2, 2024
Merged
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
17 changes: 17 additions & 0 deletions sambacc/ctdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,23 @@ def _convert_tdb_file(tdb_path: str, dest_dir: str, pnn: int = 0) -> None:
subprocess.check_call(list(cmd))


def archive_tdb(iconfig: config.InstanceConfig, dest_dir: str) -> None:
"""Arhive TDB files into a given directory."""
# TODO: these paths should be based on our instance config, not hard coded
try:
os.mkdir(dest_dir)
_logger.debug("dest_dir: %r created", dest_dir)
except FileExistsError:
_logger.debug("dest_dir: %r already exists", dest_dir)
for tdbfile in _SRC_TDB_FILES:
for parent in _SRC_TDB_DIRS:
tdb_path = os.path.join(parent, tdbfile)
Comment on lines +597 to +599
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of double nested for loop, consider something like:

from itertools import product
from pathlib import Path

for tdb_path in [ Path(p) / f for p, f in product(_SRC_TDB_DIRS, _SRC_TDB_FILES) ]:
    ...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how the older, migrate functions is written. I don't want to deviate from the pattern now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough

if _has_tdb_file(tdb_path):
dest_path = os.path.join(dest_dir, tdbfile)
_logger.info("archiving: %r -> %r", tdb_path, dest_path)
os.rename(tdb_path, dest_path)


def check_nodestatus(cmd: samba_cmds.SambaCommand = samba_cmds.ctdb) -> None:
cmd_ctdb_check = cmd["nodestatus"]
samba_cmds.execute(cmd_ctdb_check)
Expand Down