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 22:39:04 UTC
svn commit: r1137012 - in /libcloud/trunk: libcloud/compute/base.py
test/compute/test_deployment.py
Author: tomaz
Date: Fri Jun 17 20:39:04 2011
New Revision: 1137012
URL: http://svn.apache.org/viewvc?rev=1137012&view=rev
Log:
1. More tests
2. Some style changes
3. Whole deployment code shouldn't be inside an if
Modified:
libcloud/trunk/libcloud/compute/base.py
libcloud/trunk/test/compute/test_deployment.py
Modified: libcloud/trunk/libcloud/compute/base.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/libcloud/compute/base.py?rev=1137012&r1=1137011&r2=1137012&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/base.py (original)
+++ libcloud/trunk/libcloud/compute/base.py Fri Jun 17 20:39:04 2011
@@ -517,40 +517,39 @@ class NodeDriver(object):
raise NotImplementedError, \
'deploy_node not implemented for this driver'
- if not kwargs.has_key('auth'):
+ if 'auth' not in kwargs:
kwargs['auth'] = NodeAuthPassword(os.urandom(16).encode('hex'))
password = kwargs['auth'].password
node = self.create_node(**kwargs)
- try:
- if 'generates_password' in self.features['create_node']:
- password = node.extra.get('password')
-
- # Wait until node is up and running and has public IP assigned
- node = self._wait_until_running(node=node, wait_period=3,
- timeout=NODE_ONLINE_WAIT_TIMEOUT)
-
- ssh_username = kwargs.get('ssh_username', 'root')
- ssh_port = kwargs.get('ssh_port', 22)
- ssh_timeout = kwargs.get('ssh_timeout', 10)
-
- ssh_client = SSHClient(hostname=node.public_ip[0],
- port=ssh_port, username=ssh_username,
- password=password,
- timeout=ssh_timeout)
-
- # Connect to the SSH server running on the node
- ssh_client = self._ssh_client_connect(ssh_client=ssh_client,
- timeout=SSH_CONNECT_TIMEOUT)
-
- # Execute the deployment task
- node = self._run_deployment_script(task=kwargs['deploy'],
- node=node,
- ssh_client=ssh_client,
- max_tries=3)
+ if 'generates_password' in self.features['create_node']:
+ password = node.extra.get('password')
+ try:
+ # Wait until node is up and running and has public IP assigned
+ self._wait_until_running(node=node, wait_period=3,
+ timeout=NODE_ONLINE_WAIT_TIMEOUT)
+
+ ssh_username = kwargs.get('ssh_username', 'root')
+ ssh_port = kwargs.get('ssh_port', 22)
+ ssh_timeout = kwargs.get('ssh_timeout', 10)
+
+ ssh_client = SSHClient(hostname=node.public_ip[0],
+ port=ssh_port, username=ssh_username,
+ password=password,
+ timeout=ssh_timeout)
+
+ # Connect to the SSH server running on the node
+ ssh_client = self._ssh_client_connect(ssh_client=ssh_client,
+ timeout=SSH_CONNECT_TIMEOUT)
+
+ # Execute the deployment task
+ self._run_deployment_script(task=kwargs['deploy'],
+ node=node,
+ ssh_client=ssh_client,
+ max_tries=3)
except Exception, e:
raise DeploymentError(node, e)
return node
Modified: libcloud/trunk/test/compute/test_deployment.py
URL: http://svn.apache.org/viewvc/libcloud/trunk/test/compute/test_deployment.py?rev=1137012&r1=1137011&r2=1137012&view=diff
==============================================================================
--- libcloud/trunk/test/compute/test_deployment.py (original)
+++ libcloud/trunk/test/compute/test_deployment.py Fri Jun 17 20:39:04 2011
@@ -221,7 +221,8 @@ class DeploymentTests(unittest.TestCase)
deploy = Mock()
- self.driver.deploy_node(deploy=deploy)
+ node = self.driver.deploy_node(deploy=deploy)
+ self.assertEqual(self.node.id, node.id)
@patch('libcloud.compute.base.SSHClient')
def test_deploy_node_exception_run_deployment_script(self, _):
@@ -239,7 +240,7 @@ class DeploymentTests(unittest.TestCase)
else:
self.fail('Exception was not thrown')
- @patch('libcloud.compute.base.SSHClient', spec=True)
+ @patch('libcloud.compute.base.SSHClient')
def test_deploy_node_exception_ssh_client_connect(self, ssh_client):
self.driver.create_node = Mock()
self.driver.create_node.return_value = self.node
@@ -255,8 +256,6 @@ class DeploymentTests(unittest.TestCase)
self.fail('Exception was not thrown')
def test_deploy_node_depoy_node_not_implemented(self):
- oldFeatures = self.driver.features
-
self.driver.features = {'create_node': []}
try:
@@ -275,6 +274,16 @@ class DeploymentTests(unittest.TestCase)
else:
self.fail('Exception was not thrown')
+ @patch('libcloud.compute.base.SSHClient')
+ def test_deploy_node_password_auth(self, _):
+ self.driver.features = {'create_node': ['password']}
+
+ self.driver.create_node = Mock()
+ self.driver.create_node.return_value = self.node
+
+ node = self.driver.deploy_node(deploy=Mock())
+ self.assertEqual(self.node.id, node.id)
+
class RackspaceMockHttp(MockHttp):