Handle profile-copying errors.
authorMark Cote <mcote@mozilla.com>
Mon, 06 Jun 2011 14:19:02 -0400
changeset 50 fdbe44287aa6eba795a976df58ec67fe4f26cab2
parent 49 45f4b4b24c5865ebf1e3f8458438f09967767994
child 51 19e184c0802181e6454e7a6bfd164b0367434dea
push id48
push usermcote@mozilla.com
push dateMon, 06 Jun 2011 18:19:10 +0000
Handle profile-copying errors.
client/speedtests.py
--- a/client/speedtests.py
+++ b/client/speedtests.py
@@ -113,52 +113,63 @@ class BrowserController(object):
                 for f in filenames:
                     filepath = os.path.join(dirpath, f)
                     arcpath = filepath[len(p['path']):]
                     profile_zip.write(filepath, arcpath)
             profile_zip.close()
     
     def copy_profiles(self):
         if not self.browser_exists() or not self.profiles:
-            return
+            return False
         for p in self.profiles:
             profile_archive = self.get_profile_archive_path(p)
             if not os.path.exists(profile_archive):
                 return
             if os.path.exists(p['path']):
                 t = tempfile.mkdtemp()
-                shutil.move(p['path'], t)
+                try:
+                    shutil.move(p['path'], t)
+                except (IOError, OSError):
+                    print 'Failed to copy profile: %s' % sys.exc_info()[1]
+                    return False
                 p['previous_profile'] = os.path.join(t, os.path.basename(p['path']))
             else:
                 p['previous_profile'] = ''
             try:
                 os.mkdir(p['path'])
             except OSError:
                 pass
             profile_zip = zipfile.ZipFile(profile_archive, 'r')
             profile_zip.extractall(p['path'])
+        return True
     
     def clean_up(self):
         if not self.profiles:
             return
         for p in self.profiles:
             if not p['previous_profile']:
                 continue
-            shutil.rmtree(p['path'])
-            shutil.move(p['previous_profile'], p['path'])
-            os.rmdir(os.path.dirname(p['previous_profile']))
+            try:
+                shutil.rmtree(p['path'])
+                shutil.move(p['previous_profile'], p['path'])
+                os.rmdir(os.path.dirname(p['previous_profile']))
+            except (IOError, OSError):
+                print 'Failed to restore profile: %s' % sys.exc_info()[1]
+                pass
 
     def launch(self, url=None):
-        self.copy_profiles()
+        if not self.copy_profiles():
+            return False
         if not url:
             url = config.test_url
         cl = self.cmd_line(url)
         print 'Launching %s...' % ' '.join(cl)
         self.launch_time = datetime.datetime.now()
         self.proc = subprocess.Popen(cl)
+        return True
 
     def running(self):
         running = self.proc and self.proc.poll()
         if running != None:
             self.proc = None
         return running == None
 	
     def execution_time(self):
@@ -207,19 +218,20 @@ class LatestFxBrowserController(BrowserC
             shutil.rmtree(install_path, ignore_errors=True)
             fxins = fxinstall.FirefoxInstaller(install_path)
             print 'Getting firefox nightly...'
             if not fxins.get_install():
                 print 'Failed to get firefox nightly.'
         
     def launch(self, url=None):
         if self.os_name == 'windows':
-            super(LatestFxBrowserController, self).launch(url)
-        else:
-            print 'Nightly not yet supported on OSs other than Windows.'
+            return super(LatestFxBrowserController, self).launch(url)
+			
+        print 'Nightly not yet supported on OSs other than Windows.'
+        return False
 
 
 class IEController(BrowserController):
 
     """ Specialization to deal with IE's registry settings. """
 
     def __init__(self, os_name, browser_name, cmd, args_tuple=()):
         super(IEController, self).__init__(os_name, browser_name, [], cmd, args_tuple)
@@ -367,17 +379,16 @@ class BrowserRunner(object):
         self.testmode = testmode
         try:
             self.browsers = BrowserRunner.browsers_by_os(platform.system())
         except KeyError:
             sys.stderr.write('Unknown platform "%s".\n' % platform.system())
             sys.exit(errno.EOPNOTSUPP)
         self.browser_iter = BrowserRunner.BrowserControllerIter(self.browsers, browser_names)
         self.current_controller = None
-        self.proc = None
         self.lock = threading.Lock()
 
     def find_browser(self, browsername):
         for b in self.browsers:
             if b.browser_name == browsername:
                 return b
         print 'Unknown browser "%s".' % browsername
         return None
@@ -420,20 +431,21 @@ class BrowserRunner(object):
             try:
                 self.current_controller = self.browser_iter.next()
             except StopIteration:
                 self.evt.set()
                 self.lock.release()
                 return
             self.current_controller.init_browser()
             if self.current_controller.browser_exists():
-                break
-
-        print 'launching %s' % self.current_controller.browser_name
-        self.proc = self.current_controller.launch()
+                print 'launching %s' % self.current_controller.browser_name
+                if self.current_controller.launch():
+                    break
+                else:
+                    print 'failed to launch browser.'
         self.lock.release()
 
 
 class TestRunnerHTTPServer(BaseHTTPServer.HTTPServer):
     
     def __init__(self, server_address, RequestHandlerClass, browser_runner):
         BaseHTTPServer.HTTPServer.__init__(self, server_address, RequestHandlerClass)
         self.browser_runner = browser_runner