Skip to content

Commit

Permalink
Fixes #596 :Check for SFC virtual system list , before binding. Need…
Browse files Browse the repository at this point in the history
… to have atleast one virtual system chained to sfc to bind
  • Loading branch information
karimull-intc committed Nov 2, 2017
1 parent 7500b5a commit e29ccd6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,11 @@ private ServiceFunctionChain validateAndLoadSfcBind(EntityManager em, BindSecuri
}

List<Long> sfcVsIdList = sfc.getVirtualSystems().stream().map(vs -> vs.getId()).collect(Collectors.toList());
if (sfcVsIdList.isEmpty()) {
throw new VmidcBrokerValidationException(String.format(
"Service Function Chain : %s has no Virtual System references, cannot be binded",
sfc.getName()));
}
List<Long> sfcVsIdOrderList = sfc.getVirtualSystems().stream().map(vs -> vs.getId()).collect(Collectors.toList());

List<VirtualSystemPolicyBindingDto> servicesToBindTo = request.getServicesToBindTo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,30 @@ public void testValidate_WhenRequestSfcBindFlagIsFalseForVcOfTypeNeutronSfc_Thro
this.bindSecurityGroupService.dispatch(request);
}

@Test
public void testValidate_WhenSfcVirtualSystemListIsEmpty_ThrowsValidationException() throws Exception {
// Arrange
BindSecurityGroupRequest request = createRequest(VALID_ID, VALID_ID, VALID_ID);
ServiceFunctionChain sfc = createSFC(VALID_ID, VALID_ID);
List<VirtualSystem> vsList = new ArrayList<VirtualSystem>();
sfc.setVirtualSystems(vsList);
VirtualSystemPolicyBindingDto serviceToBindTo = createRequestWithService(INVALID_ID);
request.addServiceToBindTo(serviceToBindTo);
request.setBindSfc(true);

Mockito.when(this.em.find(Mockito.eq(VirtualizationConnector.class), Mockito.eq(VALID_ID)))
.thenReturn(VALID_SG.getVirtualizationConnector());
Mockito.when(this.em.find(Mockito.eq(ServiceFunctionChain.class), Mockito.eq(VALID_ID))).thenReturn(sfc);
Mockito.when(this.bindSecurityGroupService.apiFactoryService.supportsNeutronSFC(VALID_SG)).thenReturn(true);
this.exception.expect(VmidcBrokerValidationException.class);
this.exception.expectMessage(String.format(
"Cannot bind Service Function Chain : %s with empty Virtual System list",
sfc.getName()));

// Act
this.bindSecurityGroupService.dispatch(request);
}

private static SecurityGroup createSecurityGroup(Long id, boolean markedFOrDeletion) {
VirtualizationConnector vc = new VirtualizationConnector();
vc.setId(id);
Expand Down

0 comments on commit e29ccd6

Please sign in to comment.