diff options
| author | Giampaolo Lauria <lauria@us.ibm.com> | 2013-03-12 16:10:08 -0400 |
|---|---|---|
| committer | Giampaolo Lauria <lauria@us.ibm.com> | 2013-03-14 16:24:47 -0400 |
| commit | 3971c4ee489fb3b059448eac173d76a87e202e66 (patch) | |
| tree | 7d6dbfce1670d5189736d01dd72b8c7c3a7267eb | |
| parent | 46683d34db0045a45f8d16e2c255282f289c8901 (diff) | |
| download | nova-3971c4ee489fb3b059448eac173d76a87e202e66.tar.gz nova-3971c4ee489fb3b059448eac173d76a87e202e66.tar.xz nova-3971c4ee489fb3b059448eac173d76a87e202e66.zip | |
Fix exception message in Networks API extension
Raise exception indicating VLAN is disabled when
trying to associate a network w/ a tenant in cases where
VLAN is not the network manager
Added unit test case
Fixes bug 1075790
Change-Id: I3dcac09fbf06d9f64b18cc52d0b069dc9c0a7370
| -rw-r--r-- | nova/api/openstack/compute/contrib/os_networks.py | 3 | ||||
| -rw-r--r-- | nova/network/manager.py | 3 | ||||
| -rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_networks.py | 13 |
3 files changed, 19 insertions, 0 deletions
diff --git a/nova/api/openstack/compute/contrib/os_networks.py b/nova/api/openstack/compute/contrib/os_networks.py index c6268f277..2cea0e081 100644 --- a/nova/api/openstack/compute/contrib/os_networks.py +++ b/nova/api/openstack/compute/contrib/os_networks.py @@ -139,6 +139,9 @@ class NetworkController(wsgi.Controller): try: self.network_api.add_network_to_project( context, project_id, network_id) + except NotImplementedError: + msg = (_("VLAN support must be enabled")) + raise exc.HTTPNotImplemented(explanation=msg) except Exception as ex: msg = (_("Cannot associate network %(network)s" " with project %(project)s: %(message)s") % diff --git a/nova/network/manager.py b/nova/network/manager.py index 63270a136..0186cc8ef 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -1389,6 +1389,9 @@ class NetworkManager(manager.Manager): dev = self.driver.get_dev(network) self.driver.update_dns(context, dev, network) + def add_network_to_project(self, ctxt, project_id, network_uuid): + raise NotImplementedError() + class FlatManager(NetworkManager): """Basic network where no vlans are used. diff --git a/nova/tests/api/openstack/compute/contrib/test_networks.py b/nova/tests/api/openstack/compute/contrib/test_networks.py index 8238f9248..7bf871690 100644 --- a/nova/tests/api/openstack/compute/contrib/test_networks.py +++ b/nova/tests/api/openstack/compute/contrib/test_networks.py @@ -94,10 +94,14 @@ NEW_NETWORK = { class FakeNetworkAPI(object): _sentinel = object() + _vlan_is_disabled = False def __init__(self): self.networks = copy.deepcopy(FAKE_NETWORKS) + def disable_vlan(self): + self._vlan_is_disabled = True + def delete(self, context, network_id): for i, network in enumerate(self.networks): if network['id'] == network_id: @@ -125,6 +129,8 @@ class FakeNetworkAPI(object): def add_network_to_project(self, context, project_id, network_uuid=None): + if self._vlan_is_disabled: + raise NotImplementedError() if network_uuid: for network in self.networks: if network.get('project_id', None) is None: @@ -274,6 +280,13 @@ class NetworksTest(test.TestCase): self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete, req, 100) + def test_network_add_vlan_disabled(self): + self.fake_network_api.disable_vlan() + uuid = FAKE_NETWORKS[1]['uuid'] + req = fakes.HTTPRequest.blank('/v2/1234/os-networks/add') + self.assertRaises(webob.exc.HTTPNotImplemented, + self.controller.add, req, {'id': uuid}) + def test_network_add(self): uuid = FAKE_NETWORKS[1]['uuid'] req = fakes.HTTPRequest.blank('/v2/1234/os-networks/add') |
