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

CLI: Improved customizability and scriptability of verdi storage maintain #5936

Merged
merged 15 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 12 additions & 4 deletions aiida/cmdline/commands/cmd_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ def storage_info(detailed):
is_flag=True,
help='Perform all maintenance tasks, including the ones that should not be executed while the profile is in use.'
)
@click.option(
'--no-repack', is_flag=True, help='Disable the repacking of the storage when running a `full maintenance`.'
)
@click.option('--yes', '-y', 'skip_prompt', is_flag=True, help='Skip confirmation prompt.')
@click.option(
'--dry-run',
is_flag=True,
Expand All @@ -117,7 +121,7 @@ def storage_info(detailed):
)
@decorators.with_dbenv()
@click.pass_context
def storage_maintain(ctx, full, dry_run):
def storage_maintain(ctx, full, no_repack, skip_prompt, dry_run):
"""Performs maintenance tasks on the repository."""
from aiida.common.exceptions import LockingProfileError
from aiida.manage.manager import get_manager
Expand Down Expand Up @@ -149,11 +153,15 @@ def storage_maintain(ctx, full, dry_run):
)

if not dry_run:
if not click.confirm('Are you sure you want continue in this mode?'):
return
if not skip_prompt:
if not click.confirm('Are you sure you want continue in this mode?'):
return

try:
storage.maintain(full=full, dry_run=dry_run)
if full and no_repack:
storage.maintain(full=full, dry_run=dry_run, do_repack=False)
else:
storage.maintain(full=full, dry_run=dry_run)
except LockingProfileError as exception:
echo.echo_critical(str(exception))
echo.echo_success('Requested maintenance procedures finished.')
2 changes: 1 addition & 1 deletion aiida/repository/backend/disk_object_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def maintain( # type: ignore[override] # pylint: disable=arguments-differ,too-ma
"""
if live and (do_repack or clean_storage or do_vacuum):
overrides = {'do_repack': do_repack, 'clean_storage': clean_storage, 'do_vacuum': do_vacuum}
keys = ', '.join([key for key, override in overrides if override is True]) # type: ignore
keys = ', '.join([key for key, override in overrides.items() if override is True]) # type: ignore
raise ValueError(f'The following overrides were enabled but cannot be if `live=True`: {keys}')

pack_loose = True if pack_loose is None else pack_loose
Expand Down
35 changes: 32 additions & 3 deletions tests/cmdline/commands/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,52 @@ def mock_maintain(*args, **kwargs):

monkeypatch.setattr(storage, 'maintain', mock_maintain)

# Not passing user input Y or `--yes` should causing the command to exit without executing `storage.mantain`
# Checking that no logs are produced in the with caplog context
with caplog.at_level(logging.INFO):
_ = run_cli_command(cmd_storage.storage_maintain, user_input='Y', use_subprocess=False)
_ = run_cli_command(cmd_storage.storage_maintain, use_subprocess=False)

assert len(caplog.records) == 0

# Test `storage.mantain` with `--yes`
with caplog.at_level(logging.INFO):
_ = run_cli_command(cmd_storage.storage_maintain, parameters=['--yes'], use_subprocess=False)

message_list = caplog.records[0].msg.splitlines()
assert ' > full: False' in message_list
assert ' > dry_run: False' in message_list

# Test `storage.mantain` with user input Y
with caplog.at_level(logging.INFO):
_ = run_cli_command(cmd_storage.storage_maintain, parameters=['--dry-run'], use_subprocess=False)
_ = run_cli_command(cmd_storage.storage_maintain, user_input='Y', use_subprocess=False)

message_list = caplog.records[1].msg.splitlines()
assert ' > full: False' in message_list
assert ' > dry_run: False' in message_list

# Test `storage.mantain` with `--dry-run`
with caplog.at_level(logging.INFO):
_ = run_cli_command(cmd_storage.storage_maintain, parameters=['--dry-run'], use_subprocess=False)

message_list = caplog.records[2].msg.splitlines()
assert ' > full: False' in message_list
assert ' > dry_run: True' in message_list

# Test `storage.mantain` with `--full`
with caplog.at_level(logging.INFO):
run_cli_command(cmd_storage.storage_maintain, parameters=['--full'], user_input='Y', use_subprocess=False)

message_list = caplog.records[2].msg.splitlines()
message_list = caplog.records[3].msg.splitlines()
assert ' > full: True' in message_list
assert ' > dry_run: False' in message_list

# Test `storage.mantain` with `--full` and `--no-repack`
with caplog.at_level(logging.INFO):
run_cli_command(
cmd_storage.storage_maintain, parameters=['--full', '--no-repack'], user_input='Y', use_subprocess=False
)

message_list = caplog.records[4].msg.splitlines()
assert ' > full: True' in message_list
assert ' > do_repack: False' in message_list
assert ' > dry_run: False' in message_list