Commits

Mikhail Korobov committed 14c7d95

forced ssh reconnection was a bad idea that breaks things; make it opt-in

Comments (0)

Files changed (2)

example/runtests.py

         fab(mkfile)
         self.assertTrue(fab(file_exists)[0])
 
-        self.take_snapshot('test-snapshot')
+        self.take_test_snapshot('test-snapshot')
         self.assertTrue(fab(file_exists)[0])
 
-        self.activate_snapshot(self.snapshot)
+        self.activate_test_snapshot(self.snapshot)
         self.assertFalse(fab(file_exists)[0])
 
-        self.activate_snapshot('test-snapshot')
+        self.activate_test_snapshot('test-snapshot')
         self.assertTrue(fab(file_exists)[0])
 
 
 
 from fabric.api import env
 from fabric import state
-from fabric.state import connections
-from fabtest.utils import force_ssh_reconnect
+from fabric.network import disconnect_all
 
 from fabtest.vbox import VirtualBox
-from fabric.network import disconnect_all
+from fabtest.utils import force_ssh_reconnect
 
 class VirtualBoxTest(unittest.TestCase):
     vm_name = 'Squeeze' # name or uuid of VirtualBox VM
         self.activate_snapshot(self.snapshot)
 
     def tearDown(self):
-        if not self.keep_box:
-            self.box.stop()
+        if self.keep_box:
+            return
+        self.box.stop()
         for name in self._snapshots:
             self.box.snapshot('delete', name)
 
         self.box.snapshot('restore', name)
         self.box.start(self.headless)
 
-    def take_snapshot(self, name):
+    def take_test_snapshot(self, name):
         """
         Creates temporary snapshot that will be deleted after test.
         """
         env.key_filename = self.key_filename
         env.disable_known_hosts = True
 
-    def activate_snapshot(self, name):
-        super(FabTest, self).activate_snapshot(name)
-        force_ssh_reconnect()
+    def take_test_snapshot(self, name, reconnect=True):
+        super(FabTest, self).take_test_snapshot(name)
+        if reconnect:
+            force_ssh_reconnect()
 
-    def take_snapshot(self, name):
-        super(FabTest, self).take_snapshot(name)
-        force_ssh_reconnect()
+    def activate_test_snapshot(self, name, reconnect=True):
+        """
+        Activates test snapshot.
+        """
+        self.activate_snapshot(name)
+        if reconnect:
+            force_ssh_reconnect()