[NSX-v3]: Fix L2GW connection-create
If no seg-id is passed during l2 gateway connection create, we must retrieve the seg-id from l2 gateway resource. This patch makes sure we retrieve the seg-id from the l2 gateway resources interface list. This patch also adds validation to make sure only one interface is created for a given L2GW resource. Change-Id: Ida957f7b2e048574ee7ea48958a875c679bb2d07 Closes-Bug: #1569622
This commit is contained in:
parent
1f219649ea
commit
1e2208170a
@ -126,6 +126,11 @@ class NsxV3Driver(l2gateway_db.L2GatewayMixin):
|
|||||||
if not uuidutils.is_uuid_like(devices[0]['device_name']):
|
if not uuidutils.is_uuid_like(devices[0]['device_name']):
|
||||||
msg = _("Device name must be configured with a UUID")
|
msg = _("Device name must be configured with a UUID")
|
||||||
raise n_exc.InvalidInput(error_message=msg)
|
raise n_exc.InvalidInput(error_message=msg)
|
||||||
|
# One L2 gateway must have only one interface defined.
|
||||||
|
interfaces = devices[0].get(l2gw_const.IFACE_NAME_ATTR)
|
||||||
|
if len(interfaces) > 1:
|
||||||
|
msg = _("Maximum of one interface is supported for one L2 gateway")
|
||||||
|
raise n_exc.InvalidInput(error_message=msg)
|
||||||
|
|
||||||
def create_l2_gateway(self, context, l2_gateway):
|
def create_l2_gateway(self, context, l2_gateway):
|
||||||
"""Create a logical L2 gateway."""
|
"""Create a logical L2 gateway."""
|
||||||
@ -169,8 +174,11 @@ class NsxV3Driver(l2gateway_db.L2GatewayMixin):
|
|||||||
# connection create. l2gateway_db_mixin makes sure that it is
|
# connection create. l2gateway_db_mixin makes sure that it is
|
||||||
# configured one way or the other.
|
# configured one way or the other.
|
||||||
seg_id = gw_connection.get(l2gw_const.SEG_ID)
|
seg_id = gw_connection.get(l2gw_const.SEG_ID)
|
||||||
if seg_id is None:
|
if not seg_id:
|
||||||
seg_id = devices[0]['interfaces'][0].get('segmentation_id')
|
# Seg-id was not passed as part of connection-create. Retrieve
|
||||||
|
# seg-id from L2 gateway's interface.
|
||||||
|
interface = self._get_l2_gw_interfaces(context, devices[0]['id'])
|
||||||
|
seg_id = interface[0].get(l2gw_const.SEG_ID)
|
||||||
self._validate_segment_id(seg_id)
|
self._validate_segment_id(seg_id)
|
||||||
try:
|
try:
|
||||||
tags = nsx_utils.build_v3_tags_payload(
|
tags = nsx_utils.build_v3_tags_payload(
|
||||||
|
@ -125,6 +125,19 @@ class TestNsxV3L2GatewayDriver(test_l2gw_db.L2GWTestCase,
|
|||||||
self.driver.create_l2_gateway,
|
self.driver.create_l2_gateway,
|
||||||
self.context, invalid_l2gw_dict)
|
self.context, invalid_l2gw_dict)
|
||||||
|
|
||||||
|
def test_create_l2_gateway_multiple_interfaces_fail(self):
|
||||||
|
invalid_l2gw_dict = {
|
||||||
|
"l2_gateway": {
|
||||||
|
"tenant_id": "fake_tenant_id",
|
||||||
|
"name": "invalid_l2gw",
|
||||||
|
"devices": [{"interfaces":
|
||||||
|
[{"name": "interface1"},
|
||||||
|
{"name": "interface2"}],
|
||||||
|
"device_name": "device1"}]}}
|
||||||
|
self.assertRaises(n_exc.InvalidInput,
|
||||||
|
self.driver.create_l2_gateway,
|
||||||
|
self.context, invalid_l2gw_dict)
|
||||||
|
|
||||||
def test_create_l2_gateway_invalid_device_name_fail(self):
|
def test_create_l2_gateway_invalid_device_name_fail(self):
|
||||||
invalid_l2gw_dict = {
|
invalid_l2gw_dict = {
|
||||||
"l2_gateway": {
|
"l2_gateway": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user