You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2011/06/17 20:35:16 UTC

svn commit: r1136970 - in /libcloud/trunk: libcloud/compute/base.py setup.py

Author: tomaz
Date: Fri Jun 17 18:35:16 2011
New Revision: 1136970

URL: http://svn.apache.org/viewvc?rev=1136970&view=rev
Log:
Refactor deploy_node a bit more and add mock to tests_requires.

Modified:
    libcloud/trunk/libcloud/compute/base.py
    libcloud/trunk/setup.py

Modified: libcloud/trunk/libcloud/compute/base.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/base.py?rev=1136970&r1=1136969&r2=1136970&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/base.py (original)
+++ libcloud/trunk/libcloud/compute/base.py Fri Jun 17 18:35:16 2011
@@ -33,6 +33,13 @@ from libcloud.httplib_ssl import Libclou
 from libcloud.common.base import LibcloudHTTPConnection
 from libcloud.common.types import LibcloudError
 
+# How long to wait for the node to come online after creating it
+NODE_ONLINE_WAIT_TIMEOUT = 10*60
+
+# How long to try connecting to a remote SSH server when running a deployment
+# script.
+SSH_CONNECT_TIMEOUT=5*60
+
 __all__ = [
     "Node",
     "NodeState",
@@ -520,7 +527,7 @@ class NodeDriver(object):
 
                 # Wait until node is up and running and has public IP assigned
                 node = self._wait_until_running(node=node, wait_period=3,
-                                                timeout=15*60)
+                                                timeout=NODE_ONLINE_WAIT_TIMEOUT)
 
                 ssh_username = kwargs.get('ssh_username', 'root')
                 ssh_port = kwargs.get('ssh_port', 22)
@@ -533,7 +540,7 @@ class NodeDriver(object):
 
                 # Connect to the SSH server running on the node
                 ssh_client = self._ssh_client_connect(ssh_client=ssh_client,
-                                                      timeout=300)
+                                                      timeout=SSH_CONNECT_TIMEOUT)
 
                 # Execute the deployment task
                 node = self._run_deployment_script(task=kwargs['deploy'],
@@ -569,13 +576,13 @@ class NodeDriver(object):
         while tries < max_tries:
             try:
                 node = task.run(node, ssh_client)
-                ssh_client.close()
             except Exception:
                 tries += 1
                 if tries >= max_tries:
                     raise LibcloudError(value='Failed after %d tries'
                                         % (max_tries), driver=self)
             else:
+                ssh_client.close()
                 return node
 
     def _ssh_client_connect(self, ssh_client, timeout=300):
@@ -630,21 +637,18 @@ class NodeDriver(object):
         end = start + timeout
 
         while time.time() < end:
-            time.sleep(wait_period)
             nodes = self.list_nodes()
             nodes = filter(lambda n: n.uuid == node.uuid, nodes)
 
             if len(nodes) == 0:
-                raise DeploymentError(
-                    node,
-                    ("Booted node[%s] " % node
-                     + "is missing from list_nodes."))
+                raise LibcloudError(value=('Booted node[%s] ' % node
+                                    + 'is missing from list_nodes.'),
+                                    driver=self)
 
             if len(nodes) > 1:
-                raise DeploymentError(
-                    node,
-                    ("Booted single node[%s], " % node
-                     + "but multiple nodes have same UUID"))
+                raise LibcloudError(value=('Booted single node[%s], ' % node
+                                    + 'but multiple nodes have same UUID'),
+                                    driver=self)
 
             node = nodes[0]
 
@@ -653,6 +657,7 @@ class NodeDriver(object):
                 and node.state == NodeState.RUNNING):
                 return node
             else:
+                time.sleep(wait_period)
                 continue
 
         raise LibcloudError(value='Timed out after %s seconds' % (timeout),

Modified: libcloud/trunk/setup.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/setup.py?rev=1136970&r1=1136969&r2=1136970&view=diff
==============================================================================
--- libcloud/trunk/setup.py (original)
+++ libcloud/trunk/setup.py Fri Jun 17 18:35:16 2011
@@ -152,6 +152,7 @@ setup(
     author='Apache Software Foundation',
     author_email='dev@libcloud.apache.org',
     requires=([], ['ssl', 'simplejson'],)[pre_python26],
+    tests_require=('mock'),
     packages=[
         'libcloud',
         'libcloud.common',