From 8d1d5922953c76dbb686e7a6829bce4340de957a Mon Sep 17 00:00:00 2001 From: Raphael Randschau Date: Thu, 12 Jan 2023 10:01:40 -0800 Subject: [PATCH] make cluster creation/deletion async by default (#16185) --- src/lightning_app/cli/cmd_clusters.py | 4 ++-- src/lightning_app/cli/lightning_cli_create.py | 10 +++++----- src/lightning_app/cli/lightning_cli_delete.py | 10 +++++----- tests/tests_app/cli/test_cli.py | 3 ++- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/lightning_app/cli/cmd_clusters.py b/src/lightning_app/cli/cmd_clusters.py index b7e62f52a1..35aefa5760 100644 --- a/src/lightning_app/cli/cmd_clusters.py +++ b/src/lightning_app/cli/cmd_clusters.py @@ -109,7 +109,7 @@ class AWSClusterManager: region: str = "us-east-1", external_id: str = None, edit_before_creation: bool = False, - do_async: bool = False, + do_async: bool = True, ) -> None: """request Lightning AI BYOC compute cluster creation. @@ -192,7 +192,7 @@ class AWSClusterManager: console = Console() console.print(clusters.as_table()) - def delete(self, cluster_id: str, force: bool = False, do_async: bool = False) -> None: + def delete(self, cluster_id: str, force: bool = False, do_async: bool = True) -> None: if force: click.echo( """ diff --git a/src/lightning_app/cli/lightning_cli_create.py b/src/lightning_app/cli/lightning_cli_create.py index 5182b1e69d..45783918c9 100644 --- a/src/lightning_app/cli/lightning_cli_create.py +++ b/src/lightning_app/cli/lightning_cli_create.py @@ -50,13 +50,13 @@ def create() -> None: help="Edit the cluster specs before submitting them to the API server.", ) @click.option( - "--async", - "do_async", + "--sync", + "do_sync", type=bool, required=False, default=False, is_flag=True, - help="This flag makes the CLI return immediately and lets the cluster creation happen in the background.", + help="This flag makes the CLI wait until cluster creation completes.", ) def create_cluster( cluster_id: str, @@ -66,7 +66,7 @@ def create_cluster( provider: str, edit_before_creation: bool, enable_performance: bool, - do_async: bool, + do_sync: bool, **kwargs: Any, ) -> None: """Create a Lightning AI BYOC compute cluster with your cloud provider credentials.""" @@ -81,7 +81,7 @@ def create_cluster( external_id=external_id, edit_before_creation=edit_before_creation, cost_savings=not enable_performance, - do_async=do_async, + do_async=not do_sync, ) diff --git a/src/lightning_app/cli/lightning_cli_delete.py b/src/lightning_app/cli/lightning_cli_delete.py index 1664022e51..91eeb95e90 100644 --- a/src/lightning_app/cli/lightning_cli_delete.py +++ b/src/lightning_app/cli/lightning_cli_delete.py @@ -20,15 +20,15 @@ def delete() -> None: @delete.command("cluster") @click.argument("cluster", type=str) @click.option( - "--async", - "do_async", + "--sync", + "do_sync", type=bool, required=False, default=False, is_flag=True, - help="This flag makes the CLI return immediately and lets the cluster deletion happen in the background", + help="This flag makes the CLI wait until cluster deletion completes.", ) -def delete_cluster(cluster: str, force: bool = False, do_async: bool = False) -> None: +def delete_cluster(cluster: str, force: bool = False, do_sync: bool = False) -> None: """Delete a Lightning AI BYOC cluster and all associated cloud provider resources. Deleting a cluster also deletes all apps that were started on the cluster. @@ -44,7 +44,7 @@ def delete_cluster(cluster: str, force: bool = False, do_async: bool = False) -> VPC components, etc. are irreversibly deleted and cannot be recovered! """ cluster_manager = AWSClusterManager() - cluster_manager.delete(cluster_id=cluster, force=force, do_async=do_async) + cluster_manager.delete(cluster_id=cluster, force=force, do_async=not do_sync) def _find_cluster_for_user(app_name: str, cluster_id: Optional[str]) -> str: diff --git a/tests/tests_app/cli/test_cli.py b/tests/tests_app/cli/test_cli.py index b33db38532..ce01260200 100644 --- a/tests/tests_app/cli/test_cli.py +++ b/tests/tests_app/cli/test_cli.py @@ -88,6 +88,7 @@ def test_create_cluster(create_command: mock.MagicMock): "dummy", "--role-arn", "arn:aws:iam::1234567890:role/lai-byoc", + "--sync", ], ) @@ -124,7 +125,7 @@ def test_list_clusters(list_command: mock.MagicMock): @mock.patch("lightning_app.cli.cmd_clusters.AWSClusterManager.delete") def test_delete_cluster(delete: mock.MagicMock): runner = CliRunner() - runner.invoke(delete_cluster, ["test-7"]) + runner.invoke(delete_cluster, ["test-7", "--sync"]) delete.assert_called_once_with(cluster_id="test-7", force=False, do_async=False)