diff options
| author | Vishvananda Ishaya <vishvananda@gmail.com> | 2012-04-09 22:11:10 -0700 |
|---|---|---|
| committer | Vishvananda Ishaya <vishvananda@gmail.com> | 2012-04-10 13:31:33 -0700 |
| commit | a0e37c6d29c57cde416b047cd38c93b6a9588005 (patch) | |
| tree | a714cd2a1ccff01191395c91c99a619cf092a7cc /nova/tests | |
| parent | 7a1957dfe91011510d34b849fadbb973b53d0414 (diff) | |
Fix errors in os-networks extension
* Makes sure the uuid is returned as id if it exists
* Simplifies db get for manager.get_networks
* Removes direct db access from manager which was breaking test
* Updates tests to verify the new logic
* Makes sure Remote NotFounds are turned into 404s
(The RemoteError blocks can be removed once
https://review.openstack.org/5749 lands)
* Fixes bug 977712
* Fixes bug 977723
Change-Id: I6aa815960782c7ae5165aeebd83bdaaa62c19b04
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_networks.py | 34 | ||||
| -rw-r--r-- | nova/tests/fake_network.py | 3 | ||||
| -rw-r--r-- | nova/tests/network/test_manager.py | 28 |
3 files changed, 39 insertions, 26 deletions
diff --git a/nova/tests/api/openstack/compute/contrib/test_networks.py b/nova/tests/api/openstack/compute/contrib/test_networks.py index 78c8ad374..c0580c6a7 100644 --- a/nova/tests/api/openstack/compute/contrib/test_networks.py +++ b/nova/tests/api/openstack/compute/contrib/test_networks.py @@ -20,6 +20,7 @@ import webob from nova.api.openstack.compute.contrib import networks from nova import exception +from nova.rpc import common from nova import test from nova.tests.api.openstack import fakes @@ -28,7 +29,8 @@ 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, + 'updated_at': '2011-08-16 09:26:13.048257', + 'id': 1, 'uuid': '20c8acc0-f747-4d71-a389-46d078ebf047', 'cidr_v6': None, 'deleted_at': None, 'gateway': '10.0.0.1', 'label': 'mynet_0', 'project_id': '1234', @@ -68,21 +70,21 @@ class FakeNetworkAPI(object): if network['id'] == network_id: del self.networks[0] return True - raise exception.NetworkNotFound() + raise exception.NetworkNotFoundForUUID() #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: + if network.get('uuid') == network_id: return True - raise exception.NetworkNotFound() + raise common.RemoteError(type(exception.NetworkNotFound()).__name__) def get_all(self, context): return self.networks def get(self, context, network_id): for network in self.networks: - if network['id'] == network_id: + if network.get('uuid') == network_id: return network raise exception.NetworkNotFound() @@ -99,11 +101,15 @@ class NetworksTest(test.TestCase): 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}) + expected = copy.deepcopy(FAKE_NETWORKS) + expected[0]['id'] = expected[0]['uuid'] + del expected[0]['uuid'] + self.assertEquals(res_dict, {'networks': expected}) def test_network_disassociate(self): - req = fakes.HTTPRequest.blank('/v2/1234/os-networks/1/action') - res = self.controller.action(req, 1, {'disassociate': None}) + uuid = FAKE_NETWORKS[0]['uuid'] + req = fakes.HTTPRequest.blank('/v2/1234/os-networks/%s/action' % uuid) + res = self.controller.action(req, uuid, {'disassociate': None}) self.assertEqual(res.status_int, 202) def test_network_disassociate_not_found(self): @@ -113,9 +119,12 @@ class NetworksTest(test.TestCase): 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]} + uuid = FAKE_NETWORKS[0]['uuid'] + req = fakes.HTTPRequest.blank('/v2/1234/os-networks/%s' % uuid) + res_dict = self.controller.show(req, uuid) + expected = {'network': copy.deepcopy(FAKE_NETWORKS[0])} + expected['network']['id'] = expected['network']['uuid'] + del expected['network']['uuid'] self.assertEqual(res_dict, expected) def test_network_get_not_found(self): @@ -124,7 +133,8 @@ class NetworksTest(test.TestCase): self.controller.show, req, 100) def test_network_delete(self): - req = fakes.HTTPRequest.blank('/v2/1234/os-networks/1') + uuid = FAKE_NETWORKS[0]['uuid'] + req = fakes.HTTPRequest.blank('/v2/1234/os-networks/%s' % uuid) res = self.controller.delete(req, 1) self.assertEqual(res.status_int, 202) diff --git a/nova/tests/fake_network.py b/nova/tests/fake_network.py index 9d0a5b971..03ad472b7 100644 --- a/nova/tests/fake_network.py +++ b/nova/tests/fake_network.py @@ -120,6 +120,9 @@ class FakeNetworkManager(network_manager.NetworkManager): def network_get(self, context, network_id): return {'cidr_v6': '2001:db8:69:%x::/64' % network_id} + def network_get_by_uuid(self, context, network_uuid): + raise exception.NetworkNotFoundForUUID() + def network_get_all(self, context): raise exception.NoNetworksFound() diff --git a/nova/tests/network/test_manager.py b/nova/tests/network/test_manager.py index 50d49b132..3b33296b6 100644 --- a/nova/tests/network/test_manager.py +++ b/nova/tests/network/test_manager.py @@ -1266,10 +1266,9 @@ class CommonNetworkTestCase(test.TestCase): 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.StubOutWithMock(manager.db, 'network_get_by_uuid') + manager.db.network_get_by_uuid(mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn(networks[0]) self.mox.ReplayAll() uuid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' network = manager.get_network(fake_context, uuid) @@ -1278,9 +1277,10 @@ class CommonNetworkTestCase(test.TestCase): 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.StubOutWithMock(manager.db, 'network_get_by_uuid') + manager.db.network_get_by_uuid( + mox.IgnoreArg(), + mox.IgnoreArg()).AndRaise(exception.NetworkNotFoundForUUID) self.mox.ReplayAll() uuid = 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee' self.assertRaises(exception.NetworkNotFound, @@ -1302,10 +1302,9 @@ class CommonNetworkTestCase(test.TestCase): 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.StubOutWithMock(manager.db, 'network_get_by_uuid') + manager.db.network_get_by_uuid(mox.IgnoreArg(), + mox.IgnoreArg()).AndReturn(networks[0]) self.mox.ReplayAll() uuid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' manager.disassociate_network(fake_context, uuid) @@ -1313,9 +1312,10 @@ class CommonNetworkTestCase(test.TestCase): 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.StubOutWithMock(manager.db, 'network_get_by_uuid') + manager.db.network_get_by_uuid( + mox.IgnoreArg(), + mox.IgnoreArg()).AndRaise(exception.NetworkNotFoundForUUID) self.mox.ReplayAll() uuid = 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee' self.assertRaises(exception.NetworkNotFound, |
