Revert "allow binding to vlan 0"

This reverts commit 782271f5db.

Conflicts:
	networking_l2gw/tests/unit/db/test_l2gw_db.py

Change-Id: I02b9b3f5902957734f6a840c38a824108ee6a3b6
changes/56/347156/2
Armando Migliaccio 7 years ago
parent 8d53fea503
commit b5635a3109

@ -67,7 +67,7 @@ class L2GatewayMixin(l2gateway.L2GatewayPluginBase,
query = context.session.query(models.L2GatewayInterface)
int_db = query.filter_by(id=int_model.id).first()
seg_id = int_db[constants.SEG_ID]
if seg_id >= 0:
if seg_id > 0:
return True
return False
@ -91,6 +91,8 @@ class L2GatewayMixin(l2gateway.L2GatewayPluginBase,
if gw_conn is None:
raise l2gw_exc.L2GatewayConnectionNotFound(id="")
segmentation_id = gw_conn['segmentation_id']
if segmentation_id == 0:
segmentation_id = ""
res = {'id': gw_conn['id'],
'network_id': gw_conn['network_id'],
'l2_gateway_id': gw_conn['l2_gateway_id'],
@ -105,6 +107,8 @@ class L2GatewayMixin(l2gateway.L2GatewayPluginBase,
interface_list = []
for interfaces_db in d.interfaces:
seg_id = interfaces_db[constants.SEG_ID]
if seg_id == 0:
seg_id = ""
interface_list.append({'name':
interfaces_db['interface_name'],
constants.SEG_ID:
@ -173,7 +177,7 @@ class L2GatewayMixin(l2gateway.L2GatewayPluginBase,
interface_db = self._get_int_model(uuid,
int_name,
dev_db.id,
None)
0)
context.session.add(interface_db)
context.session.query(models.L2GatewayDevice).all()
return self._make_l2_gateway_dict(gw_db)
@ -294,10 +298,8 @@ class L2GatewayMixin(l2gateway.L2GatewayPluginBase,
nw_map['tenant_id'] = tenant_id
connection_id = uuidutils.generate_uuid()
nw_map['id'] = connection_id
if segmentation_id == 0:
nw_map['segmentation_id'] = segmentation_id
elif not segmentation_id:
nw_map['segmentation_id'] = None
if not segmentation_id:
nw_map['segmentation_id'] = "0"
gw_db.network_connections.append(
models.L2GatewayConnection(**nw_map))
gw_db = models.L2GatewayConnection(id=connection_id,

@ -38,8 +38,7 @@ def delete_vlan_binding(context, record_dict):
"""Delete vlan bindings of a given physical port."""
session = context.session
with session.begin(subtransactions=True):
if(record_dict['vlan'] >= 0 and
record_dict['logical_switch_uuid']):
if(record_dict['vlan'] and record_dict['logical_switch_uuid']):
session.query(models.VlanBindings).filter_by(
port_uuid=record_dict['port_uuid'], vlan=record_dict['vlan'],
logical_switch_uuid=record_dict['logical_switch_uuid'],

@ -93,7 +93,7 @@ class UcastMacsRemotes(model_base.BASEV2):
class VlanBindings(model_base.BASEV2):
__tablename__ = 'vlan_bindings'
port_uuid = sa.Column(sa.String(36), nullable=False, primary_key=True)
vlan = sa.Column(sa.Integer, nullable=True, primary_key=True)
vlan = sa.Column(sa.Integer, nullable=False, primary_key=True)
logical_switch_uuid = sa.Column(sa.String(36), nullable=False,
primary_key=True)
ovsdb_identifier = sa.Column(sa.String(64), nullable=False,

@ -1,35 +0,0 @@
# Copyright 2016 vikas.d-m@hpe.com/Hewlett Packard Enterprise
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
"""allow_vlan_binding_0
Revision ID: 96191add2197
Revises: 79919185aa99
Create Date: 2016-06-21 21:57:01.823502
"""
# revision identifiers, used by Alembic.
revision = '96191add2197'
down_revision = '79919185aa99'
from alembic import op
import sqlalchemy as sa
def upgrade():
op.alter_column('vlan_bindings', 'vlan', nullable=True,
existing_type=sa.Integer(), existing_nullable=False,
autoincrement=False)

@ -72,8 +72,7 @@ def validate_gwdevice_list(data, valid_values=None):
def validate_network_mapping_list(network_mapping, check_vlan):
"""Validate network mapping list in connection."""
if (network_mapping.get(constants.SEG_ID) or
network_mapping.get(constants.SEG_ID) == 0):
if network_mapping.get('segmentation_id'):
if check_vlan:
raise exceptions.InvalidInput(
error_message=_("default segmentation_id should not be"
@ -82,7 +81,7 @@ def validate_network_mapping_list(network_mapping, check_vlan):
seg_id = network_mapping.get(constants.SEG_ID)
is_valid_vlan_id(seg_id)
elif not network_mapping.get(constants.SEG_ID):
if not network_mapping.get('segmentation_id'):
if check_vlan is False:
raise exceptions.InvalidInput(
error_message=_("Segmentation id must be specified in create "

@ -346,7 +346,7 @@ class L2gwRpcDriver(service_drivers.L2gwDriver):
network_id = gw_connection.get(constants.NETWORK_ID)
nw_map[constants.NETWORK_ID] = network_id
nw_map['l2_gateway_id'] = l2_gw_id
if seg_id is not None:
if seg_id:
nw_map[constants.SEG_ID] = gw_connection.get(constants.SEG_ID)
if not self.service_plugin._get_network(context, network_id):
raise exceptions.NetworkNotFound(net_id=network_id)
@ -417,9 +417,7 @@ class L2gwRpcDriver(service_drivers.L2gwDriver):
vlan_bindings = db.get_all_vlan_bindings_by_physical_port(
context, pp_dict)
if method == "CREATE":
if seg_id == 0:
LOG.debug("gateway connection with segmentation id 0")
elif not seg_id:
if not seg_id:
vlan_id = interface.get('segmentation_id')
else:
vlan_id = int(seg_id)
@ -444,9 +442,7 @@ class L2gwRpcDriver(service_drivers.L2gwDriver):
physical_port['vlan_bindings'] = port_list
else:
vlan_id = gw_connection.get('segmentation_id')
if vlan_id == 0:
LOG.debug("gateway connection with segmentation id 0")
elif not vlan_id:
if not vlan_id:
vlan_id = interface.get('segmentation_id')
vlan_dict = {'vlan': vlan_id,
'logical_switch_uuid': logical_switch_uuid}

@ -62,15 +62,6 @@ class L2GWTestCase(testlib_api.SqlTestCase):
"device_name": device_name}]}}
return data
def _get_l2_gateway_data_with_seg_id(self, name, device_name, seg_id):
"""Get l2 gateway data helper method."""
data = {"l2_gateway": {"name": name,
"devices":
[{"interfaces": [{"name": "port1",
"segmentation_id": [seg_id]}],
"device_name": device_name}]}}
return data
def _get_l2_gateway_data_with_multiple_segid(self, name, device_name):
"""Get l2 gateway data helper method for multiple seg id."""
data = {"l2_gateway": {"name": name,
@ -150,46 +141,6 @@ class L2GWTestCase(testlib_api.SqlTestCase):
result = self._create_l2gateway(data)
self.assertEqual(result['name'], name)
def test_l2_gateway_create_delete_with_seg_id_0(self):
name = "l2gw"
device_name = "device1"
seg_id = 0
data = self._get_l2_gateway_data_with_seg_id(name, device_name,
seg_id)
result = self._create_l2gateway(data)
self.assertEqual(name, result['name'])
result_devices = result['devices']
for device in result_devices:
result_interfaces = device["interfaces"]
for interface in result_interfaces:
result_interface_seg_id = interface["segmentation_id"]
result_interface_seg_id = list(map(int,
result_interface_seg_id))
self.assertEqual([seg_id], result_interface_seg_id,)
del_result = self._delete_l2gateway(result['id'])
self.assertIsNone(del_result)
def test_l2_gateway_connection_create_delete_with_seg_id_0(self):
name = "l2gw_con1"
device_name = "device_name1"
seg_id = 0
l2gw_data = self._get_l2_gateway_data_without_seg_id(name, device_name)
gw = self._create_l2gateway(l2gw_data)
net_data = self._get_nw_data()
net = self.plugin.create_network(self.ctx, net_data)
l2gw_id = gw['id']
data_con = {self.con_resource: {'l2_gateway_id': l2gw_id,
'network_id': net['id'],
'segmentation_id': seg_id}}
gw_con = self._create_l2gateway_connection(data_con)
exp_net_id = gw_con['network_id']
self.assertEqual(net['id'], exp_net_id)
list_con = self._list_l2gateway_connection()
self.assertIn('id', list_con[0])
self.assertEqual(seg_id, gw_con['segmentation_id'])
result = self._delete_l2gw_connection_by_l2gw_id(l2gw_id)
self.assertIsNone(result)
def _get_l2_gateway(self, l2gw_id):
with self.ctx.session.begin(subtransactions=True):
return self.mixin.get_l2_gateway(self.ctx, l2gw_id)

Loading…
Cancel
Save