summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-01-12 17:53:54 +0000
committerGerrit Code Review <review@openstack.org>2012-01-12 17:53:54 +0000
commit395f2b6796d2d256aa5d5cbe58e392a808e86e61 (patch)
treed46a725ab3cc9613506937fe6d33ddb3747ac995 /nova/tests
parent475691a4bd5795feb50b5c9ccfe98e6487390e58 (diff)
parenta7c0632600cc874b72c7e60efb7e16d6c8a2e733 (diff)
Merge "Add 'os-networks' extension"
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/v2/contrib/test_networks.py137
-rw-r--r--nova/tests/api/openstack/v2/test_extensions.py1
-rw-r--r--nova/tests/fake_network.py6
-rw-r--r--nova/tests/test_network.py61
4 files changed, 205 insertions, 0 deletions
diff --git a/nova/tests/api/openstack/v2/contrib/test_networks.py b/nova/tests/api/openstack/v2/contrib/test_networks.py
new file mode 100644
index 000000000..04bd82e2c
--- /dev/null
+++ b/nova/tests/api/openstack/v2/contrib/test_networks.py
@@ -0,0 +1,137 @@
+# Copyright 2011 Grid Dynamics
+# Copyright 2011 OpenStack LLC.
+# All Rights Reserved.
+#
+# Licensed 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 copy
+
+import webob
+
+from nova.api.openstack.v2.contrib import networks
+from nova import context
+from nova import exception
+from nova import test
+from nova.tests.api.openstack import fakes
+
+
+FAKE_NETWORKS = [
+ {
+ 'bridge': 'br100', 'vpn_public_port': 1000,
+ 'dhcp_start': '10.0.0.3', 'bridge_interface': 'eth0',
+ 'updated_at': '2011-08-16 09:26:13.048257', 'id': 1,
+ 'cidr_v6': None, 'deleted_at': None,
+ 'gateway': '10.0.0.1', 'label': 'mynet_0',
+ 'project_id': '1234',
+ 'vpn_private_address': '10.0.0.2', 'deleted': False,
+ 'vlan': 100, 'broadcast': '10.0.0.7',
+ 'netmask': '255.255.255.248', 'injected': False,
+ 'cidr': '10.0.0.0/29',
+ 'vpn_public_address': '127.0.0.1', 'multi_host': False,
+ 'dns1': None, 'host': 'nsokolov-desktop',
+ 'gateway_v6': None, 'netmask_v6': None,
+ 'created_at': '2011-08-15 06:19:19.387525',
+ },
+ {
+ 'bridge': 'br101', 'vpn_public_port': 1001,
+ 'dhcp_start': '10.0.0.11', 'bridge_interface': 'eth0',
+ 'updated_at': None, 'id': 2, 'cidr_v6': None,
+ 'deleted_at': None, 'gateway': '10.0.0.9',
+ 'label': 'mynet_1', 'project_id': None,
+ 'vpn_private_address': '10.0.0.10', 'deleted': False,
+ 'vlan': 101, 'broadcast': '10.0.0.15',
+ 'netmask': '255.255.255.248', 'injected': False,
+ 'cidr': '10.0.0.10/29', 'vpn_public_address': None,
+ 'multi_host': False, 'dns1': None, 'host': None,
+ 'gateway_v6': None, 'netmask_v6': None,
+ 'created_at': '2011-08-15 06:19:19.885495',
+ },
+]
+
+
+class FakeNetworkAPI(object):
+
+ def __init__(self):
+ self.networks = copy.deepcopy(FAKE_NETWORKS)
+
+ def delete(self, context, network_id):
+ for i, network in enumerate(self.networks):
+ if network['id'] == network_id:
+ del self.networks[0]
+ return True
+ raise exception.NetworkNotFound()
+
+ #NOTE(bcwaldon): this does nothing other than check for existance
+ def disassociate(self, context, network_id):
+ for i, network in enumerate(self.networks):
+ if network['id'] == network_id:
+ return True
+ raise exception.NetworkNotFound()
+
+ def get_all(self, context):
+ return self.networks
+
+ def get(self, context, network_id):
+ for network in self.networks:
+ if network['id'] == network_id:
+ return network
+ raise exception.NetworkNotFound()
+
+
+class NetworksTest(test.TestCase):
+
+ def setUp(self):
+ super(NetworksTest, self).setUp()
+ self.flags(allow_admin_api=True)
+ self.fake_network_api = FakeNetworkAPI()
+ self.controller = networks.NetworkController(self.fake_network_api)
+ fakes.stub_out_networking(self.stubs)
+ fakes.stub_out_rate_limiting(self.stubs)
+ self.context = context.RequestContext('user', '1234', is_admin=True)
+
+ def test_network_list_all(self):
+ req = fakes.HTTPRequest.blank('/v2/1234/os-networks')
+ res_dict = self.controller.index(req)
+ self.assertEquals(res_dict, {'networks': FAKE_NETWORKS})
+
+ def test_network_disassociate(self):
+ req = fakes.HTTPRequest.blank('/v2/1234/os-networks/1/action')
+ res = self.controller.action(req, 1, {'disassociate': None})
+ self.assertEqual(res.status_int, 202)
+
+ def test_network_disassociate_not_found(self):
+ req = fakes.HTTPRequest.blank('/v2/1234/os-networks/100/action')
+ self.assertRaises(webob.exc.HTTPNotFound,
+ self.controller.action,
+ req, 100, {'disassociate': None})
+
+ def test_network_get(self):
+ req = fakes.HTTPRequest.blank('/v2/1234/os-networks/1')
+ res_dict = self.controller.show(req, 1)
+ expected = {'network': FAKE_NETWORKS[0]}
+ self.assertEqual(res_dict, expected)
+
+ def test_network_get_not_found(self):
+ req = fakes.HTTPRequest.blank('/v2/1234/os-networks/100')
+ self.assertRaises(webob.exc.HTTPNotFound,
+ self.controller.show, req, 100)
+
+ def test_network_delete(self):
+ req = fakes.HTTPRequest.blank('/v2/1234/os-networks/1')
+ res = self.controller.delete(req, 1)
+ self.assertEqual(res.status_int, 202)
+
+ def test_network_delete_not_found(self):
+ req = fakes.HTTPRequest.blank('/v2/1234/os-networks/100')
+ self.assertRaises(webob.exc.HTTPNotFound,
+ self.controller.delete, req, 100)
diff --git a/nova/tests/api/openstack/v2/test_extensions.py b/nova/tests/api/openstack/v2/test_extensions.py
index 473892692..f2a49c3ed 100644
--- a/nova/tests/api/openstack/v2/test_extensions.py
+++ b/nova/tests/api/openstack/v2/test_extensions.py
@@ -128,6 +128,7 @@ class ExtensionControllerTest(ExtensionTestCase):
"Volumes",
"VolumeTypes",
"Zones",
+ "Networks",
]
self.ext_list.sort()
diff --git a/nova/tests/fake_network.py b/nova/tests/fake_network.py
index 03c12ed37..07f07f461 100644
--- a/nova/tests/fake_network.py
+++ b/nova/tests/fake_network.py
@@ -89,6 +89,12 @@ class FakeNetworkManager(network_manager.NetworkManager):
def network_get_all(self, context):
raise exception.NoNetworksFound()
+ def network_get_all_by_uuids(self, context):
+ raise exception.NoNetworksFound()
+
+ def network_disassociate(self, context, network_id):
+ return True
+
def virtual_interface_get_all(self, context):
floats = [{'address': '172.16.1.1'},
{'address': '172.16.1.2'},
diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py
index c05be6a5a..bf4c60427 100644
--- a/nova/tests/test_network.py
+++ b/nova/tests/test_network.py
@@ -1101,6 +1101,67 @@ class CommonNetworkTestCase(test.TestCase):
self.assertEqual(len(res), 1)
self.assertEqual(res[0]['instance_id'], _vifs[2]['instance_id'])
+ def test_get_network(self):
+ manager = fake_network.FakeNetworkManager()
+ fake_context = context.RequestContext('user', 'project')
+ self.mox.StubOutWithMock(manager.db, 'network_get_all_by_uuids')
+ manager.db.network_get_all_by_uuids(mox.IgnoreArg(),
+ mox.IgnoreArg()).\
+ AndReturn(networks)
+ self.mox.ReplayAll()
+ uuid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
+ network = manager.get_network(fake_context, uuid)
+ self.assertEqual(network['uuid'], uuid)
+
+ def test_get_network_not_found(self):
+ manager = fake_network.FakeNetworkManager()
+ fake_context = context.RequestContext('user', 'project')
+ self.mox.StubOutWithMock(manager.db, 'network_get_all_by_uuids')
+ manager.db.network_get_all_by_uuids(mox.IgnoreArg(),
+ mox.IgnoreArg()).\
+ AndReturn([])
+ self.mox.ReplayAll()
+ uuid = 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee'
+ self.assertRaises(exception.NetworkNotFound,
+ manager.get_network, fake_context, uuid)
+
+ def test_get_all_networks(self):
+ manager = fake_network.FakeNetworkManager()
+ fake_context = context.RequestContext('user', 'project')
+ self.mox.StubOutWithMock(manager.db, 'network_get_all')
+ manager.db.network_get_all(mox.IgnoreArg()).\
+ AndReturn(networks)
+ self.mox.ReplayAll()
+ output = manager.get_all_networks(fake_context)
+ self.assertEqual(len(networks), 2)
+ self.assertEqual(output[0]['uuid'],
+ 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa')
+ self.assertEqual(output[1]['uuid'],
+ 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb')
+
+ def test_disassociate_network(self):
+ manager = fake_network.FakeNetworkManager()
+ fake_context = context.RequestContext('user', 'project')
+ self.mox.StubOutWithMock(manager.db, 'network_get_all_by_uuids')
+ manager.db.network_get_all_by_uuids(mox.IgnoreArg(),
+ mox.IgnoreArg()).\
+ AndReturn(networks)
+ self.mox.ReplayAll()
+ uuid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
+ manager.disassociate_network(fake_context, uuid)
+
+ def test_disassociate_network_not_found(self):
+ manager = fake_network.FakeNetworkManager()
+ fake_context = context.RequestContext('user', 'project')
+ self.mox.StubOutWithMock(manager.db, 'network_get_all_by_uuids')
+ manager.db.network_get_all_by_uuids(mox.IgnoreArg(),
+ mox.IgnoreArg()).\
+ AndReturn([])
+ self.mox.ReplayAll()
+ uuid = 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee'
+ self.assertRaises(exception.NetworkNotFound,
+ manager.disassociate_network, fake_context, uuid)
+
class TestRPCFixedManager(network_manager.RPCAllocateFixedIP,
network_manager.NetworkManager):