Bug 1298771 - Attach last-update.log to update results for Firefox UI update tests draft
authorHenrik Skupin <mail@hskupin.info>
Mon, 29 Aug 2016 17:55:42 +0200
changeset 406855 a3f039155d09fecac654a341d4b8d191a3f5c4f1
parent 406727 4f72b1d0526767db87007ed8f00f07cf90e49443
child 529766 07240c0f889f7815e75cd99d13d8713fd8a11f1d
push id27847
push userbmo:hskupin@gmail.com
push dateMon, 29 Aug 2016 18:43:33 +0000
bugs1298771
milestone51.0a1
Bug 1298771 - Attach last-update.log to update results for Firefox UI update tests MozReview-Commit-ID: DtNwBbPuHPy
testing/firefox-ui/harness/firefox_ui_harness/testcases.py
--- a/testing/firefox-ui/harness/firefox_ui_harness/testcases.py
+++ b/testing/firefox-ui/harness/firefox_ui_harness/testcases.py
@@ -1,12 +1,13 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
+import os
 import pprint
 from datetime import datetime
 
 import mozfile
 
 from marionette import MarionetteTestCase
 from marionette_driver import Wait
 
@@ -109,20 +110,22 @@ class UpdateTestCase(FirefoxTestCase):
         # Check if the user has permissions to run the update
         self.assertTrue(self.software_update.allowed,
                         'Current user has permissions to update the application.')
 
     def tearDown(self):
         try:
             self.browser.tabbar.close_all_tabs([self.browser.tabbar.selected_tab])
 
+            # Add content of the update log file for detailed failures when applying an update
+            self.updates[self.current_update_index]['update_log'] = self.read_update_log()
+
             # Print results for now until we have treeherder integration
             output = pprint.pformat(self.updates)
             self.logger.info('Update test results: \n{}'.format(output))
-
         finally:
             super(UpdateTestCase, self).tearDown()
 
             # Ensure that no trace of an partially downloaded update remain
             self.remove_downloaded_update()
 
             self.restore_config_files()
 
@@ -350,21 +353,35 @@ class UpdateTestCase(FirefoxTestCase):
                 dialog.close()
 
             finally:
                 self.updates[self.current_update_index]['patch'] = self.patch_info
 
         # Restart Firefox to apply the update
         self.restart()
 
+    def read_update_log(self):
+        """Read the content of the update log file for the last update attempt."""
+        path = os.path.join(os.path.dirname(self.software_update.staging_directory),
+                            'last-update.log')
+        try:
+            with open(path, 'rb') as f:
+                return f.read().splitlines()
+        except IOError as exc:
+            self.logger.warning(str(exc))
+            return None
+
     def remove_downloaded_update(self):
-        """Remove an already downloaded update from the update staging directory."""
-        self.logger.info('Clean-up update staging directory: {}'.format(
-            self.software_update.staging_directory))
-        mozfile.remove(self.software_update.staging_directory)
+        """Remove an already downloaded update from the update staging directory.
+
+        Hereby not only remove the update subdir but everything below 'updates'.
+        """
+        path = os.path.dirname(self.software_update.staging_directory)
+        self.logger.info('Clean-up update staging directory: {}'.format(path))
+        mozfile.remove(path)
 
     def restore_config_files(self):
         # Reset channel-prefs.js file if modified
         try:
             if self.default_update_channel:
                 path = self.default_update_channel['path']
                 self.logger.info('Restoring channel defaults for: {}'.format(path))
                 with open(path, 'w') as f: