Throw meaningful exception bad network config
In the unmanaged driver, create port will fail with a KeyError if a network_id is used that isn't configured properly in neutron.conf (ie - bridge isn't defined). Added checks and meaningful error for users. Change-Id: Ief9c2371100063ff679858abc5fdf7cc24ec9dda Closes-Bug: #1611440 JIRA:NCP-2012
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
#
|
#
|
||||||
|
from neutron_lib import exceptions as n_exc
|
||||||
|
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
|
||||||
@@ -58,8 +59,15 @@ class UnmanagedDriver(base.BaseDriver):
|
|||||||
def create_port(self, context, network_id, port_id, **kwargs):
|
def create_port(self, context, network_id, port_id, **kwargs):
|
||||||
LOG.info("create_port %s %s %s" % (context.tenant_id, network_id,
|
LOG.info("create_port %s %s %s" % (context.tenant_id, network_id,
|
||||||
port_id))
|
port_id))
|
||||||
bridge_name = STRATEGY.get_network(network_id)["bridge"]
|
network = STRATEGY.get_network(network_id)
|
||||||
return {"uuid": port_id, "bridge": bridge_name}
|
if network and "bridge" in network:
|
||||||
|
return {"uuid": port_id, "bridge": network["bridge"]}
|
||||||
|
else:
|
||||||
|
raise n_exc.BadRequest(resource="ports",
|
||||||
|
msg=("Bridge is either not configured for"
|
||||||
|
" network or this network is not"
|
||||||
|
" defined in default_net_strategy:"
|
||||||
|
" %s" % network_id))
|
||||||
|
|
||||||
def update_port(self, context, port_id, **kwargs):
|
def update_port(self, context, port_id, **kwargs):
|
||||||
LOG.info("update_port %s %s" % (context.tenant_id, port_id))
|
LOG.info("update_port %s %s" % (context.tenant_id, port_id))
|
||||||
|
@@ -18,6 +18,7 @@ import uuid
|
|||||||
|
|
||||||
import mock
|
import mock
|
||||||
import netaddr
|
import netaddr
|
||||||
|
from neutron_lib import exceptions as n_exc
|
||||||
|
|
||||||
from quark.drivers import unmanaged
|
from quark.drivers import unmanaged
|
||||||
from quark import network_strategy
|
from quark import network_strategy
|
||||||
@@ -65,6 +66,11 @@ class TestUnmanagedDriver(test_base.TestBase):
|
|||||||
self.driver.create_port(context=self.context,
|
self.driver.create_port(context=self.context,
|
||||||
network_id="public_network", port_id=2)
|
network_id="public_network", port_id=2)
|
||||||
|
|
||||||
|
def test_create_port_raises(self):
|
||||||
|
with self.assertRaises(n_exc.BadRequest):
|
||||||
|
self.driver.create_port(context=self.context,
|
||||||
|
network_id="bad_network", port_id=2)
|
||||||
|
|
||||||
def test_update_port(self):
|
def test_update_port(self):
|
||||||
self.driver.update_port(context=self.context,
|
self.driver.update_port(context=self.context,
|
||||||
network_id="public_network", port_id=2)
|
network_id="public_network", port_id=2)
|
||||||
|
Reference in New Issue
Block a user