Replace network type names by constants

Each network type name is defined as a constant in neutron-lib. This
replaces the remaining string by the common constants.

This change ignores tests code because updating all test code brings
little gain while it touches huge number of lines.

Change-Id: I26ee715209d7d3f12c39c9e05d4fb9953b9b9537
This commit is contained in:
Takashi Kajinami 2023-11-28 16:06:13 +09:00
parent 56172ed5ae
commit 47d140d4d0
6 changed files with 25 additions and 18 deletions

View File

@ -18,7 +18,7 @@
import os
import sys
from neutron_lib import constants
from neutron_lib import constants as const
from openstack import connection
@ -27,8 +27,8 @@ GENEVE_ENCAP_OVERHEAD = 38
# map of network types to migrate and the difference in overhead size when
# converted to Geneve.
NETWORK_TYPE_OVERHEAD_DIFF = {
'vxlan': GENEVE_ENCAP_OVERHEAD - constants.VXLAN_ENCAP_OVERHEAD,
'gre': GENEVE_ENCAP_OVERHEAD - constants.GRE_ENCAP_OVERHEAD,
const.TYPE_VXLAN: GENEVE_ENCAP_OVERHEAD - const.VXLAN_ENCAP_OVERHEAD,
const.TYPE_GRE: GENEVE_ENCAP_OVERHEAD - const.GRE_ENCAP_OVERHEAD,
}

View File

@ -15,6 +15,7 @@
import sys
from neutron_lib import constants
from oslo_config import cfg
from oslo_log import log as logging
@ -454,11 +455,11 @@ def enable_tests_from_config():
cfg.CONF.set_default('arp_header_match', True)
cfg.CONF.set_default('icmpv6_header_match', True)
if 'vxlan' in cfg.CONF.AGENT.tunnel_types:
if constants.TYPE_VXLAN in cfg.CONF.AGENT.tunnel_types:
cfg.CONF.set_default('ovs_vxlan', True)
if 'geneve' in cfg.CONF.AGENT.tunnel_types:
if constants.TYPE_GENEVE in cfg.CONF.AGENT.tunnel_types:
cfg.CONF.set_default('ovs_geneve', True)
if ('vxlan' in cfg.CONF.ml2.type_drivers or
if (constants.TYPE_VXLAN in cfg.CONF.ml2.type_drivers or
cfg.CONF.VXLAN.enable_vxlan):
cfg.CONF.set_default('iproute2_vxlan', True)
if (cfg.CONF.notify_nova_on_port_status_changes or

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
from neutron_lib import constants
from oslo_config import cfg
from neutron._i18n import _
@ -21,11 +22,13 @@ from neutron.common import _constants as common_const
ml2_opts = [
cfg.ListOpt('type_drivers',
default=['local', 'flat', 'vlan', 'gre', 'vxlan', 'geneve'],
default=[constants.TYPE_LOCAL, constants.TYPE_FLAT,
constants.TYPE_VLAN, constants.TYPE_GRE,
constants.TYPE_VXLAN, constants.TYPE_GENEVE],
help=_("List of network type driver entrypoints to be loaded "
"from the neutron.ml2.type_drivers namespace.")),
cfg.ListOpt('tenant_network_types',
default=['local'],
default=[constants.TYPE_LOCAL],
help=_("Ordered list of network_types to allocate as tenant "
"networks. The default value 'local' is useful for "
"single-box testing but provides no connectivity "

View File

@ -13,6 +13,7 @@
# under the License.
from neutron_lib.api.definitions import portbindings as pb_api
from neutron_lib import constants
from neutron_lib import context as n_context
from neutron_lib.db import api as db_api
from neutron_lib import exceptions
@ -46,9 +47,9 @@ def migrate_neutron_database_to_ovn():
with db_api.CONTEXT_WRITER.using(ctx) as session:
# Change network type from vxlan geneve
segments = network_obj.NetworkSegment.get_objects(
ctx, network_type='vxlan')
ctx, network_type=constants.TYPE_VXLAN)
for segment in segments:
segment.network_type = 'geneve'
segment.network_type = constants.TYPE_GENEVE
segment.update()
# Update Geneve allocation for the segment
session.query(geneveallocation.GeneveAllocation).filter(

View File

@ -1020,7 +1020,7 @@ class OVNMechanismDriver(api.MechanismDriver):
{'port_id': port['id'],
'network_type': network_type})
if ((network_type in ['flat', 'vlan']) and
if ((network_type in [const.TYPE_FLAT, const.TYPE_VLAN]) and
(physical_network not in chassis_physnets)):
LOG.info('Refusing to bind port %(port_id)s on '
'host %(host)s due to the OVN chassis '
@ -1236,7 +1236,7 @@ class OVNMechanismDriver(api.MechanismDriver):
available_seg_ids = {
segment['id'] for segment in segments
if segment['network_type'] in ('flat', 'vlan')}
if segment['network_type'] in (const.TYPE_FLAT, const.TYPE_VLAN)}
segment_service_db.update_segment_host_mapping(
ctx, host, available_seg_ids)

View File

@ -353,9 +353,9 @@ class DNSExtensionDriverML2(DNSExtensionDriver):
LOG.info("DNSExtensionDriverML2 initialization complete")
def _is_tunnel_tenant_network(self, provider_net):
if provider_net['network_type'] == 'geneve':
if provider_net['network_type'] == lib_const.TYPE_GENEVE:
tunnel_ranges = cfg.CONF.ml2_type_geneve.vni_ranges
elif provider_net['network_type'] == 'vxlan':
elif provider_net['network_type'] == lib_const.TYPE_VXLAN:
tunnel_ranges = cfg.CONF.ml2_type_vxlan.vni_ranges
else:
tunnel_ranges = cfg.CONF.ml2_type_gre.tunnel_id_ranges
@ -392,13 +392,15 @@ class DNSExtensionDriverML2(DNSExtensionDriver):
if len(segments) > 1:
return False
provider_net = segments[0]
if provider_net['network_type'] == 'local':
if provider_net['network_type'] == lib_const.TYPE_LOCAL:
return True
if provider_net['network_type'] == 'flat':
if provider_net['network_type'] == lib_const.TYPE_FLAT:
return False
if provider_net['network_type'] == 'vlan':
if provider_net['network_type'] == lib_const.TYPE_VLAN:
return self._is_vlan_tenant_network(provider_net)
if provider_net['network_type'] in ['gre', 'vxlan', 'geneve']:
if provider_net['network_type'] in [
lib_const.TYPE_GRE, lib_const.TYPE_VXLAN,
lib_const.TYPE_GENEVE]:
return self._is_tunnel_tenant_network(provider_net)
return True