diff --git a/test/fixtures/gogrid/image_list.json b/test/fixtures/gogrid/image_list.json new file mode 100644 index 0000000..f111c3f --- /dev/null +++ b/test/fixtures/gogrid/image_list.json @@ -0,0 +1,180 @@ +{ + "list": [ + { + "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 + }, + { + "billingtokens": [ + { + "id": 47, + "name": "CentOS 5.3 64bit", + "price": 0 + } + ], + "description": "CentOS 5.3 (64-bit) w/ None", + "friendlyName": "CentOS 5.3 (64-bit) w/ None", + "id": 1532, + "isActive": true, + "isPublic": true, + "location": "gogrid/GSI-939ef909-84b8-4a2f-ad56-02ccd7da05ff.img", + "name": "centos5.3_64_base", + "object": "serverimage", + "os": { + "description": "CentOS 5.3 (64-bit)", + "id": 17, + "name": "CentOS 5.3 (64-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": 1257789076417 + }, + { + "billingtokens": [ + { + "id": 48, + "name": "RHEL 5.4 32bit", + "price": 0 + } + ], + "description": "RHEL 5.4 (32-bit) w/ None", + "friendlyName": "RHEL 5.4 (32-bit) w/ None", + "id": 1533, + "isActive": true, + "isPublic": true, + "location": "gogrid/GSI-4c88cb92-dd7b-4bb1-95b6-7cc93eb1d2aa.img", + "name": "rhel5.4_32_base", + "object": "serverimage", + "os": { + "description": "RHEL 5.4 (32-bit)", + "id": 18, + "name": "RHEL 5.4 (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": 1257789076417 + }, + { + "billingtokens": [ + { + "id": 49, + "name": "RHEL 5.4 64bit", + "price": 0 + } + ], + "description": "RHEL 5.4 (64-bit) w/ None", + "friendlyName": "RHEL 5.4 (64-bit) w/ None", + "id": 1534, + "isActive": true, + "isPublic": true, + "location": "gogrid/GSI-2bd8ddb3-cc53-4a76-8188-0dce7537a422.img", + "name": "rhel5.4_64_base", + "object": "serverimage", + "os": { + "description": "RHEL 5.4 (64-bit)", + "id": 19, + "name": "RHEL 5.4 (64-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": 1257789076417 + } + ], + "method": "/grid/image/list", + "status": "success", + "summary": { + "numpages": 0, + "returned": 59, + "start": 0, + "total": 59 + } +} diff --git a/test/fixtures/gogrid/ip_list.json b/test/fixtures/gogrid/ip_list.json new file mode 100644 index 0000000..35b5a11 --- /dev/null +++ b/test/fixtures/gogrid/ip_list.json @@ -0,0 +1,220 @@ +{ + "list": [ + { + "id": 1659917, + "ip": "192.168.0.192", + "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" + }, + { + "id": 1659918, + "ip": "192.168.0.193", + "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" + }, + { + "id": 1659919, + "ip": "192.168.0.194", + "object": "ip", + "public": true, + "state": { + "description": "IP is available to use", + "id": 1, + "name": "Unassigned", + "object": "option" + }, + "subnet": "192.168.0.192/255.255.255.240" + }, + { + "id": 1659920, + "ip": "192.168.0.195", + "object": "ip", + "public": true, + "state": { + "description": "IP is available to use", + "id": 1, + "name": "Unassigned", + "object": "option" + }, + "subnet": "192.168.0.192/255.255.255.240" + }, + { + "id": 1659921, + "ip": "192.168.0.196", + "object": "ip", + "public": true, + "state": { + "description": "IP is available to use", + "id": 1, + "name": "Unassigned", + "object": "option" + }, + "subnet": "192.168.0.192/255.255.255.240" + }, + { + "id": 1659922, + "ip": "192.168.0.197", + "object": "ip", + "public": true, + "state": { + "description": "IP is available to use", + "id": 1, + "name": "Unassigned", + "object": "option" + }, + "subnet": "192.168.0.192/255.255.255.240" + }, + { + "id": 1659923, + "ip": "192.168.0.198", + "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" + }, + { + "id": 1659924, + "ip": "192.168.0.199", + "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" + }, + { + "id": 1659925, + "ip": "192.168.0.200", + "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" + }, + { + "id": 1659926, + "ip": "192.168.0.201", + "object": "ip", + "public": true, + "state": { + "description": "IP is available to use", + "id": 1, + "name": "Unassigned", + "object": "option" + }, + "subnet": "192.168.0.192/255.255.255.240" + }, + { + "id": 1659927, + "ip": "192.168.0.202", + "object": "ip", + "public": true, + "state": { + "description": "IP is available to use", + "id": 1, + "name": "Unassigned", + "object": "option" + }, + "subnet": "192.168.0.192/255.255.255.240" + }, + { + "id": 1659928, + "ip": "192.168.0.203", + "object": "ip", + "public": true, + "state": { + "description": "IP is available to use", + "id": 1, + "name": "Unassigned", + "object": "option" + }, + "subnet": "192.168.0.192/255.255.255.240" + }, + { + "id": 1659929, + "ip": "192.168.0.204", + "object": "ip", + "public": true, + "state": { + "description": "IP is available to use", + "id": 1, + "name": "Unassigned", + "object": "option" + }, + "subnet": "192.168.0.192/255.255.255.240" + }, + { + "id": 1659930, + "ip": "192.168.0.205", + "object": "ip", + "public": true, + "state": { + "description": "IP is available to use", + "id": 1, + "name": "Unassigned", + "object": "option" + }, + "subnet": "192.168.0.192/255.255.255.240" + }, + { + "id": 1659931, + "ip": "192.168.0.206", + "object": "ip", + "public": true, + "state": { + "description": "IP is available to use", + "id": 1, + "name": "Unassigned", + "object": "option" + }, + "subnet": "192.168.0.192/255.255.255.240" + }, + { + "id": 1659932, + "ip": "192.168.0.207", + "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" + } + ], + "method": "/grid/ip/list", + "status": "success", + "summary": { + "numpages": 0, + "returned": 16, + "start": 0, + "total": 16 + } +} diff --git a/test/fixtures/gogrid/server_add.json b/test/fixtures/gogrid/server_add.json new file mode 100644 index 0000000..afb1164 --- /dev/null +++ b/test/fixtures/gogrid/server_add.json @@ -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/add", + "status": "success", + "summary": { + "numpages": 0, + "returned": 1, + "start": 0, + "total": 1 + } +} diff --git a/test/fixtures/gogrid/server_delete.json b/test/fixtures/gogrid/server_delete.json new file mode 100644 index 0000000..e63bce1 --- /dev/null +++ b/test/fixtures/gogrid/server_delete.json @@ -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/delete", + "status": "success", + "summary": { + "numpages": 0, + "returned": 1, + "start": 0, + "total": 1 + } +} diff --git a/test/fixtures/gogrid/server_list.json b/test/fixtures/gogrid/server_list.json new file mode 100644 index 0000000..df2ce95 --- /dev/null +++ b/test/fixtures/gogrid/server_list.json @@ -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/list", + "status": "success", + "summary": { + "numpages": 0, + "returned": 1, + "start": 0, + "total": 1 + } +} diff --git a/test/fixtures/gogrid/server_power.json b/test/fixtures/gogrid/server_power.json new file mode 100644 index 0000000..4534b58 --- /dev/null +++ b/test/fixtures/gogrid/server_power.json @@ -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": "success", + "summary": { + "numpages": 0, + "returned": 1, + "start": 0, + "total": 1 + } +} diff --git a/test/test_gogrid.py b/test/test_gogrid.py new file mode 100644 index 0000000..2b1b0fc --- /dev/null +++ b/test/test_gogrid.py @@ -0,0 +1,94 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import sys +import unittest + +try: + import json +except ImportError: + import simplejson as json + +from libcloud.drivers.gogrid import GoGridNodeDriver +from libcloud.base import Node, NodeImage, NodeSize + +from test import MockHttp, TestCaseMixin +from test.file_fixtures import FileFixtures + +import httplib + +class GoGridTests(unittest.TestCase, TestCaseMixin): + + def setUp(self): + GoGridNodeDriver.connectionCls.conn_classes = (None, GoGridMockHttp) + self.driver = GoGridNodeDriver("foo", "bar") + + def test_create_node(self): + image = NodeImage(1531, '', self.driver) + size = NodeSize('512Mb', '', '', '', '', '', driver=self.driver) + + node = self.driver.create_node(name='foo', image=image, size=size) + self.assertEqual(node.id, 90967) + + def test_list_nodes(self): + node = self.driver.list_nodes()[0] + self.assertEqual(node.id, 90967) + + def test_reboot_node(self): + node = Node(90967, None, None, None, None, self.driver) + ret = self.driver.reboot_node(node) + self.assertTrue(ret) + + def test_destroy_node(self): + node = Node(90967, None, None, None, None, self.driver) + ret = self.driver.destroy_node(node) + self.assertTrue(ret) + + def test_list_images(self): + images = self.driver.list_images() + image = images[0] + self.assertEqual(len(images), 4) + self.assertEqual(image.name, 'CentOS 5.3 (32-bit) w/ None') + self.assertEqual(image.id, 1531) + +class GoGridMockHttp(MockHttp): + + fixtures = FileFixtures('gogrid') + + def _api_grid_image_list(self, method, url, body, headers): + body = self.fixtures.load('image_list.json') + return (httplib.OK, body, {}, httplib.responses[httplib.OK]) + + def _api_grid_server_list(self, method, url, body, headers): + body = self.fixtures.load('server_list.json') + return (httplib.OK, body, {}, httplib.responses[httplib.OK]) + + def _api_grid_ip_list(self, method, url, body, headers): + body = self.fixtures.load('ip_list.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]) + + 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]) + + 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]) + +if __name__ == '__main__': + sys.exit(unittest.main())