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)],
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],
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)
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)