Bug 1256730 - Fail configure when API key files do not exist or are empty. r=chmanchester, r=mikedeboer, a=jcristau
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 09 Aug 2016 18:17:35 +0900
changeset 377939 d68404317ac4634a36e3c931e616f86cc8293624
parent 377938 2aa800c5c8f8d75b28adb870205a4741162768c9
child 377940 d72b6265473009f102359a293eb3a7c79c25eb96
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester, mikedeboer, jcristau
bugs1256730
milestone53.0a2
Bug 1256730 - Fail configure when API key files do not exist or are empty. r=chmanchester, r=mikedeboer, a=jcristau
build/moz.configure/keyfiles.configure
python/mozbuild/mozbuild/test/configure/test_checks_configure.py
--- a/build/moz.configure/keyfiles.configure
+++ b/build/moz.configure/keyfiles.configure
@@ -20,20 +20,19 @@ def keyfile(desc, help=None, callback=la
     @imports(_from='__builtin__', _import='IOError')
     def keyfile(value):
         if value:
             try:
                 with open(value[0]) as fh:
                     result = fh.read().strip()
                     if result:
                         return callback(result)
-            except FatalCheckError:
-                raise
-            except IOError:
-                pass
+                    raise FatalCheckError("'%s' is empty." % value[0])
+            except IOError as e:
+                raise FatalCheckError("'%s': %s." % (value[0], e.strerror))
         return no_key
 
     return keyfile
 
 
 @template
 def simple_keyfile(desc):
     value = keyfile(desc)
--- a/python/mozbuild/mozbuild/test/configure/test_checks_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_checks_configure.py
@@ -835,23 +835,34 @@ class TestChecksConfigure(unittest.TestC
         self.assertEqual(config, {
             'MOZ_MOZILLA_API_KEY': 'no-mozilla-api-key',
         })
 
         config, output, status = self.get_result(
             "simple_keyfile('Mozilla API')",
             args=['--with-mozilla-api-keyfile=/foo/bar/does/not/exist'],
             includes=includes)
-        self.assertEqual(status, 0)
+        self.assertEqual(status, 1)
         self.assertEqual(output, textwrap.dedent('''\
             checking for the Mozilla API key... no
+            ERROR: '/foo/bar/does/not/exist': No such file or directory.
         '''))
-        self.assertEqual(config, {
-            'MOZ_MOZILLA_API_KEY': 'no-mozilla-api-key',
-        })
+        self.assertEqual(config, {})
+
+        with MockedOpen({'key': ''}):
+            config, output, status = self.get_result(
+                "simple_keyfile('Mozilla API')",
+                args=['--with-mozilla-api-keyfile=key'],
+                includes=includes)
+            self.assertEqual(status, 1)
+            self.assertEqual(output, textwrap.dedent('''\
+                checking for the Mozilla API key... no
+                ERROR: 'key' is empty.
+            '''))
+            self.assertEqual(config, {})
 
         with MockedOpen({'key': 'fake-key\n'}):
             config, output, status = self.get_result(
                 "simple_keyfile('Mozilla API')",
                 args=['--with-mozilla-api-keyfile=key'],
                 includes=includes)
             self.assertEqual(status, 0)
             self.assertEqual(output, textwrap.dedent('''\
@@ -874,24 +885,34 @@ class TestChecksConfigure(unittest.TestC
             'MOZ_BING_API_CLIENTID': 'no-bing-api-clientid',
             'MOZ_BING_API_KEY': 'no-bing-api-key',
         })
 
         config, output, status = self.get_result(
             "id_and_secret_keyfile('Bing API')",
             args=['--with-bing-api-keyfile=/foo/bar/does/not/exist'],
             includes=includes)
-        self.assertEqual(status, 0)
+        self.assertEqual(status, 1)
         self.assertEqual(output, textwrap.dedent('''\
             checking for the Bing API key... no
+            ERROR: '/foo/bar/does/not/exist': No such file or directory.
         '''))
-        self.assertEqual(config, {
-            'MOZ_BING_API_CLIENTID': 'no-bing-api-clientid',
-            'MOZ_BING_API_KEY': 'no-bing-api-key',
-        })
+        self.assertEqual(config, {})
+
+        with MockedOpen({'key': ''}):
+            config, output, status = self.get_result(
+                "id_and_secret_keyfile('Bing API')",
+                args=['--with-bing-api-keyfile=key'],
+                includes=includes)
+            self.assertEqual(status, 1)
+            self.assertEqual(output, textwrap.dedent('''\
+                checking for the Bing API key... no
+                ERROR: 'key' is empty.
+            '''))
+            self.assertEqual(config, {})
 
         with MockedOpen({'key': 'fake-id fake-key\n'}):
             config, output, status = self.get_result(
                 "id_and_secret_keyfile('Bing API')",
                 args=['--with-bing-api-keyfile=key'],
                 includes=includes)
             self.assertEqual(status, 0)
             self.assertEqual(output, textwrap.dedent('''\