]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Move values for network_type to plugins.common.constants.py
authorRomil Gupta <romilg@hp.com>
Mon, 23 Mar 2015 15:05:41 +0000 (08:05 -0700)
committerRomil Gupta <romilg@hp.com>
Mon, 13 Apr 2015 06:59:31 +0000 (23:59 -0700)
It is quite confusing to have values for network type in common.constants.py
instead of having in plugins.common.constants.py.

Currently, the plugins/common/constants.py consists network_type constants
like VLAN, VXLAN, GRE etc. but values for network type like ranges
are defined in common.constants.py which is not good, it is better to have
both things at the same place.

This patch set addresses the same.

Moved out few methods which are predominantly used in plugins
from common.utils.py to plugins.common.utils.py.

Removed constants which were used in neutron-fwaas from
plugins.common.constants.py: https://review.openstack.org/#/c/168709/

Closes-Bug: #1441043

Change-Id: Iecfb15c541ed5d3cce95ba48f072af7fa60ac6f1

15 files changed:
neutron/agent/common/ovs_lib.py
neutron/common/constants.py
neutron/common/utils.py
neutron/db/migration/migrate_to_ml2.py
neutron/plugins/brocade/vlanbm.py
neutron/plugins/cisco/db/n1kv_db_v2.py
neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py
neutron/plugins/common/constants.py
neutron/plugins/common/utils.py
neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py
neutron/plugins/ml2/drivers/type_vlan.py
neutron/plugins/ml2/drivers/type_vxlan.py
neutron/plugins/openvswitch/agent/ovs_neutron_agent.py
neutron/tests/unit/common/test_utils.py
neutron/tests/unit/plugins/linuxbridge/agent/test_linuxbridge_neutron_agent.py

index d79092d2416c2226ba9687296bba3c4f927976fa..3004bc99b583bef6c471abfa5d56f9feec910fcd 100644 (file)
@@ -28,7 +28,7 @@ from neutron.agent.linux import ip_lib
 from neutron.agent.ovsdb import api as ovsdb
 from neutron.common import exceptions
 from neutron.i18n import _LE, _LI, _LW
-from neutron.plugins.common import constants
+from neutron.plugins.common import constants as p_const
 
 # Default timeout for ovs-vsctl command
 DEFAULT_OVS_VSCTL_TIMEOUT = 10
@@ -264,15 +264,15 @@ class OVSBridge(BaseOVS):
         return DeferredOVSBridge(self, **kwargs)
 
     def add_tunnel_port(self, port_name, remote_ip, local_ip,
-                        tunnel_type=constants.TYPE_GRE,
-                        vxlan_udp_port=constants.VXLAN_UDP_PORT,
+                        tunnel_type=p_const.TYPE_GRE,
+                        vxlan_udp_port=p_const.VXLAN_UDP_PORT,
                         dont_fragment=True):
         attrs = [('type', tunnel_type)]
         # TODO(twilson) This is an OrderedDict solely to make a test happy
         options = collections.OrderedDict()
         vxlan_uses_custom_udp_port = (
-            tunnel_type == constants.TYPE_VXLAN and
-            vxlan_udp_port != constants.VXLAN_UDP_PORT
+            tunnel_type == p_const.TYPE_VXLAN and
+            vxlan_udp_port != p_const.VXLAN_UDP_PORT
         )
         if vxlan_uses_custom_udp_port:
             options['dst_port'] = vxlan_udp_port
index 662f447581e3a9cca46818e794d53457a983ba81..1bb4891183df99fd3fe789c725ce8371043ef87b 100644 (file)
@@ -76,17 +76,6 @@ IPv6_ANY = '::/0'
 
 DHCP_RESPONSE_PORT = 68
 
-MIN_VLAN_TAG = 1
-MAX_VLAN_TAG = 4094
-
-# For GRE Tunnel
-MIN_GRE_ID = 1
-MAX_GRE_ID = 2 ** 32 - 1
-
-# For VXLAN Tunnel
-MIN_VXLAN_VNI = 1
-MAX_VXLAN_VNI = 2 ** 24 - 1
-
 FLOODING_ENTRY = ('00:00:00:00:00:00', '0.0.0.0')
 
 AGENT_TYPE_DHCP = 'DHCP agent'
index 2502c4d719442da243851d9055628bd27d530001..fb4a3ddf1997a1e6c6983e5641c799b46ae5cf6d 100644 (file)
@@ -38,7 +38,6 @@ from oslo_utils import excutils
 
 from neutron.common import constants as q_const
 
-
 TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
 LOG = logging.getLogger(__name__)
 SYNCHRONIZED_PREFIX = 'neutron-'
@@ -270,18 +269,6 @@ def log_opt_values(log):
     cfg.CONF.log_opt_values(log, std_logging.DEBUG)
 
 
-def is_valid_vlan_tag(vlan):
-    return q_const.MIN_VLAN_TAG <= vlan <= q_const.MAX_VLAN_TAG
-
-
-def is_valid_gre_id(gre_id):
-    return q_const.MIN_GRE_ID <= gre_id <= q_const.MAX_GRE_ID
-
-
-def is_valid_vxlan_vni(vni):
-    return q_const.MIN_VXLAN_VNI <= vni <= q_const.MAX_VXLAN_VNI
-
-
 def get_random_mac(base_mac):
     mac = [int(base_mac[0], 16), int(base_mac[1], 16),
            int(base_mac[2], 16), random.randint(0x00, 0xff),
index 2aca5ad97ac6015b8441191591053f48f186f2a0..e6c5db332fdfbc50f2d57654be98024b36701323 100755 (executable)
@@ -66,7 +66,6 @@ import sqlalchemy as sa
 from neutron.extensions import portbindings
 from neutron.openstack.common import uuidutils
 from neutron.plugins.common import constants as p_const
-from neutron.plugins.ml2.drivers import type_vxlan
 
 
 # Migration targets
@@ -431,7 +430,7 @@ class MigrateOpenvswitchToMl2_Juno(BaseMigrateToMl2):
             """)
         elif tunnel_type == p_const.TYPE_VXLAN:
             if not vxlan_udp_port:
-                vxlan_udp_port = type_vxlan.VXLAN_UDP_PORT
+                vxlan_udp_port = p_const.VXLAN_UDP_PORT
             engine.execute("""
               INSERT INTO ml2_vxlan_allocations
                 SELECT tunnel_id as vxlan_vni, allocated
index 16c9d4bf3611d969c99130e0e44e7d408ecf4af5..fb3aeba20ad90926bc34febad780d68a2c8a123b 100644 (file)
 """A Vlan Bitmap class to handle allocation/de-allocation of vlan ids."""
 from six import moves
 
-from neutron.common import constants
 from neutron.plugins.brocade.db import models as brocade_db
+from neutron.plugins.common import constants as p_const
 
-
-MIN_VLAN = constants.MIN_VLAN_TAG + 1
-MAX_VLAN = constants.MAX_VLAN_TAG
+MIN_VLAN = p_const.MIN_VLAN_TAG + 1
+MAX_VLAN = p_const.MAX_VLAN_TAG
 
 
 class VlanBitmap(object):
index aca3eca49a7acf053fef0f99a5c842608439ad11..078e52298902567e924a59a94f4176ccbb7b772b 100644 (file)
@@ -20,7 +20,6 @@ from sqlalchemy.orm import exc
 from sqlalchemy import sql
 
 from neutron.api.v2 import attributes
-from neutron.common import constants
 from neutron.common import exceptions as n_exc
 import neutron.db.api as db
 from neutron.db import models_v2
@@ -29,6 +28,8 @@ from neutron.plugins.cisco.common import cisco_constants as c_const
 from neutron.plugins.cisco.common import cisco_exceptions as c_exc
 from neutron.plugins.cisco.common import config as c_conf
 from neutron.plugins.cisco.db import n1kv_models_v2
+from neutron.plugins.common import constants as p_const
+
 
 LOG = logging.getLogger(__name__)
 
@@ -1381,20 +1382,20 @@ class NetworkProfile_db_mixin(object):
         seg_min, seg_max = self._get_segment_range(net_p['segment_range'])
         if segment_type == c_const.NETWORK_TYPE_VLAN:
             if not ((seg_min <= seg_max) and
-                    ((seg_min in range(constants.MIN_VLAN_TAG,
+                    ((seg_min in range(p_const.MIN_VLAN_TAG,
                                        c_const.N1KV_VLAN_RESERVED_MIN) and
-                      seg_max in range(constants.MIN_VLAN_TAG,
+                      seg_max in range(p_const.MIN_VLAN_TAG,
                                        c_const.N1KV_VLAN_RESERVED_MIN)) or
                      (seg_min in range(c_const.N1KV_VLAN_RESERVED_MAX + 1,
-                                       constants.MAX_VLAN_TAG) and
+                                       p_const.MAX_VLAN_TAG) and
                       seg_max in range(c_const.N1KV_VLAN_RESERVED_MAX + 1,
-                                       constants.MAX_VLAN_TAG)))):
+                                       p_const.MAX_VLAN_TAG)))):
                 msg = (_("Segment range is invalid, select from "
                          "%(min)s-%(nmin)s, %(nmax)s-%(max)s") %
-                       {"min": constants.MIN_VLAN_TAG,
+                       {"min": p_const.MIN_VLAN_TAG,
                         "nmin": c_const.N1KV_VLAN_RESERVED_MIN - 1,
                         "nmax": c_const.N1KV_VLAN_RESERVED_MAX + 1,
-                        "max": constants.MAX_VLAN_TAG - 1})
+                        "max": p_const.MAX_VLAN_TAG - 1})
                 LOG.error(msg)
                 raise n_exc.InvalidInput(error_message=msg)
             profiles = _get_network_profiles(
index bb80e17773d6ece27e9ab5099d19cb1bf2692ec4..d0b5f2549c3845562a2dc5770e2b99e9ba0ed159 100644 (file)
@@ -26,7 +26,6 @@ from neutron.common import constants
 from neutron.common import exceptions as n_exc
 from neutron.common import rpc as n_rpc
 from neutron.common import topics
-from neutron.common import utils
 from neutron.db import agents_db
 from neutron.db import agentschedulers_db
 from neutron.db import db_base_plugin_v2
@@ -47,6 +46,7 @@ from neutron.plugins.cisco.db import network_db_v2
 from neutron.plugins.cisco.extensions import n1kv
 from neutron.plugins.cisco.n1kv import n1kv_client
 from neutron.plugins.common import constants as svc_constants
+from neutron.plugins.common import utils
 
 
 LOG = logging.getLogger(__name__)
index 627a3fcf8e27ab69eb3fc69b219286807254356e..5c562dc3b7b6344fd91f9320c83e855bb088e323 100644 (file)
@@ -13,7 +13,7 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-# service type constants:
+# Service type constants:
 CORE = "CORE"
 DUMMY = "DUMMY"
 LOADBALANCER = "LOADBALANCER"
@@ -24,7 +24,7 @@ METERING = "METERING"
 L3_ROUTER_NAT = "L3_ROUTER_NAT"
 
 
-#maps extension alias to service type
+# Maps extension alias to service type
 EXT_TO_SERVICE_MAPPING = {
     'dummy': DUMMY,
     'lbaas': LOADBALANCER,
@@ -66,15 +66,6 @@ ACTIVE_PENDING_STATUSES = (
     PENDING_UPDATE
 )
 
-# FWaaS firewall rule action
-FWAAS_ALLOW = "allow"
-FWAAS_DENY = "deny"
-
-# L3 Protocol name constants
-TCP = "tcp"
-UDP = "udp"
-ICMP = "icmp"
-
 # Network Type constants
 TYPE_FLAT = 'flat'
 TYPE_GRE = 'gre'
@@ -84,6 +75,18 @@ TYPE_VLAN = 'vlan'
 TYPE_NONE = 'none'
 
 # Values for network_type
+
+# For VLAN Network
+MIN_VLAN_TAG = 1
+MAX_VLAN_TAG = 4094
+
+# For GRE Tunnel
+MIN_GRE_ID = 1
+MAX_GRE_ID = 2 ** 32 - 1
+
+# For VXLAN Tunnel
+MIN_VXLAN_VNI = 1
+MAX_VXLAN_VNI = 2 ** 24 - 1
 VXLAN_UDP_PORT = 4789
 
 # Network Type MTU overhead
index 7addb639a4d63506533f2c9926c31a53cba92d73..40ca2cffd3532cbec220f72dcfb243a784a25b61 100644 (file)
@@ -17,14 +17,25 @@ Common utilities and helper functions for Openstack Networking Plugins.
 """
 
 from neutron.common import exceptions as n_exc
-from neutron.common import utils
 from neutron.plugins.common import constants as p_const
 
 
+def is_valid_vlan_tag(vlan):
+    return p_const.MIN_VLAN_TAG <= vlan <= p_const.MAX_VLAN_TAG
+
+
+def is_valid_gre_id(gre_id):
+    return p_const.MIN_GRE_ID <= gre_id <= p_const.MAX_GRE_ID
+
+
+def is_valid_vxlan_vni(vni):
+    return p_const.MIN_VXLAN_VNI <= vni <= p_const.MAX_VXLAN_VNI
+
+
 def verify_tunnel_range(tunnel_range, tunnel_type):
     """Raise an exception for invalid tunnel range or malformed range."""
-    mappings = {p_const.TYPE_GRE: utils.is_valid_gre_id,
-                p_const.TYPE_VXLAN: utils.is_valid_vxlan_vni}
+    mappings = {p_const.TYPE_GRE: is_valid_gre_id,
+                p_const.TYPE_VXLAN: is_valid_vxlan_vni}
     if tunnel_type in mappings:
         for ident in tunnel_range:
             if not mappings[tunnel_type](ident):
@@ -42,7 +53,7 @@ def verify_tunnel_range(tunnel_range, tunnel_type):
 def verify_vlan_range(vlan_range):
     """Raise an exception for invalid tags or malformed range."""
     for vlan_tag in vlan_range:
-        if not utils.is_valid_vlan_tag(vlan_tag):
+        if not is_valid_vlan_tag(vlan_tag):
             raise n_exc.NetworkVlanRangeError(
                 vlan_range=vlan_range,
                 error=_("%s is not a valid VLAN tag") % vlan_tag)
index c4eee0884bb875261aadb3acfd76614e73648cf9..7b1f2861500062369a0d3f6c6d279ab4a34c3d9f 100644 (file)
@@ -115,7 +115,7 @@ class LinuxBridgeManager(object):
         return tap_device_name
 
     def get_vxlan_device_name(self, segmentation_id):
-        if 0 <= int(segmentation_id) <= constants.MAX_VXLAN_VNI:
+        if 0 <= int(segmentation_id) <= p_const.MAX_VXLAN_VNI:
             return VXLAN_INTERFACE_PREFIX + str(segmentation_id)
         else:
             LOG.warning(_LW("Invalid Segmentation ID: %s, will lead to "
@@ -523,7 +523,7 @@ class LinuxBridgeManager(object):
             return False
 
         test_iface = None
-        for seg_id in moves.xrange(1, constants.MAX_VXLAN_VNI + 1):
+        for seg_id in moves.xrange(1, p_const.MAX_VXLAN_VNI + 1):
             if not ip_lib.device_exists(
                     self.get_vxlan_device_name(seg_id)):
                 test_iface = self.ensure_vxlan(seg_id)
index c767bb6024d23c018754ce4f8850a61d620ce3f8..d2459e785e633315f131ae2ccf2bf516ab2dc216 100644 (file)
@@ -20,9 +20,7 @@ from oslo_log import log
 from six import moves
 import sqlalchemy as sa
 
-from neutron.common import constants as q_const
 from neutron.common import exceptions as exc
-from neutron.common import utils
 from neutron.db import api as db_api
 from neutron.db import model_base
 from neutron.i18n import _LE, _LI, _LW
@@ -177,11 +175,11 @@ class VlanTypeDriver(helpers.SegmentTypeDriver):
                          " for VLAN provider network") % physical_network)
                 raise exc.InvalidInput(error_message=msg)
             if segmentation_id:
-                if not utils.is_valid_vlan_tag(segmentation_id):
+                if not plugin_utils.is_valid_vlan_tag(segmentation_id):
                     msg = (_("segmentation_id out of range (%(min)s through "
                              "%(max)s)") %
-                           {'min': q_const.MIN_VLAN_TAG,
-                            'max': q_const.MAX_VLAN_TAG})
+                           {'min': p_const.MIN_VLAN_TAG,
+                            'max': p_const.MAX_VLAN_TAG})
                     raise exc.InvalidInput(error_message=msg)
         elif segmentation_id:
             msg = _("segmentation_id requires physical_network for VLAN "
index 9d76c1727a07bb5f3150ab2d39a2a83fd7381660..5b7dbdc383a5116d2c9ffc73c5b3a8418b577f5c 100644 (file)
@@ -29,9 +29,6 @@ from neutron.plugins.ml2.drivers import type_tunnel
 
 LOG = log.getLogger(__name__)
 
-VXLAN_UDP_PORT = 4789
-MAX_VXLAN_VNI = 16777215
-
 vxlan_opts = [
     cfg.ListOpt('vni_ranges',
                 default=[],
@@ -94,7 +91,7 @@ class VxlanTypeDriver(type_tunnel.TunnelTypeDriver):
         # determine current configured allocatable vnis
         vxlan_vnis = set()
         for tun_min, tun_max in self.tunnel_ranges:
-            if tun_max + 1 - tun_min > MAX_VXLAN_VNI:
+            if tun_max + 1 - tun_min > p_const.MAX_VXLAN_VNI:
                 LOG.error(_LE("Skipping unreasonable VXLAN VNI range "
                               "%(tun_min)s:%(tun_max)s"),
                           {'tun_min': tun_min, 'tun_max': tun_max})
@@ -157,7 +154,7 @@ class VxlanTypeDriver(type_tunnel.TunnelTypeDriver):
         return (session.query(VxlanEndpoints).
                 filter_by(ip_address=ip).first())
 
-    def add_endpoint(self, ip, host, udp_port=VXLAN_UDP_PORT):
+    def add_endpoint(self, ip, host, udp_port=p_const.VXLAN_UDP_PORT):
         LOG.debug("add_vxlan_endpoint() called for ip %s", ip)
         session = db_api.get_session()
         try:
index 457f1399fb64bd1089888e2deea819b04849231e..d6fd658e09e5ed27d7502cc486770aaa5ce61fd8 100644 (file)
@@ -51,7 +51,7 @@ LOG = logging.getLogger(__name__)
 cfg.CONF.import_group('AGENT', 'neutron.plugins.openvswitch.common.config')
 
 # A placeholder for dead vlans.
-DEAD_VLAN_TAG = q_const.MAX_VLAN_TAG + 1
+DEAD_VLAN_TAG = p_const.MAX_VLAN_TAG + 1
 
 
 class DeviceListRetrievalError(exceptions.NeutronException):
@@ -161,8 +161,8 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
         super(OVSNeutronAgent, self).__init__()
         self.use_veth_interconnection = use_veth_interconnection
         self.veth_mtu = veth_mtu
-        self.available_local_vlans = set(moves.xrange(q_const.MIN_VLAN_TAG,
-                                                      q_const.MAX_VLAN_TAG))
+        self.available_local_vlans = set(moves.xrange(p_const.MIN_VLAN_TAG,
+                                                      p_const.MAX_VLAN_TAG))
         self.use_call = True
         self.tunnel_types = tunnel_types or []
         self.l2_pop = l2_population
index 7a370f13bbec7f492cc8b13317a89bb8f614b61f..27f6604ab30b3de70795f07d16e2c4114d8f6891 100644 (file)
@@ -118,15 +118,15 @@ class TestParseTunnelRangesMixin(object):
 
 class TestGreTunnelRangeVerifyValid(TestParseTunnelRangesMixin,
                                     base.BaseTestCase):
-    TUN_MIN = constants.MIN_GRE_ID
-    TUN_MAX = constants.MAX_GRE_ID
+    TUN_MIN = p_const.MIN_GRE_ID
+    TUN_MAX = p_const.MAX_GRE_ID
     TYPE = p_const.TYPE_GRE
 
 
 class TestVxlanTunnelRangeVerifyValid(TestParseTunnelRangesMixin,
                                       base.BaseTestCase):
-    TUN_MIN = constants.MIN_VXLAN_VNI
-    TUN_MAX = constants.MAX_VXLAN_VNI
+    TUN_MIN = p_const.MIN_VXLAN_VNI
+    TUN_MAX = p_const.MAX_VXLAN_VNI
     TYPE = p_const.TYPE_VXLAN
 
 
index 7832dc696269342b360810878c41b231ec664302..bc6b59532dbaa0048835fa821b67173089ec0249 100644 (file)
@@ -373,7 +373,7 @@ class TestLinuxBridgeManager(base.BaseTestCase):
                          constants.TAP_DEVICE_PREFIX)
 
     def test_get_vxlan_device_name(self):
-        vn_id = constants.MAX_VXLAN_VNI
+        vn_id = p_const.MAX_VXLAN_VNI
         self.assertEqual(self.lbm.get_vxlan_device_name(vn_id),
                          "vxlan-" + str(vn_id))
         self.assertIsNone(self.lbm.get_vxlan_device_name(vn_id + 1))