Author: tomaz
Date: Thu Jul  7 17:00:42 2011
New Revision: 1143922

URL: http://svn.apache.org/viewvc?rev=1143922&view=rev
Log:
Throw an exception in deploy_node if paramiko is not available.

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=1143922&r1=1143921&r2=1143922&view=diff
==============================================================================
--- libcloud/trunk/libcloud/compute/base.py (original)
+++ libcloud/trunk/libcloud/compute/base.py Thu Jul  7 17:00:42 2011
@@ -23,6 +23,7 @@ import os
 import socket
 import struct
 
+import libcloud.compute.ssh
 from libcloud.pricing import get_size_price
 from libcloud.compute.types import NodeState, DeploymentError
 from libcloud.compute.ssh import SSHClient
@@ -516,6 +517,10 @@ class NodeDriver(object):
         Deploy node is typically not overridden in subclasses.  The
         existing implementation should be able to handle most such.
         """
+        if not libcloud.compute.ssh.have_paramiko:
+            raise RuntimeError('paramiko is not installed. You can install ' +
+                               'it using pip: pip install paramiko')
+
         # TODO: support ssh keys
         password = None
 

Modified: libcloud/trunk/test/compute/test_deployment.py
URL: 
http://svn.apache.org/viewvc/libcloud/trunk/test/compute/test_deployment.py?rev=1143922&r1=1143921&r2=1143922&view=diff
==============================================================================
--- libcloud/trunk/test/compute/test_deployment.py (original)
+++ libcloud/trunk/test/compute/test_deployment.py Thu Jul  7 17:00:42 2011
@@ -284,6 +284,27 @@ class DeploymentTests(unittest.TestCase)
         node = self.driver.deploy_node(deploy=Mock())
         self.assertEqual(self.node.id, node.id)
 
+    @patch('libcloud.compute.base.SSHClient')
+    @patch('libcloud.compute.ssh')
+    def test_exception_is_thrown_is_paramiko_is_not_available(self,
+                                                              mock_ssh_module,
+                                                              _):
+        self.driver.features = {'create_node': ['password']}
+        self.driver.create_node = Mock()
+        self.driver.create_node.return_value = self.node
+
+        mock_ssh_module.have_paramiko = False
+
+        try:
+            self.driver.deploy_node(deploy=Mock())
+        except RuntimeError, e:
+            self.assertTrue(str(e).find('paramiko is not installed') != -1)
+        else:
+            self.fail('Exception was not thrown')
+
+        mock_ssh_module.have_paramiko = True
+        node = self.driver.deploy_node(deploy=Mock())
+        self.assertEqual(self.node.id, node.id)
 
 class RackspaceMockHttp(MockHttp):
 


Reply via email to