Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Commit 695e522

Browse files
robertwbaaltay
authored andcommitted
Better error messaging on missing gcloud
Also don't retry certain permanent auth errors. ----Release Notes---- [] ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=117748492
1 parent 0228864 commit 695e522

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

google/cloud/dataflow/internal/auth.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from oauth2client.client import OAuth2Credentials
2626

2727
from google.cloud.dataflow.utils import processes
28+
from google.cloud.dataflow.utils import retry
2829
from google.cloud.dataflow.utils.options import GoogleCloudOptions
2930
from google.cloud.dataflow.utils.options import PipelineOptions
3031

@@ -53,6 +54,10 @@ def set_running_in_gce(worker_executing_project):
5354
executing_project = worker_executing_project
5455

5556

57+
class AuthenticationException(retry.PermanentException):
58+
pass
59+
60+
5661
class GCEMetadataCredentials(OAuth2Credentials):
5762
"""Credential object initialized using access token from GCE VM metadata."""
5863

@@ -98,8 +103,8 @@ def _refresh(self, http_request):
98103
gcloud_process = processes.Popen(
99104
['gcloud', 'auth', 'print-access-token'], stdout=processes.PIPE)
100105
except OSError as exn:
101-
logging.error('The gcloud tool was not found.')
102-
raise exn
106+
logging.error('The gcloud tool was not found.', exc_info=True)
107+
raise AuthenticationException('The gcloud tool was not found: %s' % exn)
103108
output, _ = gcloud_process.communicate()
104109
self.access_token = output.strip()
105110

@@ -120,9 +125,11 @@ def get_service_credentials():
120125
sys.argv).view_as(GoogleCloudOptions)
121126
if google_cloud_options.service_account_name:
122127
if not google_cloud_options.service_account_key_file:
123-
raise Exception('key file not provided for service account.')
128+
raise AuthenticationException(
129+
'key file not provided for service account.')
124130
if not os.path.exists(google_cloud_options.service_account_key_file):
125-
raise Exception('Specified service account key file does not exist.')
131+
raise AuthenticationException(
132+
'Specified service account key file does not exist.')
126133
client_scopes = [
127134
'https://www.googleapis.com/auth/bigquery',
128135
'https://www.googleapis.com/auth/cloud-platform',

google/cloud/dataflow/utils/retry.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
from apitools.base.py.exceptions import HttpError
3030

3131

32+
class PermanentException(Exception):
33+
"""Base class for exceptions that should not be retried."""
34+
pass
35+
36+
3237
class FuzzedExponentialIntervals(object):
3338
"""Iterable for intervals that are exponentially spaced, with fuzzing.
3439
@@ -75,6 +80,8 @@ def retry_on_server_errors_filter(exception):
7580
return True
7681
else:
7782
return False
83+
elif isinstance(exception, PermanentException):
84+
return False
7885
else:
7986
# We may get here for non HttpErrors such as socket timeouts, SSL
8087
# exceptions, etc.

0 commit comments

Comments
 (0)