]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
validate flat networks physical name
authorManish Godara <manishg@yahoo-inc.com>
Tue, 24 Jun 2014 17:23:59 +0000 (10:23 -0700)
committerManish Godara <manishg@yahoo-inc.com>
Wed, 25 Jun 2014 18:51:05 +0000 (11:51 -0700)
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
neutron/tests/unit/ml2/test_type_flat.py

index 3e736eabc8bc689097ec4564757deb93535d95cc..543e0089f4b86b79a3abcf94c0a87cebccf3c5e9 100644 (file)
@@ -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)
 
index 711418ccd201f1bd2b4dcf041af2150a9aa0648d..759424e8ffd0796eb05075985e67a9781c4b5cbf 100644 (file)
@@ -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,