Bug 1233679 - UpdateTestcase should remove any partially downloaded update. r?maja_zf draft
authorHenrik Skupin <mail@hskupin.info>
Tue, 24 May 2016 12:14:59 +0200
changeset 370246 12f01c92f633bdeee6318ef9097d447cf6b13f9e
parent 368850 cfe3bbf2dc6beec52c4f5f939987673f97d51619
child 521706 e01f6c66526ac77a612b5300e179b1b3e3d853bf
push id19014
push userbmo:hskupin@gmail.com
push dateTue, 24 May 2016 10:15:22 +0000
reviewersmaja_zf
bugs1233679
milestone49.0a1
Bug 1233679 - UpdateTestcase should remove any partially downloaded update. r?maja_zf MozReview-Commit-ID: FpKDcElYF7L
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,15 +1,17 @@
 # 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 pprint
 from datetime import datetime
 
+import mozfile
+
 from marionette import MarionetteTestCase
 from marionette_driver import Wait
 
 from firefox_puppeteer.api.prefs import Preferences
 from firefox_puppeteer.api.software_update import SoftwareUpdate
 from firefox_puppeteer.testcases import BaseFirefoxTestCase
 from firefox_puppeteer.ui.update_wizard import UpdateWizardDialog
 
@@ -52,17 +54,18 @@ class UpdateTestCase(FirefoxTestCase):
         super(UpdateTestCase, self).setUp()
 
         self.software_update = SoftwareUpdate(lambda: self.marionette)
         self.download_duration = None
 
         # Bug 604364 - Preparation to test multiple update steps
         self.current_update_index = 0
 
-        self.staging_directory = self.software_update.staging_directory
+        # Ensure that there exists no already partially downloaded update
+        self.remove_downloaded_update()
 
         # If requested modify the default update channel. It will be active
         # after the next restart of the application
         # Bug 1142805 - Modify file via Python directly
         if self.update_channel:
             # Backup the original content and the path of the channel-prefs.js file
             self.default_update_channel = {
                 'content': self.software_update.update_channel.file_contents,
@@ -113,16 +116,19 @@ class UpdateTestCase(FirefoxTestCase):
 
             # 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()
 
     @property
     def patch_info(self):
         """ Returns information about the active update in the queue.
 
         :returns: A dictionary with information about the active patch
         """
@@ -357,16 +363,22 @@ 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 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)
+
     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:
                     f.write(self.default_update_channel['content'])