Commits

Mikhail Korobov committed 6d82452

update for fabric 1.4. Fix #2.

Comments (0)

Files changed (3)

 
 from fabric.api import env
 from fabric import state
+from fabric.state import connections
+from fabtest.utils import force_ssh_reconnect
 
 from fabtest.vbox import VirtualBox
-from fabtest.utils import close_fabric_connections
+from fabric.network import disconnect_all
 
 class VirtualBoxTest(unittest.TestCase):
     vm_name = 'Squeeze' # name or uuid of VirtualBox VM
     key_filename = None
 
     def setUp(self):
+        self.setup_env()
+        disconnect_all()
+        self.previous_env = state._AttributeDict(env)
         super(FabTest, self).setUp()
-        close_fabric_connections()
-        self.previous_env = state._AttributeDict(env)
-        self.setup_env()
 
     def tearDown(self):
-        close_fabric_connections()
+        disconnect_all()
         env.update(self.previous_env)
         super(FabTest, self).tearDown()
 
     def setup_env(self):
         env.hosts = [self.host]
         env.password = self.password
+        env.host_string = self.host
         env.key_filename = self.key_filename
         env.disable_known_hosts = True
-from fabric import state
-from fabric.tasks import WrappedCallableTask
+from __future__ import absolute_import
+from fabric.api import env
+from fabric.state import connections
+from fabric.tasks import execute
 
 class FabricAbortException(Exception):
     pass
 
 def fab(command, *args, **kwargs):
-    """ Runs fab command. Accepts callable. """
-
-    # collect results
-    results = []
-
-    # partially implement the logic from fabric.main.main
-    state.env.command = command.__name__
-    state.env.all_hosts = hosts = WrappedCallableTask(command).get_hosts(*args)
-
-    try: # convert fabric.abort() calls to real exceptions
-        for host in hosts:
-            interpret_host_string(host)
-            res = command(*args, **kwargs)
-            results.append(res)
-        return results
+    """
+    Runs fab command. Similar to fabric.task.execute but
+    converts 'abort' calls to exceptions of type FabricAbortException
+    and returns a list of results, not a dictionary.
+    """
+    try:
+        results = execute(command, *args, **kwargs)
+        # .values() is for backward compatibility with fabtest 0.0.8
+        # XXX: do we need backward compatibility?
+        return results.values()
     except SystemExit, e:
         import traceback
         traceback.print_exc()
         raise FabricAbortException()
 
-def close_fabric_connections():
-    for key, connection in state.connections.items():
-        connection.close()
-        del state.connections[key]
-
-
+def force_ssh_reconnect():
+    connections.connect(env.host_string)
     description = """ Test Fabric scripts on VirtualBox VMs """,
 
     long_description = open('README.rst').read(),
-    requires = ['Fabric'],
+    requires = ['Fabric (>= 1.4.0)'],
 
     classifiers=(
         'Development Status :: 3 - Alpha',
         'Intended Audience :: Developers',
         'License :: OSI Approved :: MIT License',
         'Programming Language :: Python',
+        'Programming Language :: Python :: 2',
+        'Programming Language :: Python :: 2.5',
+        'Programming Language :: Python :: 2.6',
+        'Programming Language :: Python :: 2.7',
         'Topic :: Software Development :: Libraries :: Python Modules',
         'Topic :: Software Development :: Testing',
     ),