Merge "Validate network config (vlan)"
This commit is contained in:
commit
5f9f174a99
@ -305,6 +305,10 @@ class NetworkVlanRangeError(NeutronException):
|
||||
super(NetworkVlanRangeError, self).__init__(**kwargs)
|
||||
|
||||
|
||||
class PhysicalNetworkNameError(NeutronException):
|
||||
message = _("Empty physical network name.")
|
||||
|
||||
|
||||
class NetworkTunnelRangeError(NeutronException):
|
||||
message = _("Invalid network Tunnel range: "
|
||||
"'%(tunnel_range)s' - %(error)s")
|
||||
|
@ -61,6 +61,8 @@ def parse_network_vlan_range(network_vlan_range):
|
||||
vlan_range = (int(vlan_min), int(vlan_max))
|
||||
except ValueError as ex:
|
||||
raise n_exc.NetworkVlanRangeError(vlan_range=entry, error=ex)
|
||||
if not network:
|
||||
raise n_exc.PhysicalNetworkNameError()
|
||||
verify_vlan_range(vlan_range)
|
||||
return network, vlan_range
|
||||
else:
|
||||
|
@ -87,8 +87,6 @@ class VlanTypeDriver(helpers.TypeDriverHelper):
|
||||
try:
|
||||
self.network_vlan_ranges = plugin_utils.parse_network_vlan_ranges(
|
||||
cfg.CONF.ml2_type_vlan.network_vlan_ranges)
|
||||
# TODO(rkukura): Validate that each physical_network name
|
||||
# is neither empty nor too long.
|
||||
except Exception:
|
||||
LOG.exception(_("Failed to parse network_vlan_ranges. "
|
||||
"Service terminated!"))
|
||||
|
@ -19,18 +19,18 @@ from testtools import matchers
|
||||
from neutron.common import exceptions as exc
|
||||
import neutron.db.api as db
|
||||
from neutron.plugins.common import constants as p_const
|
||||
from neutron.plugins.common import utils as plugin_utils
|
||||
from neutron.plugins.ml2 import driver_api as api
|
||||
from neutron.plugins.ml2.drivers import type_vlan
|
||||
from neutron.tests.unit import testlib_api
|
||||
from oslo.config import cfg
|
||||
|
||||
PROVIDER_NET = 'phys_net1'
|
||||
TENANT_NET = 'phys_net2'
|
||||
VLAN_MIN = 200
|
||||
VLAN_MAX = 209
|
||||
NETWORK_VLAN_RANGES = {
|
||||
PROVIDER_NET: [],
|
||||
TENANT_NET: [(VLAN_MIN, VLAN_MAX)],
|
||||
}
|
||||
NETWORK_VLAN_RANGES = [PROVIDER_NET, "%s:%s:%s" %
|
||||
(TENANT_NET, VLAN_MIN, VLAN_MAX)]
|
||||
UPDATED_VLAN_RANGES = {
|
||||
PROVIDER_NET: [],
|
||||
TENANT_NET: [(VLAN_MIN + 5, VLAN_MAX + 5)],
|
||||
@ -41,11 +41,21 @@ class VlanTypeTest(testlib_api.SqlTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(VlanTypeTest, self).setUp()
|
||||
cfg.CONF.set_override('network_vlan_ranges', NETWORK_VLAN_RANGES,
|
||||
group='ml2_type_vlan')
|
||||
self.network_vlan_ranges = plugin_utils.parse_network_vlan_ranges(
|
||||
NETWORK_VLAN_RANGES)
|
||||
self.driver = type_vlan.VlanTypeDriver()
|
||||
self.driver.network_vlan_ranges = NETWORK_VLAN_RANGES
|
||||
self.driver._sync_vlan_allocations()
|
||||
self.session = db.get_session()
|
||||
|
||||
def test_parse_network_exception_handling(self):
|
||||
with mock.patch.object(plugin_utils,
|
||||
'parse_network_vlan_ranges') as parse_ranges:
|
||||
parse_ranges.side_effect = Exception('any exception')
|
||||
self.assertRaises(SystemExit,
|
||||
self.driver._parse_network_vlan_ranges)
|
||||
|
||||
def _get_allocation(self, session, segment):
|
||||
return session.query(type_vlan.VlanAllocation).filter_by(
|
||||
physical_network=segment[api.PHYSICAL_NETWORK],
|
||||
@ -128,7 +138,7 @@ class VlanTypeTest(testlib_api.SqlTestCase):
|
||||
self.assertFalse(
|
||||
self._get_allocation(self.session, segment).allocated)
|
||||
|
||||
check_in_ranges(NETWORK_VLAN_RANGES)
|
||||
check_in_ranges(self.network_vlan_ranges)
|
||||
self.driver.network_vlan_ranges = UPDATED_VLAN_RANGES
|
||||
self.driver._sync_vlan_allocations()
|
||||
check_in_ranges(UPDATED_VLAN_RANGES)
|
||||
|
@ -161,6 +161,22 @@ class UtilTestParseVlanRanges(base.BaseTestCase):
|
||||
return self._err_prefix + v_range_str + self._err_range
|
||||
|
||||
|
||||
class TestVlanNetworkNameValid(base.BaseTestCase):
|
||||
def parse_vlan_ranges(self, vlan_range):
|
||||
return plugin_utils.parse_network_vlan_ranges(vlan_range)
|
||||
|
||||
def test_validate_provider_phynet_name_mixed(self):
|
||||
self.assertRaises(n_exc.PhysicalNetworkNameError,
|
||||
self.parse_vlan_ranges,
|
||||
['', ':23:30', 'physnet1',
|
||||
'tenant_net:100:200'])
|
||||
|
||||
def test_validate_provider_phynet_name_bad(self):
|
||||
self.assertRaises(n_exc.PhysicalNetworkNameError,
|
||||
self.parse_vlan_ranges,
|
||||
[':1:34'])
|
||||
|
||||
|
||||
class TestVlanRangeVerifyValid(UtilTestParseVlanRanges):
|
||||
def verify_range(self, vlan_range):
|
||||
return plugin_utils.verify_vlan_range(vlan_range)
|
||||
|
Loading…
Reference in New Issue
Block a user