Add tests for OpenStack and Rackspace networks functionality.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/0530b792 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/0530b792 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/0530b792 Branch: refs/heads/trunk Commit: 0530b792dfcb8b97345587ea3d1a39dd7419ec52 Parents: d2a71cb Author: Tomaz Muraus <[email protected]> Authored: Wed Oct 9 23:40:37 2013 +0200 Committer: Tomaz Muraus <[email protected]> Committed: Wed Oct 9 23:46:44 2013 +0200 ---------------------------------------------------------------------- CHANGES | 4 +++ .../fixtures/openstack_v1.1/_os_networks.json | 1 + .../openstack_v1.1/_os_networks_POST.json | 1 + libcloud/test/compute/test_openstack.py | 32 ++++++++++++++++++++ libcloud/test/compute/test_rackspace.py | 14 +++++++++ 5 files changed, 52 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/0530b792/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 40f18b0..2f90ca1 100644 --- a/CHANGES +++ b/CHANGES @@ -93,6 +93,10 @@ Changes with Apache Libcloud in development both, OpenStack and Rackspace driver. (LIBCLOUD-368) [Tomaz Muraus] + - Add tests for networking functionality in the OpenStack and Rackspace + driver. + [Tomaz Muraus] + *) Storage - Allow users to filter objects starting with a prefix by passing ex_prefix http://git-wip-us.apache.org/repos/asf/libcloud/blob/0530b792/libcloud/test/compute/fixtures/openstack_v1.1/_os_networks.json ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_os_networks.json b/libcloud/test/compute/fixtures/openstack_v1.1/_os_networks.json new file mode 100644 index 0000000..26fb34c --- /dev/null +++ b/libcloud/test/compute/fixtures/openstack_v1.1/_os_networks.json @@ -0,0 +1 @@ +{"networks": [{"cidr": "127.0.0.0/24", "id": "f13e5051-feea-416b-827a-1a0acc2dad14", "label": "test1"}, {"id": "00000000-0000-0000-0000-000000000000", "label": "public"}, {"id": "11111111-1111-1111-1111-111111111111", "label": "private"}]} http://git-wip-us.apache.org/repos/asf/libcloud/blob/0530b792/libcloud/test/compute/fixtures/openstack_v1.1/_os_networks_POST.json ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/openstack_v1.1/_os_networks_POST.json b/libcloud/test/compute/fixtures/openstack_v1.1/_os_networks_POST.json new file mode 100644 index 0000000..7b916da --- /dev/null +++ b/libcloud/test/compute/fixtures/openstack_v1.1/_os_networks_POST.json @@ -0,0 +1 @@ +{"network": {"cidr": "127.0.0.0/24", "id": "ef2143d4-2353-4e3c-b577-0de372411f42", "label": "test1"}} http://git-wip-us.apache.org/repos/asf/libcloud/blob/0530b792/libcloud/test/compute/test_openstack.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_openstack.py b/libcloud/test/compute/test_openstack.py index f1a6385..a35baea 100644 --- a/libcloud/test/compute/test_openstack.py +++ b/libcloud/test/compute/test_openstack.py @@ -1267,6 +1267,24 @@ class OpenStack_1_1_Tests(unittest.TestCase, TestCaseMixin): self.assertEqual(pool.delete_floating_ip.call_count, 1) + def test_ex_list_network(self): + networks = self.driver.ex_list_networks() + network = networks[0] + + self.assertEqual(len(networks), 3) + self.assertEqual(network.name, 'test1') + self.assertEqual(network.cidr, '127.0.0.0/24') + + def test_ex_create_network(self): + network = self.driver.ex_create_network(name='test1', + cidr='127.0.0.0/24') + self.assertEqual(network.name, 'test1') + self.assertEqual(network.cidr, '127.0.0.0/24') + + def test_ex_delete_network(self): + network = self.driver.ex_list_networks()[0] + self.assertTrue(self.driver.ex_delete_network(network=network)) + class OpenStack_1_1_FactoryMethodTests(OpenStack_1_1_Tests): should_list_locations = False @@ -1555,6 +1573,20 @@ class OpenStack_1_1_MockHttp(MockHttpTestCase): return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) + def _v1_1_slug_os_networks(self, method, url, body, headers): + if method == 'GET': + body = self.fixtures.load('_os_networks.json') + return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) + elif method == 'POST': + body = self.fixtures.load('_os_networks_POST.json') + return (httplib.ACCEPTED, body, self.json_content_headers, httplib.responses[httplib.OK]) + raise NotImplementedError() + + def _v1_1_slug_os_networks_f13e5051_feea_416b_827a_1a0acc2dad14(self, method, url, body, headers): + if method == 'DELETE': + body = '' + return (httplib.ACCEPTED, body, self.json_content_headers, httplib.responses[httplib.OK]) + raise NotImplementedError() # This exists because the nova compute url in devstack has v2 in there but the v1.1 fixtures # work fine. http://git-wip-us.apache.org/repos/asf/libcloud/blob/0530b792/libcloud/test/compute/test_rackspace.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_rackspace.py b/libcloud/test/compute/test_rackspace.py index 601a529..0f39ff5 100644 --- a/libcloud/test/compute/test_rackspace.py +++ b/libcloud/test/compute/test_rackspace.py @@ -85,6 +85,20 @@ class RackspaceNovaMockHttp(OpenStack_1_1_MockHttp): new_name = name.replace('_v1_1_slug_', '_v2_1337_') setattr(self, new_name, method_type(method, self, RackspaceNovaMockHttp)) + def _v2_1337_os_networksv2(self, method, url, body, headers): + if method == 'GET': + body = self.fixtures.load('_os_networks.json') + return (httplib.OK, body, self.json_content_headers, httplib.responses[httplib.OK]) + elif method == 'POST': + body = self.fixtures.load('_os_networks_POST.json') + return (httplib.ACCEPTED, body, self.json_content_headers, httplib.responses[httplib.OK]) + raise NotImplementedError() + + def _v2_1337_os_networksv2_f13e5051_feea_416b_827a_1a0acc2dad14(self, method, url, body, headers): + if method == 'DELETE': + body = '' + return (httplib.ACCEPTED, body, self.json_content_headers, httplib.responses[httplib.OK]) + raise NotImplementedError() class RackspaceNovaLonMockHttp(RackspaceNovaMockHttp):
