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 stack delete confirmation prompt #548

Merged
merged 5 commits into from
Apr 29, 2022
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
14 changes: 11 additions & 3 deletions src/zenml/cli/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,17 @@ def describe_stack(stack_name: Optional[str]) -> None:

@stack.command("delete")
@click.argument("stack_name", type=str)
def delete_stack(stack_name: str) -> None:
@click.option("--yes", "-y", is_flag=True, required=False)
def delete_stack(stack_name: str, yes: bool = False) -> None:
"""Delete a stack."""
cli_utils.print_active_profile()
confirmation = yes or cli_utils.confirmation(
f"This will delete stack '{stack_name}' from your repository. \n"
"Are you sure you want to proceed?"
)

if not confirmation:
cli_utils.declare("Stack deletion cancelled.")

with console.status(f"Deleting stack '{stack_name}'...\n"):
cfg = GlobalConfiguration()
Expand All @@ -588,8 +596,8 @@ def delete_stack(stack_name: str) -> None:
)
return

Repository().deregister_stack(stack_name)
cli_utils.declare(f"Deleted stack '{stack_name}'.")
Repository().deregister_stack(stack_name)
cli_utils.declare(f"Deleted stack '{stack_name}'.")


@stack.command("set")
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/cli/test_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from zenml.artifact_stores import LocalArtifactStore
from zenml.cli.stack import (
delete_stack,
describe_stack,
remove_stack_component,
rename_stack,
Expand Down Expand Up @@ -203,3 +204,19 @@ def test_remove_non_core_component_from_stack_succeeds(clean_repo) -> None:
)
assert result.exit_code == 0
assert clean_repo.active_stack.secrets_manager is None


def test_deleting_stack_with_flag_succeeds(clean_repo) -> None:
"""Test stack delete with flag succeeds."""
new_stack = Stack(
name="arias_new_stack",
orchestrator=clean_repo.active_stack.orchestrator,
metadata_store=clean_repo.active_stack.metadata_store,
artifact_store=clean_repo.active_stack.artifact_store,
)
clean_repo.register_stack(new_stack)
runner = CliRunner()
result = runner.invoke(delete_stack, ["arias_new_stack", "-y"])
assert result.exit_code == 0
with pytest.raises(KeyError):
clean_repo.get_stack("arias_new_stack")