Skip to content

Commit

Permalink
[Core] Unsupported features should fail with non-zero exit code skypi…
Browse files Browse the repository at this point in the history
  • Loading branch information
brannt committed Dec 23, 2023
1 parent 7609e22 commit 1ce56ea
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ sky/clouds/service_catalog/data_fetchers/*.csv
.vscode/
.idea/

.venv/
107 changes: 65 additions & 42 deletions sky/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,47 +35,48 @@
import textwrap
import time
import typing
from typing import Any, Dict, List, Optional, Tuple, Union
import webbrowser
from typing import Any, Dict, List, Optional, Tuple, Union

import click
import colorama
import dotenv
from rich import progress as rich_progress
import yaml
from rich import progress as rich_progress

import sky
from sky import backends
from sky import (
backends,
clouds,
core,
exceptions,
global_user_state,
sky_logging,
status_lib,
)
from sky import check as sky_check
from sky import clouds
from sky import core
from sky import exceptions
from sky import global_user_state
from sky import serve as serve_lib
from sky import sky_logging
from sky import spot as spot_lib
from sky import status_lib
from sky.backends import backend_utils
from sky.backends import onprem_utils
from sky.benchmark import benchmark_state
from sky.benchmark import benchmark_utils
from sky.backends import backend_utils, onprem_utils
from sky.benchmark import benchmark_state, benchmark_utils
from sky.clouds import service_catalog
from sky.data import storage_utils
from sky.skylet import constants
from sky.skylet import job_lib
from sky.skylet import constants, job_lib
from sky.usage import usage_lib
from sky.utils import command_runner
from sky.utils import common_utils
from sky.utils import controller_utils
from sky.utils import dag_utils
from sky.utils import env_options
from sky.utils import kubernetes_utils
from sky.utils import log_utils
from sky.utils import rich_utils
from sky.utils import schemas
from sky.utils import subprocess_utils
from sky.utils import timeline
from sky.utils import ux_utils
from sky.utils import (
command_runner,
common_utils,
controller_utils,
dag_utils,
env_options,
kubernetes_utils,
log_utils,
rich_utils,
schemas,
subprocess_utils,
timeline,
ux_utils,
)
from sky.utils.cli_utils import status_utils

if typing.TYPE_CHECKING:
Expand Down Expand Up @@ -2383,10 +2384,11 @@ def stop(
sky stop -a
"""
_down_or_stop_clusters(clusters,
apply_to_all=all,
down=False,
no_confirm=yes)
sys.exit(
_down_or_stop_clusters(clusters,
apply_to_all=all,
down=False,
no_confirm=yes))


@cli.command(cls=_DocumentedCodeCommand)
Expand Down Expand Up @@ -2725,6 +2727,7 @@ def start(
except (exceptions.NotSupportedError,
exceptions.ClusterOwnerIdentityMismatchError) as e:
click.echo(str(e))
sys.exit(1)
else:
click.secho(f'Cluster {name} started.', fg='green')

Expand Down Expand Up @@ -2790,11 +2793,12 @@ def down(
sky down -a
"""
_down_or_stop_clusters(clusters,
apply_to_all=all,
down=True,
no_confirm=yes,
purge=purge)
sys.exit(
_down_or_stop_clusters(clusters,
apply_to_all=all,
down=True,
no_confirm=yes,
purge=purge))


def _hint_or_raise_for_down_spot_controller(controller_name: str):
Expand Down Expand Up @@ -2896,7 +2900,7 @@ def _down_or_stop_clusters(
down: bool, # pylint: disable=redefined-outer-name
no_confirm: bool,
purge: bool = False,
idle_minutes_to_autostop: Optional[int] = None) -> None:
idle_minutes_to_autostop: Optional[int] = None) -> int:
"""Tears down or (auto-)stops a cluster (or all clusters).
Controllers (spot controller and sky serve controller) can only be
Expand Down Expand Up @@ -3014,7 +3018,7 @@ def _down_or_stop_clusters(

if not clusters:
click.echo('Cluster(s) not found (tip: see `sky status`).')
return
return 1

if not no_confirm and len(clusters) > 0:
cluster_str = 'clusters' if len(clusters) > 1 else 'cluster'
Expand All @@ -3033,6 +3037,8 @@ def _down_or_stop_clusters(
task = progress.add_task(
f'[bold cyan]{operation} {len(clusters)} cluster{plural}[/]',
total=len(clusters))
errors = 0
error_lock = multiprocessing.Lock()

def _down_or_stop(name: str):
success_progress = False
Expand Down Expand Up @@ -3086,6 +3092,10 @@ def _down_or_stop(name: str):
click.echo(message)
if success_progress:
progress.update(task, advance=1)
else:
with error_lock:
nonlocal errors
errors += 1 # pylint:disable=undefined-variable
progress.start()

with progress:
Expand All @@ -3094,6 +3104,18 @@ def _down_or_stop(name: str):
# Make sure the progress bar not mess up the terminal.
progress.refresh()

if not errors:
return 0
if purge:
msg_head = f'{colorama.Fore.YELLOW}WARNING'
exitcode = 0
else:
msg_head = f'{colorama.Fore.RED}ERROR'
exitcode = 1
click.echo(f'{msg_head}: {errors} cluster{plural} failed to {command}. '
f'Please see above for details.{colorama.Style.RESET_ALL}')
return exitcode


@_interactive_node_cli_command
@usage_lib.entrypoint
Expand Down Expand Up @@ -5089,10 +5111,11 @@ def benchmark_down(
continue
to_stop.append(cluster)

_down_or_stop_clusters(to_stop,
apply_to_all=False,
down=True,
no_confirm=yes)
sys.exit(
_down_or_stop_clusters(to_stop,
apply_to_all=False,
down=True,
no_confirm=yes))


@bench.command('delete', cls=_DocumentedCodeCommand)
Expand Down

0 comments on commit 1ce56ea

Please sign in to comment.