--- /dev/null
+Scatchpad
+
+mvn jacoco:report -Djacoco.dataFile='${project.build.directory}/code-coverage/jacoco-ut.exec'
+mvn sonar:sonar -Dsonar.host.url=http://sonar.onap.org
+
@Component
public class AaiSecurityProvider extends GenericSecurityProvider {
@Value("${trustedCertificatesForAai}")
- private String trustedCertificates;
+ private String trustedCertificatesForAai;
@Value("${skipCertificateVerificationForAai}")
- private boolean skipCertificateVerification;
+ private boolean skipCertificateVerificationForAai;
@Value("${skipHostnameVerificationForAai}")
- private boolean skipHostnameVerification;
+ private boolean skipHostnameVerificationForAai;
@Override
protected boolean skipHostnameVerification() {
- return skipHostnameVerification;
+ return skipHostnameVerificationForAai;
}
@Override
protected boolean skipCertificateVerification() {
- return skipCertificateVerification;
+ return skipCertificateVerificationForAai;
}
@Override
protected String trustedCertificates() {
- return trustedCertificates;
+ return trustedCertificatesForAai;
}
}
logicalInterface.setInterfaceRole(affectedCp.getCpdId());
logicalInterface.setMacaddr(affectedCp.getMacAddress());
logicalInterface.setProvStatus("active");
+ logicalInterface.setL3InterfaceIpv6AddressList(new ArrayList<>());
+ logicalInterface.setL3InterfaceIpv4AddressList(new ArrayList<>());
if (affectedCp.getIpAddress() != null) {
if (affectedCp.getIpAddress().contains(":")) {
L3InterfaceIpv6AddressList ipv6Address = new L3InterfaceIpv6AddressList();
ipv6Address.setL3InterfaceIpv6Address(affectedCp.getIpAddress());
ipv6Address.setNeutronNetworkId(affectedCp.getNetworkProviderId());
- if (logicalInterface.getL3InterfaceIpv6AddressList() == null) {
- logicalInterface.setL3InterfaceIpv6AddressList(new ArrayList<>());
- }
logicalInterface.getL3InterfaceIpv6AddressList().add(ipv6Address);
} else {
L3InterfaceIpv4AddressList ipv4Address = new L3InterfaceIpv4AddressList();
ipv4Address.setL3InterfaceIpv4Address(affectedCp.getIpAddress());
ipv4Address.setNeutronNetworkId(affectedCp.getNetworkProviderId());
- if (logicalInterface.getL3InterfaceIpv4AddressList() == null) {
- logicalInterface.setL3InterfaceIpv4AddressList(new ArrayList<>());
- }
logicalInterface.getL3InterfaceIpv4AddressList().add(ipv4Address);
}
}
@ResponseBody
public JobInfo terminateVnf(@RequestBody VnfTerminateRequest request, @PathVariable("vnfmId") String vnfmId, @PathVariable("vnfId") String vnfInstanceId, HttpServletResponse httpResponse) {
logger.info("REST: Terminate VNF");
- return lifecycleManager.terminateVnf(vnfmId, vnfInstanceId, request, httpResponse);
+ return lifecycleManager.terminateAndDelete(vnfmId, vnfInstanceId, request, httpResponse);
}
/**
* @param httpResponse the HTTP response
* @return the job for polling the progress of the termination
*/
- public JobInfo terminateVnf(String vnfmId, String vnfId, VnfTerminateRequest request, HttpServletResponse httpResponse) {
+ public JobInfo terminateAndDelete(String vnfmId, String vnfId, VnfTerminateRequest request, HttpServletResponse httpResponse) {
logOperationInput(vnfId, "termination", request);
return scheduleExecution(vnfId, httpResponse, "terminate", jobInfo -> {
TerminateVnfRequest cbamRequest = new TerminateVnfRequest();
cbamRequest.setAdditionalParams(new Gson().toJsonTree(jobInfo).getAsJsonObject());
com.nokia.cbam.lcm.v32.model.VnfInfo vnf = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
if (vnf.getInstantiationState() == INSTANTIATED) {
- terminateVnf(vnfmId, vnfId, jobInfo, cbamRequest, vnf);
+ terminateAndDelete(vnfmId, vnfId, jobInfo, cbamRequest, vnf);
} else {
- cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
+ logger.debug("The VNF {} with identifier is not instantiated no termination required", vnf.getId());
+ deleteVnf(vnfmId, vnfId);
}
});
}
- private void terminateVnf(String vnfmId, String vnfId, JobInfo jobInfo, TerminateVnfRequest cbamRequest, com.nokia.cbam.lcm.v32.model.VnfInfo vnf) {
+ private void terminateAndDelete(String vnfmId, String vnfId, JobInfo jobInfo, TerminateVnfRequest cbamRequest, com.nokia.cbam.lcm.v32.model.VnfInfo vnf) {
String vimId = getVimIdFromInstantiationRequest(vnfmId, vnf);
grantManager.requestGrantForTerminate(vnfmId, vnfId, vimId, getVnfdIdFromModifyableAttributes(vnf), vnf, jobInfo.getJobId());
OperationExecution terminationOperation = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdTerminatePost(vnfId, cbamRequest, NOKIA_LCM_API_VERSION).blockingFirst();
OperationExecution finishedOperation = waitForOperationToFinish(vnfmId, vnfId, terminationOperation.getId());
if (finishedOperation.getStatus() == FINISHED) {
notificationManager.waitForTerminationToBeProcessed(finishedOperation.getId());
- logger.info("Deleting VNF with {}", vnfId);
- cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
- logger.info("VNF with {} has been deleted", vnfId);
+ deleteVnf(vnfmId, vnfId);
} else {
logger.error("Unable to terminate VNF the operation did not finish with success");
}
}
+ private void deleteVnf(String vnfmId, String vnfId) {
+ logger.info("Deleting VNF with {} identifier", vnfId);
+ cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
+ logger.info("The VNF with {} identifier has been deleted", vnfId);
+ }
+
private String getVimIdFromInstantiationRequest(String vnfmId, com.nokia.cbam.lcm.v32.model.VnfInfo vnf) {
OperationExecution lastInstantiation = findLastInstantiation(vnf.getOperationExecutions());
Object operationParameters = cbamRestApiProvider.getCbamOperationExecutionApi(vnfmId).operationExecutionsOperationExecutionIdOperationParamsGet(lastInstantiation.getId(), NOKIA_LCM_API_VERSION).blockingFirst();
logger.error("Unable to " + operation + " VNF with " + vnfId + " identifier", e);
jobManager.jobFinished(jobInfo.getJobId());
throw e;
- } catch (Exception e) {
- String msg = "Unable to " + operation + " VNF with " + vnfId + " identifier";
- logger.error(msg, e);
- //the job can only be signaled to be finished after the error is logged
- jobManager.jobFinished(jobInfo.getJobId());
- throw new UserVisibleError(msg, e);
}
jobManager.jobFinished(jobInfo.getJobId());
});
this.vnfInfo = vnfInfo;
this.vnfdId = vnfdId;
}
-
- public com.nokia.cbam.lcm.v32.model.VnfInfo getVnfInfo() {
- return vnfInfo;
- }
-
}
}
private AAIRestApiProvider aaiRestApiProvider;
@Mock
private HostnameVerifier hostnameVerifier;
- private AaiSecurityProvider aaiSecurityProvider = spy(new AaiSecurityProvider());
+ private AaiSecurityProvider aaiSecurityProviderReal = new AaiSecurityProvider();
+ private AaiSecurityProvider aaiSecurityProvider = spy(aaiSecurityProviderReal);
@Before
public void init() {
*/
@Test
public void testApiClientBuilder() throws Exception {
- setField(aaiSecurityProvider, "skipCertificateVerification", true);
- setField(aaiSecurityProvider, "skipHostnameVerification", true);
+ when(aaiSecurityProvider.skipCertificateVerification()).thenReturn(true);
+ when(aaiSecurityProvider.skipHostnameVerification()).thenReturn(true);
setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiUsername}", "username");
setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiPassword}", "aaiPassword");
ResultCaptor<SSLSocketFactory> sslSocketFactoryResultCaptor = new ResultCaptor<>();
*/
@Test
public void testApiClientBuilderMissingSlash() throws Exception {
- setField(aaiSecurityProvider, "skipCertificateVerification", true);
- setField(aaiSecurityProvider, "skipHostnameVerification", true);
+ when(aaiSecurityProvider.skipCertificateVerification()).thenReturn(true);
+ when(aaiSecurityProvider.skipHostnameVerification()).thenReturn(true);
setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiUsername}", "username");
setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiPassword}", "aaiPassword");
ResultCaptor<SSLSocketFactory> sslSocketFactoryResultCaptor = new ResultCaptor<>();
*/
@Test
public void testApiClientBuilderForCloud() throws Exception {
- setField(aaiSecurityProvider, "skipCertificateVerification", true);
- setField(aaiSecurityProvider, "skipHostnameVerification", true);
+ when(aaiSecurityProvider.skipCertificateVerification()).thenReturn(true);
+ when(aaiSecurityProvider.skipHostnameVerification()).thenReturn(true);
setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiUsername}", "username");
setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiPassword}", "aaiPassword");
ResultCaptor<SSLSocketFactory> sslSocketFactoryResultCaptor = new ResultCaptor<>();
*/
@Test
public void testApiClientBuilderForExternalSystems() throws Exception {
- setField(aaiSecurityProvider, "skipCertificateVerification", true);
- setField(aaiSecurityProvider, "skipHostnameVerification", true);
+ when(aaiSecurityProvider.skipCertificateVerification()).thenReturn(true);
+ when(aaiSecurityProvider.skipHostnameVerification()).thenReturn(true);
setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiUsername}", "username");
setFieldWithPropertyAnnotation(aaiRestApiProvider, "${aaiPassword}", "aaiPassword");
ResultCaptor<SSLSocketFactory> sslSocketFactoryResultCaptor = new ResultCaptor<>();
assertEquals("mac", actualInterface.getMacaddr());
assertEquals("active", actualInterface.getProvStatus());
assertEquals(1, actualInterface.getL3InterfaceIpv4AddressList().size());
- assertEquals(null, actualInterface.getL3InterfaceIpv6AddressList());
+ assertEquals(0, actualInterface.getL3InterfaceIpv6AddressList().size());
assertEquals("networkProviderId", actualInterface.getL3InterfaceIpv4AddressList().get(0).getNeutronNetworkId());
assertEquals("1.2.3.4", actualInterface.getL3InterfaceIpv4AddressList().get(0).getL3InterfaceIpv4Address());
assertRelation(actualInterface.getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
assertEquals("cpdId", actualInterface.getInterfaceRole());
assertEquals("mac", actualInterface.getMacaddr());
assertEquals("active", actualInterface.getProvStatus());
- assertEquals(null, actualInterface.getL3InterfaceIpv6AddressList());
- assertEquals(null, actualInterface.getL3InterfaceIpv4AddressList());
+ assertEquals(0, actualInterface.getL3InterfaceIpv6AddressList().size());
+ assertEquals(0, actualInterface.getL3InterfaceIpv4AddressList().size());
assertRelation(actualInterface.getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
VOID_OBSERVABLE.assertCalled();
}
assertEquals("mac", actualInterface.getMacaddr());
assertEquals("active", actualInterface.getProvStatus());
assertEquals(1, actualInterface.getL3InterfaceIpv4AddressList().size());
- assertEquals(null, actualInterface.getL3InterfaceIpv6AddressList());
+ assertEquals(0, actualInterface.getL3InterfaceIpv6AddressList().size());
assertEquals("networkProviderId", actualInterface.getL3InterfaceIpv4AddressList().get(0).getNeutronNetworkId());
assertEquals("1.2.3.4", actualInterface.getL3InterfaceIpv4AddressList().get(0).getL3InterfaceIpv4Address());
assertEquals("v3", lInterface.getResourceVersion());
assertEquals("cpdId", actualInterface.getInterfaceRole());
assertEquals("mac", actualInterface.getMacaddr());
assertEquals("active", actualInterface.getProvStatus());
- assertEquals(null, actualInterface.getL3InterfaceIpv4AddressList());
+ assertEquals(0, actualInterface.getL3InterfaceIpv4AddressList().size());
assertEquals(1, actualInterface.getL3InterfaceIpv6AddressList().size());
assertEquals("networkProviderId", actualInterface.getL3InterfaceIpv6AddressList().get(0).getNeutronNetworkId());
assertEquals("::", actualInterface.getL3InterfaceIpv6AddressList().get(0).getL3InterfaceIpv6Address());
import com.nokia.cbam.lcm.v32.model.AffectedVnfc;
import com.nokia.cbam.lcm.v32.model.ResourceHandle;
+import io.reactivex.Observable;
import java.util.ArrayList;
+import java.util.NoSuchElementException;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
when(aaiRestApiProvider.getNetworkApi()).thenReturn(networkApi);
}
+
+ /**
+ * test create
+ */
+ @Test
+ public void testCreate() throws Exception {
+ AffectedVnfc affectedVnfc = new AffectedVnfc();
+ affectedVnfc.setComputeResource(new ResourceHandle());
+ affectedVnfc.getComputeResource().setResourceId("serverProviderId");
+ affectedVnfc.setId("vnfcId");
+ when(networkApi.getNetworkVnfcsVnfc("myVnfId_vnfcId", null, null, null, null, null, null, null, null, null)).thenReturn(Observable.error(new NoSuchElementException()));
+ when(networkApi.createOrUpdateNetworkVnfcsVnfc(eq("myVnfId_vnfcId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
+ //when
+ vnfcManager.update(VIM_ID, "myTenantPrivderId", VNF_ID, affectedVnfc, true);
+ //verify
+ Vnfc vnfc = payload.getValue();
+ assertEquals("myVnfId_vnfcId", vnfc.getVnfcName());
+ assertEquals("vnfcId", vnfc.getNfcFunction());
+ assertEquals("vnfcId", vnfc.getNfcNamingCode());
+ assertRelation(payload.getValue().getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
+
+ assertRelation(vnfc.getRelationshipList(), "vserver",
+ buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)),
+ buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)),
+ buildRelationshipData("tenant.tenant-id", "myTenantPrivderId"),
+ buildRelationshipData("vserver.vserver-id", "serverProviderId"));
+ assertEquals(2, vnfc.getRelationshipList().size());
+ VOID_OBSERVABLE.assertCalled();
+ }
+
/**
* test update
*/
//when
lcmApi.terminateVnf(req, VNFM_ID, VNF_ID, httpResponse);
//verify
- verify(lifecycleManager).terminateVnf(VNFM_ID, VNF_ID, req, httpResponse);
+ verify(lifecycleManager).terminateAndDelete(VNFM_ID, VNF_ID, req, httpResponse);
verify(logger).info("REST: Terminate VNF");
}
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.lang.reflect.Field;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.concurrent.Callable;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
try {
field.setAccessible(true);
field.set(obj, value);
+ return;
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
}
+ throw new NoSuchElementException("The " + obj.getClass() + " does not have a filed with " + key + " annotation");
}
protected static class VoidObservable {
JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } ");
when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters));
//when
- JobInfo jobInfo = lifecycleManager.terminateVnf(VNFM_ID, VNF_ID, terminationRequest, restResponse);
+ JobInfo jobInfo = lifecycleManager.terminateAndDelete(VNFM_ID, VNF_ID, terminationRequest, restResponse);
//verify
waitForJobToFinishInJobManager(finished);
assertEquals(1, actualTerminationRequest.getAllValues().size());
vnfdId.setValue(ONAP_CSAR_ID);
vnfInfo.getExtensions().add(vnfdId);
JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } ");
+ when(vnfApi.vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(VOID_OBSERVABLE.value());
when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters));
//when
- JobInfo jobInfo = lifecycleManager.terminateVnf(VNFM_ID, VNF_ID, terminationRequest, restResponse);
+ lifecycleManager.terminateAndDelete(VNFM_ID, VNF_ID, terminationRequest, restResponse);
//verify
boolean deleted = false;
while (!deleted) {
try {
- Mockito.
- verify(vnfApi).vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION);
+ verify(vnfApi).vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION);
deleted = true;
} catch (Error e) {
}
}
verify(vfcGrantManager, never()).requestGrantForTerminate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, vnfInfo, JOB_ID);
verify(notificationManager, never()).waitForTerminationToBeProcessed("terminationId");
+ verify(logger).debug("The VNF {} with identifier is not instantiated no termination required", VNF_ID);
+ verify(logger).info("Deleting VNF with {} identifier", VNF_ID);
+ verify(logger).info("The VNF with {} identifier has been deleted", VNF_ID);
+ VOID_OBSERVABLE.assertCalled();
}
/**
return buildObservable(operationExecutions);
});
//when
- JobInfo jobInfo = lifecycleManager.terminateVnf(VNFM_ID, VNF_ID, terminationRequest, restResponse);
+ JobInfo jobInfo = lifecycleManager.terminateAndDelete(VNFM_ID, VNF_ID, terminationRequest, restResponse);
//verify
waitForJobToFinishInJobManager(finished);
verify(vnfApi, times(1001)).vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION);
}
});
//when
- JobInfo jobInfo = lifecycleManager.terminateVnf(VNFM_ID, VNF_ID, terminationRequest, restResponse);
+ JobInfo jobInfo = lifecycleManager.terminateAndDelete(VNFM_ID, VNF_ID, terminationRequest, restResponse);
//verify
waitForJobToFinishInJobManager(finished);
verify(vnfApi, times(101)).vnfsVnfInstanceIdOperationExecutionsGet(VNF_ID, NOKIA_LCM_API_VERSION);
JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } ");
when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters));
//when
- JobInfo jobInfo = lifecycleManager.terminateVnf(VNFM_ID, VNF_ID, terminationRequest, restResponse);
+ JobInfo jobInfo = lifecycleManager.terminateAndDelete(VNFM_ID, VNF_ID, terminationRequest, restResponse);
//verify
waitForJobToFinishInJobManager(finished);
assertEquals(1, actualTerminationRequest.getAllValues().size());
JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } ");
when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters));
//when
- JobInfo jobInfo = lifecycleManager.terminateVnf(VNFM_ID, VNF_ID, terminationRequest, restResponse);
+ JobInfo jobInfo = lifecycleManager.terminateAndDelete(VNFM_ID, VNF_ID, terminationRequest, restResponse);
//verify
waitForJobToFinishInJobManager(finished);
assertEquals(1, actualTerminationRequest.getAllValues().size());
JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } ");
when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters));
//when
- JobInfo jobInfo = lifecycleManager.terminateVnf(VNFM_ID, VNF_ID, terminationRequest, restResponse);
+ JobInfo jobInfo = lifecycleManager.terminateAndDelete(VNFM_ID, VNF_ID, terminationRequest, restResponse);
//verify
waitForJobToFinishInJobManager(finished);
assertEquals(0, actualTerminationRequest.getAllValues().size());
JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } ");
when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters));
//when
- JobInfo jobInfo = lifecycleManager.terminateVnf(VNFM_ID, VNF_ID, terminationRequest, restResponse);
+ JobInfo jobInfo = lifecycleManager.terminateAndDelete(VNFM_ID, VNF_ID, terminationRequest, restResponse);
//verify
waitForJobToFinishInJobManager(finished);
assertEquals(1, actualTerminationRequest.getAllValues().size());