Skip to content

Commit 5fb4297

Browse files
committed
revise code
1 parent 963afb8 commit 5fb4297

File tree

7 files changed

+39
-8
lines changed

7 files changed

+39
-8
lines changed

sky/adaptors/gcp.py

+7
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ def credential_error_exception():
6868
return exceptions.DefaultCredentialsError
6969

7070

71+
@common.load_lazy_modules(_LAZY_MODULES)
72+
def auth_error_exception():
73+
"""GoogleAuthError exception."""
74+
from google.auth import exceptions
75+
return exceptions.GoogleAuthError
76+
77+
7178
@common.load_lazy_modules(_LAZY_MODULES)
7279
def gcp_auth_refresh_error_exception():
7380
"""GCP auth refresh error exception."""

sky/authentication.py

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import yaml
3737

3838
from sky import clouds
39+
from sky import exceptions
3940
from sky import sky_logging
4041
from sky import skypilot_config
4142
from sky.adaptors import gcp
@@ -204,6 +205,11 @@ def setup_gcp_authentication(config: Dict[str, Any]) -> Dict[str, Any]:
204205
sys.exit(1)
205206
else:
206207
raise
208+
except gcp.auth_error_exception() as e:
209+
logger.error(
210+
f'Error getting GCP project: {common_utils.format_exception(e)}')
211+
raise exceptions.InvalidCloudCredentials(
212+
f'{common_utils.format_exception(e)}')
207213
except socket.timeout:
208214
logger.error('Socket timed out when trying to get the GCP project. '
209215
'Please check your network connection.')

sky/backends/backend_utils.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,14 @@ def write_cluster_config(
806806
logger.warning(f'Failed to calculate config_hash: {e}')
807807
logger.debug('Full exception:', exc_info=e)
808808
return config_dict
809-
_add_auth_to_cluster_config(cloud, tmp_yaml_path)
809+
810+
try:
811+
_add_auth_to_cluster_config(cloud, tmp_yaml_path)
812+
except exceptions.InvalidCloudCredentials as e:
813+
raise e
814+
except Exception as e: # pylint: disable=broad-except
815+
logger.warning(f'Failed to add auth to cluster config: {e}')
816+
logger.debug('Full exception:', exc_info=e)
810817

811818
# Restore the old yaml content for backward compatibility.
812819
if os.path.exists(yaml_path) and keep_launch_fields_in_existing_config:

sky/backends/cloud_vm_ray_backend.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ def _aws_handler(blocked_resources: Set['resources_lib.Resources'],
10981098
output = str(error)
10991099
logger.info(f'AWS handler error: {output}')
11001100
# Block AWS if the credential has expired.
1101-
if output.find('CloudCredentialExpired') != -1:
1101+
if output.find('InvalidCloudCredentials') != -1:
11021102
_add_to_blocked_resources(
11031103
blocked_resources, resources_lib.Resources(cloud=clouds.AWS()))
11041104
else:
@@ -1435,6 +1435,17 @@ def _retry_zones(
14351435
# does not have nodes labeled with GPU types.
14361436
logger.info(f'{e}')
14371437
continue
1438+
except exceptions.InvalidCloudCredentials as e:
1439+
# Failed due to invalid cloud credentials.
1440+
logger.warning(f'{common_utils.format_exception(e)}')
1441+
# We should block the entire cloud for invalid cloud credentials
1442+
_add_to_blocked_resources(
1443+
self._blocked_resources,
1444+
to_provision.copy(region=None, zone=None))
1445+
raise exceptions.ResourcesUnavailableError(
1446+
f'Failed to provision on cloud {to_provision.cloud} due to '
1447+
f'invalid cloud credentials: '
1448+
f'{common_utils.format_exception(e)}')
14381449
except exceptions.InvalidCloudConfigs as e:
14391450
# Failed due to invalid user configs in ~/.sky/config.yaml.
14401451
logger.warning(f'{common_utils.format_exception(e)}')

sky/exceptions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ class InvalidCloudConfigs(Exception):
180180
pass
181181

182182

183-
class CloudCredentialExpired(Exception):
184-
"""Raised when the cloud credentials have expired."""
183+
class InvalidCloudCredentials(Exception):
184+
"""Raised when the cloud credentials are invalid."""
185185
pass
186186

187187

sky/provision/aws/utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ def handle_boto_error(exc: Exception, msg: str) -> None:
7474
f'{colorama.Style.RESET_ALL}\n'
7575
f'You can find a script that automates this at:'
7676
f'{aws_session_script_url}')
77-
# Raise the CloudCredentialExpired exception so that
77+
# Raise the InvalidCloudCredentials exception so that
7878
# the provisioner can failover to other clouds
79-
raise exceptions.CloudCredentialExpired(
80-
f'CloudCredentialExpired: {generic_message}') from exc
79+
raise exceptions.InvalidCloudCredentials(
80+
f'InvalidCloudCredentials: {generic_message}') from exc
8181

8282
# todo: any other errors that we should catch separately?
8383

sky/provision/provisioner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def bulk_provision(
145145
except exceptions.NoClusterLaunchedError:
146146
# Skip the teardown if the cluster was never launched.
147147
raise
148-
except exceptions.CloudCredentialExpired:
148+
except exceptions.InvalidCloudCredentials:
149149
# Skip the teardown if the cloud config is expired and
150150
# the provisioner should failover to other clouds.
151151
raise

0 commit comments

Comments
 (0)