libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rbogorods...@apache.org
Subject svn commit: r1095180 [2/2] - in /incubator/libcloud/trunk: ./ libcloud/common/ libcloud/compute/drivers/ libcloud/resource/ libcloud/resource/lb/ libcloud/resource/lb/drivers/ test/ test/compute/ test/resource/ test/resource/fixtures/ test/resource/fix...
Date Tue, 19 Apr 2011 19:49:29 GMT
Added: incubator/libcloud/trunk/test/resource/lb/test_gogrid.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/resource/lb/test_gogrid.py?rev=1095180&view=auto
==============================================================================
--- incubator/libcloud/trunk/test/resource/lb/test_gogrid.py (added)
+++ incubator/libcloud/trunk/test/resource/lb/test_gogrid.py Tue Apr 19 19:49:28 2011
@@ -0,0 +1,107 @@
+import httplib
+import os.path
+import sys
+import unittest
+
+from libcloud.resource.lb.base import LB, LBNode
+from libcloud.resource.lb.drivers.gogrid import GoGridLBDriver
+
+from test import MockHttp, MockRawResponse
+from test.file_fixtures import ResourceFileFixtures
+
+class GoGridTests(unittest.TestCase):
+
+    def setUp(self):
+        GoGridLBDriver.connectionCls.conn_classes = (None,
+                GoGridLBMockHttp)
+        GoGridLBMockHttp.type = None
+        self.driver = GoGridLBDriver('user', 'key')
+
+    def test_list_balancers(self):
+        balancers = self.driver.list_balancers()
+
+        self.assertEquals(len(balancers), 2)
+        self.assertEquals(balancers[0].name, "foo")
+        self.assertEquals(balancers[0].id, "23517")
+        self.assertEquals(balancers[1].name, "bar")
+        self.assertEquals(balancers[1].id, "23526")
+
+    def test_create_balancer(self):
+        balancer = self.driver.create_balancer(name='test2',
+                port=80,
+                nodes=(LBNode(None, '10.1.0.10', 80),
+                    LBNode(None, '10.1.0.11', 80))
+                )
+
+        self.assertEquals(balancer.name, 'test2')
+        self.assertEquals(balancer.id, '123')
+
+    def test_destroy_balancer(self):
+        balancer = self.driver.list_balancers()[0]
+
+        ret = self.driver.destroy_balancer(balancer)
+        self.assertTrue(ret)
+
+    def test_balancer_detail(self):
+        balancer = self.driver.balancer_detail(balancer_id='23530')
+
+        self.assertEquals(balancer.name, 'test2')
+        self.assertEquals(balancer.id, '23530')
+
+    def test_balancer_list_nodes(self):
+        balancer = self.driver.balancer_detail(balancer_id='23530')
+        nodes = balancer.list_nodes()
+
+        expected_nodes = set([u'10.0.0.78:80', u'10.0.0.77:80',
+            u'10.0.0.76:80'])
+
+        self.assertEquals(len(nodes), 3)
+        self.assertEquals(expected_nodes,
+                set(["%s:%s" % (node.ip, node.port) for node in nodes]))
+
+    def test_balancer_attach_node(self):
+        balancer = LB(23530, None, None, None, None, None)
+        node = self.driver.balancer_attach_node(balancer,
+                ip='10.0.0.75', port='80')
+
+        self.assertEquals(node.ip, '10.0.0.75')
+        self.assertEquals(node.port, 80)
+
+    def test_balancer_detach_node(self):
+        balancer = LB(23530, None, None, None, None, None)
+        node = self.driver.balancer_list_nodes(balancer)[0]
+
+        ret = self.driver.balancer_detach_node(balancer, node)
+
+        self.assertTrue(ret)
+
+class GoGridLBMockHttp(MockHttp):
+    fixtures = ResourceFileFixtures(os.path.join('lb', 'gogrid'))
+
+    def _api_grid_loadbalancer_list(self, method, url, body, headers):
+        body = self.fixtures.load('loadbalancer_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_loadbalancer_add(self, method, url, body, headers):
+        body = self.fixtures.load('loadbalancer_add.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _api_grid_loadbalancer_delete(self, method, url, body, headers):
+        body = self.fixtures.load('loadbalancer_add.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _api_grid_loadbalancer_get(self, method, url, body, headers):
+        body = self.fixtures.load('loadbalancer_get.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _api_grid_loadbalancer_edit(self, method, url, body, headers):
+        body = self.fixtures.load('loadbalancer_edit.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+
+if __name__ == "__main__":
+    sys.exit(unittest.main())

Added: incubator/libcloud/trunk/test/resource/lb/test_rackspace.py
URL: http://svn.apache.org/viewvc/incubator/libcloud/trunk/test/resource/lb/test_rackspace.py?rev=1095180&view=auto
==============================================================================
--- incubator/libcloud/trunk/test/resource/lb/test_rackspace.py (added)
+++ incubator/libcloud/trunk/test/resource/lb/test_rackspace.py Tue Apr 19 19:49:28 2011
@@ -0,0 +1,124 @@
+import httplib
+import os.path
+import sys
+import unittest
+
+from libcloud.resource.lb.base import LB, LBNode
+from libcloud.resource.lb.drivers.rackspace import RackspaceLBDriver
+
+from test import MockHttp, MockRawResponse
+from test.file_fixtures import ResourceFileFixtures
+
+class RackspaceLBTests(unittest.TestCase):
+
+    def setUp(self):
+        RackspaceLBDriver.connectionCls.conn_classes = (None,
+                RackspaceLBMockHttp)
+        RackspaceLBMockHttp.type = None
+        self.driver = RackspaceLBDriver('user', 'key')
+
+    def test_list_balancers(self):
+        balancers = self.driver.list_balancers()
+
+        self.assertEquals(len(balancers), 2)
+        self.assertEquals(balancers[0].name, "test0")
+        self.assertEquals(balancers[0].id, "8155")
+        self.assertEquals(balancers[1].name, "test1")
+        self.assertEquals(balancers[1].id, "8156")
+
+    def test_create_balancer(self):
+        balancer = self.driver.create_balancer(name='test2',
+                port=80,
+                nodes=(LBNode(None, '10.1.0.10', 80),
+                    LBNode(None, '10.1.0.11', 80))
+                )
+
+        self.assertEquals(balancer.name, 'test2')
+        self.assertEquals(balancer.id, '8290')
+
+    def test_destroy_balancer(self):
+        balancer = self.driver.list_balancers()[0]
+
+        ret = self.driver.destroy_balancer(balancer)
+        self.assertTrue(ret)
+
+    def test_balancer_detail(self):
+        balancer = self.driver.balancer_detail(balancer_id='8290')
+
+        self.assertEquals(balancer.name, 'test2')
+        self.assertEquals(balancer.id, '8290')
+
+    def test_balancer_list_nodes(self):
+        balancer = self.driver.balancer_detail(balancer_id='8290')
+        nodes = balancer.list_nodes()
+
+        self.assertEquals(len(nodes), 2)
+        self.assertEquals(set(['10.1.0.10:80', '10.1.0.11:80']),
+                set(["%s:%s" % (node.ip, node.port) for node in nodes]))
+
+    def test_balancer_attach_node(self):
+        balancer = self.driver.balancer_detail(balancer_id='8290')
+        node = balancer.attach_node(ip='10.1.0.12', port='80')
+
+        self.assertEquals(node.ip, '10.1.0.12')
+        self.assertEquals(node.port, 80)
+
+    def test_balancer_detach_node(self):
+        balancer = self.driver.balancer_detail(balancer_id='8290')
+        node = balancer.list_nodes()[0]
+
+        ret = balancer.detach_node(node)
+
+        self.assertTrue(ret)
+
+class RackspaceLBMockHttp(MockHttp):
+    fixtures = ResourceFileFixtures(os.path.join('lb', 'rackspace'))
+
+    def _v1_0(self, method, url, body, headers):
+        headers = {'x-server-management-url': 'https://servers.api.rackspacecloud.com/v1.0/slug',
+                   'x-auth-token': 'FE011C19-CF86-4F87-BE5D-9229145D7A06',
+                   'x-cdn-management-url': 'https://cdn.clouddrive.com/v1/MossoCloudFS_FE011C19-CF86-4F87-BE5D-9229145D7A06',
+                   'x-storage-token': 'FE011C19-CF86-4F87-BE5D-9229145D7A06',
+                   'x-storage-url': 'https://storage4.clouddrive.com/v1/MossoCloudFS_FE011C19-CF86-4F87-BE5D-9229145D7A06'}
+        return (httplib.NO_CONTENT, "", headers, httplib.responses[httplib.NO_CONTENT])
+
+    def _v1_0_slug_loadbalancers(self, method, url, body, headers):
+        if method == "GET":
+            body = self.fixtures.load('v1_slug_loadbalancers.json')
+            return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+        elif method == "POST":
+            body = self.fixtures.load('v1_slug_loadbalancers_post.json')
+            return (httplib.ACCEPTED, body, {},
+                    httplib.responses[httplib.ACCEPTED])
+
+        raise NotImplementedError
+
+    def _v1_0_slug_loadbalancers_8155(self, method, url, body, headers):
+        if method == "DELETE":
+            return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED])
+
+        raise NotImplementedError
+
+    def _v1_0_slug_loadbalancers_8290(self, method, url, body, headers):
+        body = self.fixtures.load('v1_slug_loadbalancers_8290.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
+    def _v1_0_slug_loadbalancers_8290_nodes(self, method, url, body, headers):
+        if method == "GET":
+            body = self.fixtures.load('v1_slug_loadbalancers_8290_nodes.json')
+            return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+        elif method == "POST":
+            body = self.fixtures.load('v1_slug_loadbalancers_8290_nodes_post.json')
+            return (httplib.ACCEPTED, body, {},
+                    httplib.responses[httplib.ACCEPTED])
+
+        raise NotImplementedError
+
+    def _v1_0_slug_loadbalancers_8290_nodes_30944(self, method, url, body, headers):
+        if method == "DELETE":
+            return (httplib.ACCEPTED, "", {}, httplib.responses[httplib.ACCEPTED])
+
+        raise NotImplementedError
+
+if __name__ == "__main__":
+    sys.exit(unittest.main())



Mime
View raw message