You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by rb...@apache.org on 2010/08/12 09:44:09 UTC

svn commit: r984671 - in /incubator/libcloud/trunk: libcloud/drivers/gogrid.py test/fixtures/gogrid/ip_list_empty.json test/test_gogrid.py

Author: rbogorodskiy
Date: Thu Aug 12 07:44:09 2010
New Revision: 984671

URL: http://svn.apache.org/viewvc?rev=984671&view=rev
Log:
Make GoGrid driver throw an exception when trying
to create a node and there are no public IPs available
for it.

Added:
    incubator/libcloud/trunk/test/fixtures/gogrid/ip_list_empty.json
Modified:
    incubator/libcloud/trunk/libcloud/drivers/gogrid.py
    incubator/libcloud/trunk/test/test_gogrid.py

Modified: incubator/libcloud/trunk/libcloud/drivers/gogrid.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/drivers/gogrid.py?rev=984671&r1=984670&r2=984671&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/drivers/gogrid.py (original)
+++ incubator/libcloud/trunk/libcloud/drivers/gogrid.py Thu Aug 12 07:44:09 2010
@@ -16,7 +16,8 @@
 GoGrid driver
 """
 from libcloud.providers import Provider
-from libcloud.types import NodeState, MalformedResponseException, InvalidCredsException
+from libcloud.types import NodeState, MalformedResponseException,\
+        InvalidCredsException, LibCloudException
 from libcloud.base import Node, ConnectionUserAndKey, Response, NodeDriver
 from libcloud.base import NodeSize, NodeImage, NodeLocation
 import time
@@ -230,7 +231,11 @@ class GoGridNodeDriver(NodeDriver):
     def _get_first_ip(self):
         params = {'ip.state': 'Unassigned', 'ip.type': 'public'}
         object = self.connection.request("/api/grid/ip/list", params).object
-        return object['list'][0]['ip']
+        if object['list']:
+            return object['list'][0]['ip']
+        else:
+            raise LibCloudException('No public unassigned IPs left',
+                    GoGridNodeDriver)
 
     def list_sizes(self, location=None):
         return [ NodeSize(driver=self.connection.driver, **i)

Added: incubator/libcloud/trunk/test/fixtures/gogrid/ip_list_empty.json
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/fixtures/gogrid/ip_list_empty.json?rev=984671&view=auto
==============================================================================
--- incubator/libcloud/trunk/test/fixtures/gogrid/ip_list_empty.json (added)
+++ incubator/libcloud/trunk/test/fixtures/gogrid/ip_list_empty.json Thu Aug 12 07:44:09 2010
@@ -0,0 +1,12 @@
+{
+    "list": [
+    ],
+    "method": "/grid/ip/list",
+    "status": "success",
+    "summary": {
+        "numpages": 0,
+        "returned": 0,
+        "start": 0,
+        "total": 0
+    }
+}

Modified: incubator/libcloud/trunk/test/test_gogrid.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/test_gogrid.py?rev=984671&r1=984670&r2=984671&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/test_gogrid.py (original)
+++ incubator/libcloud/trunk/test/test_gogrid.py Thu Aug 12 07:44:09 2010
@@ -73,7 +73,7 @@ class GoGridTests(unittest.TestCase, Tes
         try:
             images = self.driver.list_images()
         except LibCloudException, e:
-            self.assertEqual(True, isinstance(e, LibCloudException))
+            self.assertTrue(isinstance(e, LibCloudException))
         else:
             self.fail("test should have thrown")
 
@@ -87,6 +87,20 @@ class GoGridTests(unittest.TestCase, Tes
         else:
             self.fail("test should have thrown")
 
+    def test_node_creation_without_free_public_ips(self):
+        GoGridMockHttp.type = 'NOPUBIPS'
+        try:
+            image = NodeImage(1531, None, self.driver)
+            size = NodeSize('512Mb', None, None, None, None, None, driver=self.driver)
+
+            node = self.driver.create_node(name='test1', image=image, size=size)
+        except LibCloudException, e:
+            self.assertTrue(isinstance(e, LibCloudException))
+            self.assertTrue(e.driver is not None)
+            self.assertEqual(e.driver.name, self.driver.name)
+        else:
+            self.fail("test should have thrown")
+
 class GoGridMockHttp(MockHttp):
 
     fixtures = FileFixtures('gogrid')
@@ -103,6 +117,8 @@ class GoGridMockHttp(MockHttp):
         body = self.fixtures.load('server_list.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    _api_grid_server_list_NOPUBIPS = _api_grid_server_list
+
     def _api_grid_server_list_FAIL(self, method, url, body, headers):
         return (httplib.FORBIDDEN, "123", {}, httplib.responses[httplib.FORBIDDEN])
 
@@ -110,6 +126,10 @@ class GoGridMockHttp(MockHttp):
         body = self.fixtures.load('ip_list.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _api_grid_ip_list_NOPUBIPS(self, method, url, body, headers):
+        body = self.fixtures.load('ip_list_empty.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
     def _api_grid_server_power(self, method, url, body, headers):
         body = self.fixtures.load('server_power.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
@@ -118,6 +138,8 @@ class GoGridMockHttp(MockHttp):
         body = self.fixtures.load('server_add.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    _api_grid_server_add_NOPUBIPS = _api_grid_server_add
+
     def _api_grid_server_delete(self, method, url, body, headers):
         body = self.fixtures.load('server_delete.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
@@ -126,5 +148,7 @@ class GoGridMockHttp(MockHttp):
         body = self.fixtures.load('password_list.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    _api_support_password_list_NOPUBIPS = _api_support_password_list
+
 if __name__ == '__main__':
     sys.exit(unittest.main())