Skip to content

Commit

Permalink
Add snapshot delete to cli (#1020)
Browse files Browse the repository at this point in the history
Signed-off-by: Mikayla Thompson <[email protected]>
  • Loading branch information
mikaylathompson authored Sep 27, 2024
1 parent 03dfed0 commit 2c1f760
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,23 @@ def status_snapshot_cmd(ctx, deep_check):
result = snapshot_.status(ctx.env.snapshot, deep_check=deep_check)
click.echo(result.value)


@snapshot_group.command(name="delete")
@click.option("--acknowledge-risk", is_flag=True, show_default=True, default=False,
help="Flag to acknowledge risk and skip confirmation")
@click.pass_obj
def delete_snapshot_cmd(ctx, acknowledge_risk: bool):
"""Delete the snapshot"""
if not acknowledge_risk:
confirmed = click.confirm('If you proceed with deleting the snapshot, the cluster will delete underlying local '
'and remote files associated with the snapshot. Are you sure you want to continue?')
if not confirmed:
click.echo("Aborting the command to delete snapshot.")
return
logger.info("Deleting snapshot")
result = snapshot_.delete(ctx.env.snapshot)
click.echo(result.value)

# ##################### BACKFILL ###################

# As we add other forms of backfill migrations, we should incorporate a way to dynamically allow different sets of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def status(snapshot: Snapshot, *args, **kwargs) -> CommandResult:
def delete(snapshot: Snapshot, *args, **kwargs) -> CommandResult:
logger.info(f"Deleting snapshot with {args=} and {kwargs=}")
try:
return snapshot.delete(*args, **kwargs)
return CommandResult(success=True, value=snapshot.delete(*args, **kwargs))
except Exception as e:
logger.error(f"Failure running delete snapshot: {e}")
return CommandResult(status=False, message=f"Failure running delete snapshot: {e}")
return CommandResult(success=False, value=f"Failure running delete snapshot: {e}")
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,32 @@ def test_cli_snapshot_status(runner, mocker):
mock.assert_called_once()


def test_cli_snapshot_delete_with_acknowledgement(runner, mocker):
mock = mocker.patch.object(Cluster, 'call_api', autospec=True)
mock.return_value.text = "Successfully deleted"

# Test snapshot status
result = runner.invoke(cli, ['--config-file', str(VALID_SERVICES_YAML), 'snapshot', 'delete', '--acknowledge-risk'],
catch_exceptions=True)
assert result.exit_code == 0

# Ensure the mocks were called
mock.assert_called_once()


def test_cli_snapshot_delete_without_acknowledgement_doesnt_run(runner, mocker):
mock = mocker.patch.object(Cluster, 'call_api', autospec=True)
mock.return_value.text = "Successfully deleted"

# Test snapshot status
result = runner.invoke(cli, ['--config-file', str(VALID_SERVICES_YAML), 'snapshot', 'delete'], input="n",
catch_exceptions=True)
assert result.exit_code == 0

# Ensure the mocks were called
mock.assert_not_called()


def test_cli_with_backfill_describe(runner, mocker):
mock = mocker.patch('console_link.middleware.backfill.describe')
result = runner.invoke(cli, ['--config-file', str(VALID_SERVICES_YAML), 'backfill', 'describe'],
Expand Down

0 comments on commit 2c1f760

Please sign in to comment.