From: Ann Kamyshnikova Date: Tue, 3 Mar 2015 15:19:20 +0000 (+0300) Subject: Fix validation of physical network name for flat nets X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=dbe37d571474ca759e57e61308cd3926a00b481e;p=openstack-build%2Fneutron-build.git Fix validation of physical network name for flat nets Fix validation of physical network name for flat nets for the case when physical network names are not set. Closes-bug: #1424548 Change-Id: Ibb64af48ff65ca515f48cfba176a89afc9103f1e --- diff --git a/neutron/plugins/ml2/drivers/type_flat.py b/neutron/plugins/ml2/drivers/type_flat.py index ed055f560..657486669 100644 --- a/neutron/plugins/ml2/drivers/type_flat.py +++ b/neutron/plugins/ml2/drivers/type_flat.py @@ -92,7 +92,8 @@ class FlatTypeDriver(helpers.BaseTypeDriver): if not physical_network: msg = _("physical_network required for flat provider network") raise exc.InvalidInput(error_message=msg) - if self.flat_networks and physical_network not in self.flat_networks: + if (self.flat_networks is not None and + physical_network not in self.flat_networks): msg = (_("physical_network '%s' unknown for flat provider network") % physical_network) raise exc.InvalidInput(error_message=msg) diff --git a/neutron/tests/unit/ml2/test_ml2_plugin.py b/neutron/tests/unit/ml2/test_ml2_plugin.py index c9ccf773b..081f6f15f 100644 --- a/neutron/tests/unit/ml2/test_ml2_plugin.py +++ b/neutron/tests/unit/ml2/test_ml2_plugin.py @@ -115,6 +115,8 @@ class Ml2PluginV2TestCase(test_plugin.NeutronDbPluginV2TestCase): config.cfg.CONF.set_override('network_vlan_ranges', [self.phys_vrange, self.phys2_vrange], group='ml2_type_vlan') + config.cfg.CONF.set_override('flat_networks', ['noagent'], + group='ml2_type_flat') self.setup_parent() self.driver = ml2_plugin.Ml2Plugin() self.context = context.get_admin_context() diff --git a/neutron/tests/unit/ml2/test_type_flat.py b/neutron/tests/unit/ml2/test_type_flat.py index 1e84078d3..dac24d344 100644 --- a/neutron/tests/unit/ml2/test_type_flat.py +++ b/neutron/tests/unit/ml2/test_type_flat.py @@ -86,6 +86,16 @@ class FlatTypeTest(testlib_api.SqlTestCase): self.driver.validate_provider_segment, segment) + def test_validate_provider_segment_with_empty_physical_nets_list(self): + config.cfg.CONF.set_override('flat_networks', [], + group='ml2_type_flat') + driver = type_flat.FlatTypeDriver() + segment = {api.NETWORK_TYPE: p_const.TYPE_FLAT, + api.PHYSICAL_NETWORK: 'flat_net'} + self.assertRaises(exc.InvalidInput, + driver.validate_provider_segment, + segment) + def test_reserve_provider_segment(self): segment = {api.NETWORK_TYPE: p_const.TYPE_FLAT, api.PHYSICAL_NETWORK: 'flat_net1'}