From 8f3301cb2792cf05dd29a79506719b0141bf029f Mon Sep 17 00:00:00 2001 From: Manish Godara Date: Tue, 24 Jun 2014 10:23:59 -0700 Subject: [PATCH] validate flat networks physical name Modified flat driver to validate the physical network name - we make sure that empty names are deducted. unit test changes: - added two tests to make sure that we detect empty physnet names - fix bug in existing unit-tests -- flat_networks should be a list of string and not string - use conf to setup flat_network Change-Id: Ib7cfbd3c97d2e95c82044a2cba683c917ea54a84 Partial-bug: #1325664 --- neutron/plugins/ml2/drivers/type_flat.py | 5 +++-- neutron/tests/unit/ml2/test_type_flat.py | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/neutron/plugins/ml2/drivers/type_flat.py b/neutron/plugins/ml2/drivers/type_flat.py index 3e736eabc..543e0089f 100644 --- a/neutron/plugins/ml2/drivers/type_flat.py +++ b/neutron/plugins/ml2/drivers/type_flat.py @@ -67,9 +67,10 @@ class FlatTypeDriver(api.TypeDriver): if '*' in self.flat_networks: LOG.info(_("Arbitrary flat physical_network names allowed")) self.flat_networks = None + elif not all(self.flat_networks): + msg = _("physical network name is empty") + raise exc.InvalidInput(error_message=msg) else: - # TODO(rkukura): Validate that each physical_network name - # is neither empty nor too long. LOG.info(_("Allowable flat physical_network names: %s"), self.flat_networks) diff --git a/neutron/tests/unit/ml2/test_type_flat.py b/neutron/tests/unit/ml2/test_type_flat.py index 711418ccd..759424e8f 100644 --- a/neutron/tests/unit/ml2/test_type_flat.py +++ b/neutron/tests/unit/ml2/test_type_flat.py @@ -19,9 +19,10 @@ from neutron.plugins.common import constants as p_const from neutron.plugins.ml2 import driver_api as api from neutron.plugins.ml2.drivers import type_flat from neutron.tests import base +from oslo.config import cfg -FLAT_NETWORKS = 'flat_net1, flat_net2' +FLAT_NETWORKS = ['flat_net1', 'flat_net2'] class FlatTypeTest(base.BaseTestCase): @@ -29,8 +30,9 @@ class FlatTypeTest(base.BaseTestCase): def setUp(self): super(FlatTypeTest, self).setUp() db.configure_db() + cfg.CONF.set_override('flat_networks', FLAT_NETWORKS, + group='ml2_type_flat') self.driver = type_flat.FlatTypeDriver() - self.driver._parse_networks(FLAT_NETWORKS) self.session = db.get_session() self.addCleanup(db.clear_db) @@ -43,6 +45,16 @@ class FlatTypeTest(base.BaseTestCase): api.PHYSICAL_NETWORK: 'flat_net1'} self.driver.validate_provider_segment(segment) + def test_validate_provider_phynet_name(self): + self.assertRaises(exc.InvalidInput, + self.driver._parse_networks, + entries=['']) + + def test_validate_provider_phynet_name_multiple(self): + self.assertRaises(exc.InvalidInput, + self.driver._parse_networks, + entries=['flat_net1', '']) + def test_validate_provider_segment_without_physnet_restriction(self): self.driver._parse_networks('*') segment = {api.NETWORK_TYPE: p_const.TYPE_FLAT, -- 2.45.2