From: Romil Gupta Date: Mon, 23 Mar 2015 15:05:41 +0000 (-0700) Subject: Move values for network_type to plugins.common.constants.py X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=7f406805d93298d0e65d340c2a06ba0d2dd6ff76;p=openstack-build%2Fneutron-build.git Move values for network_type to plugins.common.constants.py 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 --- diff --git a/neutron/agent/common/ovs_lib.py b/neutron/agent/common/ovs_lib.py index d79092d24..3004bc99b 100644 --- a/neutron/agent/common/ovs_lib.py +++ b/neutron/agent/common/ovs_lib.py @@ -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 diff --git a/neutron/common/constants.py b/neutron/common/constants.py index 662f44758..1bb489118 100644 --- a/neutron/common/constants.py +++ b/neutron/common/constants.py @@ -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' diff --git a/neutron/common/utils.py b/neutron/common/utils.py index 2502c4d71..fb4a3ddf1 100644 --- a/neutron/common/utils.py +++ b/neutron/common/utils.py @@ -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), diff --git a/neutron/db/migration/migrate_to_ml2.py b/neutron/db/migration/migrate_to_ml2.py index 2aca5ad97..e6c5db332 100755 --- a/neutron/db/migration/migrate_to_ml2.py +++ b/neutron/db/migration/migrate_to_ml2.py @@ -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 diff --git a/neutron/plugins/brocade/vlanbm.py b/neutron/plugins/brocade/vlanbm.py index 16c9d4bf3..fb3aeba20 100644 --- a/neutron/plugins/brocade/vlanbm.py +++ b/neutron/plugins/brocade/vlanbm.py @@ -17,12 +17,11 @@ """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): diff --git a/neutron/plugins/cisco/db/n1kv_db_v2.py b/neutron/plugins/cisco/db/n1kv_db_v2.py index aca3eca49..078e52298 100644 --- a/neutron/plugins/cisco/db/n1kv_db_v2.py +++ b/neutron/plugins/cisco/db/n1kv_db_v2.py @@ -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( diff --git a/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py b/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py index bb80e1777..d0b5f2549 100644 --- a/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py +++ b/neutron/plugins/cisco/n1kv/n1kv_neutron_plugin.py @@ -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__) diff --git a/neutron/plugins/common/constants.py b/neutron/plugins/common/constants.py index 627a3fcf8..5c562dc3b 100644 --- a/neutron/plugins/common/constants.py +++ b/neutron/plugins/common/constants.py @@ -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 diff --git a/neutron/plugins/common/utils.py b/neutron/plugins/common/utils.py index 7addb639a..40ca2cffd 100644 --- a/neutron/plugins/common/utils.py +++ b/neutron/plugins/common/utils.py @@ -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) diff --git a/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py b/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py index c4eee0884..7b1f28615 100644 --- a/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py +++ b/neutron/plugins/linuxbridge/agent/linuxbridge_neutron_agent.py @@ -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) diff --git a/neutron/plugins/ml2/drivers/type_vlan.py b/neutron/plugins/ml2/drivers/type_vlan.py index c767bb602..d2459e785 100644 --- a/neutron/plugins/ml2/drivers/type_vlan.py +++ b/neutron/plugins/ml2/drivers/type_vlan.py @@ -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 " diff --git a/neutron/plugins/ml2/drivers/type_vxlan.py b/neutron/plugins/ml2/drivers/type_vxlan.py index 9d76c1727..5b7dbdc38 100644 --- a/neutron/plugins/ml2/drivers/type_vxlan.py +++ b/neutron/plugins/ml2/drivers/type_vxlan.py @@ -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: diff --git a/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py b/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py index 457f1399f..d6fd658e0 100644 --- a/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py +++ b/neutron/plugins/openvswitch/agent/ovs_neutron_agent.py @@ -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 diff --git a/neutron/tests/unit/common/test_utils.py b/neutron/tests/unit/common/test_utils.py index 7a370f13b..27f6604ab 100644 --- a/neutron/tests/unit/common/test_utils.py +++ b/neutron/tests/unit/common/test_utils.py @@ -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 diff --git a/neutron/tests/unit/plugins/linuxbridge/agent/test_linuxbridge_neutron_agent.py b/neutron/tests/unit/plugins/linuxbridge/agent/test_linuxbridge_neutron_agent.py index 7832dc696..bc6b59532 100644 --- a/neutron/tests/unit/plugins/linuxbridge/agent/test_linuxbridge_neutron_agent.py +++ b/neutron/tests/unit/plugins/linuxbridge/agent/test_linuxbridge_neutron_agent.py @@ -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))