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

Commit 9ee598b

Browse files
authored
Add a facility to warn users of versions with known issues. (#1958)
This change was prompted by the recent issue we had with version 20180105, where an issue was discovered, but we did not have a good means of notifying users about the issue. With this change, the CLI will download a versions info file from https://storage.googleapis.com/cloud-datalab/version-issues.js that contains a JSON object reporting known issues for any affected versions of the CLI. It will then check the current version against that object and report any matching warnings.
1 parent d03e93c commit 9ee598b

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

tools/cli/commands/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,18 @@ def maybe_prompt_for_zone(args, gcloud_compute, instance):
368368
return
369369

370370

371+
def print_warning_messages(args):
372+
"""Return whether or not warning messages should be printed.
373+
374+
Args:
375+
args: The Namespace instance returned by argparse
376+
Returns:
377+
True iff the verbosity has been set to a level that includes
378+
warning messages.
379+
"""
380+
return args.verbosity in ['debug', 'info', 'default', 'warning']
381+
382+
371383
def print_info_messages(args):
372384
"""Return whether or not info messages should be printed.
373385

tools/cli/datalab.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import os
2727
import subprocess
2828
import traceback
29+
import urllib2
2930

3031

3132
_SUBCOMMANDS = {
@@ -113,6 +114,11 @@
113114
datalab_component = 'datalab'
114115

115116

117+
# Public file reporting all known version issues.
118+
version_issues_url = (
119+
'https://storage.googleapis.com/cloud-datalab/version-issues.js')
120+
121+
116122
try:
117123
with open(os.devnull, 'w') as dn:
118124
subprocess.call(['gcloud', '--version'], stderr=dn, stdout=dn)
@@ -121,6 +127,31 @@
121127
gcloud_cmd = 'gcloud.cmd'
122128

123129

130+
def report_known_issues(sdk_version, datalab_version):
131+
try:
132+
version_issues_resp = urllib2.urlopen(version_issues_url)
133+
version_issues = json.loads(version_issues_resp.read())
134+
except urllib2.HTTPError as e:
135+
print('Error downloading the version information: {}'.format(e))
136+
return
137+
138+
sdk_issues = version_issues.get(sdk_core_component, {})
139+
known_sdk_issues = sdk_issues.get(sdk_version, [])
140+
if known_sdk_issues:
141+
print('You are using Cloud SDK version "{}", '
142+
'which has the following known issues:\n\t{}'.format(
143+
sdk_version,
144+
'\n\t'.join(known_sdk_issues)))
145+
datalab_issues = version_issues.get(datalab_component, {})
146+
known_datalab_issues = datalab_issues.get(datalab_version, [])
147+
if known_datalab_issues:
148+
print('You are using the Datalab CLI version "{}", '
149+
'which has the following known issues:\n\t{}'.format(
150+
datalab_version,
151+
'\n\t'.join(known_datalab_issues)))
152+
return
153+
154+
124155
def add_gcloud_verbosity_flag(args, gcloud_cmd):
125156
"""Add the appropriate '---verbosity' flag to the given gcloud command.
126157
@@ -361,6 +392,9 @@ def run():
361392
'\n\tCloud SDK: {}\n\tDatalab: {}'.format(
362393
sdk_version, datalab_version))
363394

395+
if utils.print_warning_messages(args):
396+
report_known_issues(sdk_version, datalab_version)
397+
364398
gcloud_zone = ""
365399
if args.subcommand == 'beta':
366400
subcommand = _BETA_SUBCOMMANDS[args.beta_subcommand]

0 commit comments

Comments
 (0)