[moblab] Better error for mobmonitor gs speed test

Don't show a command error pop-up if the user runs the speed test
diagnostic before configuring google storage. Just show a message
in the results area.

BUG=chromium:842011
TEST=Test on local device, cloud_storage_speedtest_unittest.py

Change-Id: I0d9d377b8e5568f471223e95596729eeea1aecc9
Reviewed-on: https://chromium-review.googlesource.com/1138988
Commit-Ready: Matt Mallett <mattmallett@chromium.org>
Tested-by: Keith Haddow <haddowk@chromium.org>
Reviewed-by: Keith Haddow <haddowk@chromium.org>
diff --git a/src/mobmonitor/diagnostic_checks/cloud_storage_speedtest.py b/src/mobmonitor/diagnostic_checks/cloud_storage_speedtest.py
index 6ddf396..d59c8db 100644
--- a/src/mobmonitor/diagnostic_checks/cloud_storage_speedtest.py
+++ b/src/mobmonitor/diagnostic_checks/cloud_storage_speedtest.py
@@ -20,6 +20,9 @@
 
     GSUTIL_USER = 'moblab'
 
+    FAILURE_MESSAGE_TEMPLATE = (
+        'Moblab is not configured to access Google Storage\n%s')
+
     category = 'Cloud Storage'
 
     name = 'Speed Test'
@@ -45,12 +48,21 @@
     def run(self):
         bucket_url = config.Config().get('image_storage_server')
         if bucket_url is None:
-            raise DiagnosticError('Bucket URL is not configured')
+            return self.FAILURE_MESSAGE_TEMPLATE % 'No bucket is set'
+
+        # test that the boto configuration is correct before running speedtest
+        ls_cmd = ['gsutil', 'ls', '-b', bucket_url]
+        try:
+            osutils.sudo_run_command(ls_cmd, user=self.GSUTIL_USER)
+        except osutils.RunCommandError:
+            return (self.FAILURE_MESSAGE_TEMPLATE %
+                "Can't connect with bucket " + bucket_url)
 
         output_file = '/tmp/perfdiag_output.json'
-        cmd = ['gsutil', 'perfdiag', '-s' '1M', '-o', output_file, bucket_url]
+        perf_cmd = [
+            'gsutil', 'perfdiag', '-s' '1M', '-o', output_file, bucket_url]
         try:
-            osutils.sudo_run_command(cmd, user=self.GSUTIL_USER)
+            osutils.sudo_run_command(perf_cmd, user=self.GSUTIL_USER)
         except osutils.RunCommandError:
             raise DiagnosticError('Failed to run gsutil perfdiag command')