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/03/17 04:07:08 UTC

svn commit: r1082389 - in /incubator/libcloud/trunk: libcloud/compute/drivers/gogrid.py test/compute/fixtures/gogrid/server_power_fail.json test/compute/test_gogrid.py

Author: tomaz
Date: Thu Mar 17 03:07:08 2011
New Revision: 1082389

URL: http://svn.apache.org/viewvc?rev=1082389&view=rev
Log:
Increase GoGrid driver test coverage.

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

Modified: incubator/libcloud/trunk/libcloud/compute/drivers/gogrid.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/libcloud/compute/drivers/gogrid.py?rev=1082389&r1=1082388&r2=1082389&view=diff
==============================================================================
--- incubator/libcloud/trunk/libcloud/compute/drivers/gogrid.py (original)
+++ incubator/libcloud/trunk/libcloud/compute/drivers/gogrid.py Thu Mar 17 03:07:08 2011
@@ -96,7 +96,7 @@ class GoGridResponse(Response):
     def parse_error(self):
         try:
             return json.loads(self.body)["list"][0]['message']
-        except ValueError:
+        except (ValueError, KeyError):
             return None
 
 class GoGridConnection(ConnectionUserAndKey):

Added: incubator/libcloud/trunk/test/compute/fixtures/gogrid/server_power_fail.json
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/compute/fixtures/gogrid/server_power_fail.json?rev=1082389&view=auto
==============================================================================
--- incubator/libcloud/trunk/test/compute/fixtures/gogrid/server_power_fail.json (added)
+++ incubator/libcloud/trunk/test/compute/fixtures/gogrid/server_power_fail.json Thu Mar 17 03:07:08 2011
@@ -0,0 +1,97 @@
+{
+    "list": [
+        {
+            "id": 90967,
+            "image": {
+                "billingtokens": [
+                    {
+                        "id": 46,
+                        "name": "CentOS 5.3 32bit",
+                        "price": 0
+                    }
+                ],
+                "description": "CentOS 5.3 (32-bit) w/ None",
+                "friendlyName": "CentOS 5.3 (32-bit) w/ None",
+                "id": 1531,
+                "isActive": true,
+                "isPublic": true,
+                "location": "gogrid/GSI-2c4c6672-69e1-4928-ac9d-a564521d55fe.img",
+                "name": "centos5.3_32_base",
+                "object": "serverimage",
+                "os": {
+                    "description": "CentOS 5.3 (32-bit)",
+                    "id": 16,
+                    "name": "CentOS 5.3 (32-bit)",
+                    "object": "option"
+                },
+                "owner": {
+                    "id": -1,
+                    "name": "GoGrid",
+                    "object": "customer"
+                },
+                "price": 0,
+                "state": {
+                    "description": "Image is available for adds",
+                    "id": 2,
+                    "name": "Available",
+                    "object": "option"
+                },
+                "type": {
+                    "description": "Web or Application Server",
+                    "id": 1,
+                    "name": "Web Server",
+                    "object": "option"
+                },
+                "updatedTime": 1257789046453
+            },
+            "ip": {
+                "id": 1659927,
+                "ip": "192.168.0.202",
+                "object": "ip",
+                "public": true,
+                "state": {
+                    "description": "IP is reserved or in use",
+                    "id": 2,
+                    "name": "Assigned",
+                    "object": "option"
+                },
+                "subnet": "192.168.0.192/255.255.255.240"
+            },
+            "isSandbox": false,
+            "name": "test1",
+            "object": "server",
+            "os": {
+                "description": "CentOS 5.3 (32-bit)",
+                "id": 16,
+                "name": "CentOS 5.3 (32-bit)",
+                "object": "option"
+            },
+            "ram": {
+                "description": "Server with 512MB RAM",
+                "id": 1,
+                "name": "512MB",
+                "object": "option"
+            },
+            "state": {
+                "description": "Server is in active state.",
+                "id": 1,
+                "name": "On",
+                "object": "option"
+            },
+            "type": {
+                "description": "Web or Application Server",
+                "id": 1,
+                "name": "Web Server",
+                "object": "option"
+            }
+        }
+    ],
+    "method": "/grid/server/power",
+    "status": "failure",
+    "summary": {
+        "numpages": 0,
+        "returned": 1,
+        "start": 0,
+        "total": 1
+    }
+}

Modified: incubator/libcloud/trunk/test/compute/test_gogrid.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/compute/test_gogrid.py?rev=1082389&r1=1082388&r2=1082389&view=diff
==============================================================================
--- incubator/libcloud/trunk/test/compute/test_gogrid.py (original)
+++ incubator/libcloud/trunk/test/compute/test_gogrid.py Thu Mar 17 03:07:08 2011
@@ -17,6 +17,7 @@ import sys
 import unittest
 import urlparse
 
+from libcloud.compute.base import NodeState, NodeLocation
 from libcloud.common.types import LibcloudError, InvalidCredsError
 from libcloud.compute.drivers.gogrid import GoGridNodeDriver, GoGridIpAddress
 from libcloud.compute.base import Node, NodeImage, NodeSize, NodeLocation
@@ -63,6 +64,17 @@ class GoGridTests(unittest.TestCase, Tes
         ret = self.driver.reboot_node(node)
         self.assertTrue(ret)
 
+    def test_reboot_node_not_successful(self):
+        GoGridMockHttp.type = 'FAIL'
+        node = Node(90967, None, None, None, None, self.driver)
+
+        try:
+            ret = self.driver.reboot_node(node)
+        except Exception:
+            pass
+        else:
+            self.fail('Exception was not thrown')
+
     def test_destroy_node(self):
         node = Node(90967, None, None, None, None, self.driver)
         ret = self.driver.destroy_node(node)
@@ -75,6 +87,15 @@ class GoGridTests(unittest.TestCase, Tes
         self.assertEqual(image.name, 'CentOS 5.3 (32-bit) w/ None')
         self.assertEqual(image.id, '1531')
 
+        location = NodeLocation(id='gogrid/GSI-939ef909-84b8-4a2f-ad56-02ccd7da05ff.img',
+                                name='test location', country='Slovenia',
+                                driver=self.driver)
+        images = self.driver.list_images(location=location)
+        image = images[0]
+        self.assertEqual(len(images), 4)
+        self.assertEqual(image.name, 'CentOS 5.3 (32-bit) w/ None')
+        self.assertEqual(image.id, '1531')
+
     def test_malformed_reply(self):
         GoGridMockHttp.type = 'FAIL'
         try:
@@ -164,6 +185,10 @@ class GoGridTests(unittest.TestCase, Tes
 
         self.assertEqual(len(expected_ips), 0)
 
+    def test_get_state_invalid(self):
+        state = self.driver._get_state('invalid')
+        self.assertEqual(state, NodeState.UNKNOWN)
+
 class GoGridMockHttp(MockHttp):
 
     fixtures = ComputeFileFixtures('gogrid')
@@ -199,6 +224,10 @@ class GoGridMockHttp(MockHttp):
         body = self.fixtures.load('server_power.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _api_grid_server_power_FAIL(self, method, url, body, headers):
+        body = self.fixtures.load('server_power_fail.json')
+        return (httplib.NOT_FOUND, body, {}, httplib.responses[httplib.OK])
+
     def _api_grid_server_add(self, method, url, body, headers):
         body = self.fixtures.load('server_add.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])