Fixed a bug in segment creation and deletion

The segment db has 'segmentation_id' as a field where as the EOS API
expects segmentationId. While creating and deleting segments, the
segment list from the db was being passed to the API which resulted
in failures. This patch ensures that the segment data from the db
is massaged into the right format.

Change-Id: I35b5c7cf147ae2355dadfdeac2c8f2f69aa7107b
changes/00/401400/2
Shashank Hegde 6 years ago
parent c266de0845
commit d009fdbd95

@ -788,12 +788,31 @@ class AristaRPCWrapperJSON(AristaRPCWrapperBase):
def create_network_segments(self, tenant_id, network_id,
network_name, segments):
segment_data = []
for segment in segments:
segmentType = 'static'
if segment.get('is_dynamic', False):
segmentType = 'dynamic'
segment_data.append({
'id': segment['id'],
'networkId': network_id,
'type': segment['network_type'],
'segmentationId': segment['segmentation_id'],
'segmentType': segmentType,
})
path = 'region/' + self.region + '/segment'
self._send_api_request(path, 'POST', segments)
self._send_api_request(path, 'POST', segment_data)
def delete_network_segments(self, segments):
segment_data = []
for segment in segments:
segment_data.append({
'id': segment['id'],
})
path = 'region/' + self.region + '/segment'
self._send_api_request(path, 'DELETE', segments)
self._send_api_request(path, 'DELETE', segment_data)
def delete_network_bulk(self, tenant_id, network_id_list, sync=False):
path = 'region/' + self.region + '/network'

@ -216,11 +216,10 @@ class AristaDriver(driver_api.MechanismDriver):
def delete_network_postcommit(self, context):
"""Send network delete request to Arista HW."""
network = context.current
segments = []
segments = context.network_segments
if not self.rpc.hpb_supported():
# Hierarchical port binding is not supported by CVX, only
# send the request if network type is VLAN.
segments = context.network_segments
if segments[0][driver_api.NETWORK_TYPE] != p_const.TYPE_VLAN:
# If networtk type is not VLAN, do nothing
return

@ -403,6 +403,48 @@ class TestAristaJSONRPCWrapper(testlib_api.SqlTestCase):
]
self._verify_send_api_request_call(mock_send_api_req, calls)
@patch(JSON_SEND_FUNC)
def test_create_network_segments(self, mock_send_api_req):
segments = [{'segmentation_id': 101,
'physical_network': 'default',
'id': 'segment_id_1',
'is_dynamic': False,
'network_type': 'vlan'},
{'segmentation_id': 102,
'physical_network': 'default',
'id': 'segment_id_2',
'is_dynamic': True,
'network_type': 'vlan'}]
self.drv.create_network_segments('t1', 'n1', 'net1', segments)
calls = [
('region/RegionOne/segment', 'POST',
[{'id': 'segment_id_1', 'networkId': 'n1', 'type': 'vlan',
'segmentationId': 101, 'segmentType': 'static'},
{'id': 'segment_id_2', 'networkId': 'n1', 'type': 'vlan',
'segmentationId': 102, 'segmentType': 'dynamic'}])
]
self._verify_send_api_request_call(mock_send_api_req, calls)
@patch(JSON_SEND_FUNC)
def test_delete_network_segments(self, mock_send_api_req):
segments = [{'segmentation_id': 101,
'physical_network': 'default',
'id': 'segment_id_1',
'is_dynamic': False,
'network_type': 'vlan'},
{'segmentation_id': 102,
'physical_network': 'default',
'id': 'segment_id_2',
'is_dynamic': True,
'network_type': 'vlan'}]
self.drv.delete_network_segments(segments)
calls = [
('region/RegionOne/segment', 'DELETE',
[{'id': 'segment_id_1'},
{'id': 'segment_id_2'}])
]
self._verify_send_api_request_call(mock_send_api_req, calls)
@patch(JSON_SEND_FUNC)
def test_create_instance_bulk(self, mock_send_api_req):
tenant_id = 'ten-3'

@ -242,7 +242,8 @@ class AristaDriverTestCase(testlib_api.SqlTestCase):
self.drv.delete_network_postcommit(network_context)
expected_calls = [
mock.call.hpb_supported(),
mock.call.delete_network(tenant_id, network_id, []),
mock.call.delete_network(tenant_id, network_id,
network_context.network_segments),
mock.call.num_nets_provisioned(tenant_id),
mock.call.num_vms_provisioned(tenant_id),
mock.call.forget_tenant(tenant_id),
@ -266,7 +267,8 @@ class AristaDriverTestCase(testlib_api.SqlTestCase):
self.drv.delete_network_postcommit(network_context)
expected_calls += [
mock.call.hpb_supported(),
mock.call.delete_network(INTERNAL_TENANT_ID, network_id, []),
mock.call.delete_network(INTERNAL_TENANT_ID, network_id,
network_context.network_segments),
mock.call.num_nets_provisioned(INTERNAL_TENANT_ID),
mock.call.num_vms_provisioned(INTERNAL_TENANT_ID),
mock.call.forget_tenant(INTERNAL_TENANT_ID),

Loading…
Cancel
Save