package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
+import com.google.common.base.Joiner;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import static com.google.common.base.Splitter.on;
import static com.google.common.collect.Iterables.find;
+import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Lists.newArrayList;
+import static com.google.common.collect.Ordering.natural;
import static com.google.common.collect.Sets.newHashSet;
import static com.nokia.cbam.lcm.v32.model.InstantiationState.INSTANTIATED;
import static com.nokia.cbam.lcm.v32.model.OperationStatus.FINISHED;
*/
public static final String EXTERNAL_VNFM_ID = "externalVnfmId";
public static final String SCALE_OPERATION_NAME = "scale";
+ public static final String ETSI_CONFIG = "etsi_config";
+ public static final String PROPERTIES = "properties";
private static Logger logger = getLogger(LifecycleManager.class);
private final CatalogManager catalogManager;
private final IGrantManager grantManager;
@SuppressWarnings("squid:S00107") //wrapping them into an object makes the code less readable
private void instantiateVnf(String vnfmId, List<ExtVirtualLinkInfo> extVirtualLinkInfos, AdditionalParameters additionalParameters, String onapVnfdId, String vnfmVnfdId, String vnfId, String vimId, JobInfo jobInfo) {
String vnfdContent = catalogManager.getCbamVnfdContent(vnfmId, vnfmVnfdId);
+ addSpecifiedExtensions(vnfmId, vnfId, additionalParameters);
GrantVNFResponseVim vim = grantManager.requestGrantForInstantiate(vnfmId, vnfId, vimId, onapVnfdId, additionalParameters.getInstantiationLevel(), vnfdContent, jobInfo.getJobId());
handleBackwardIncompatibleApiChangesInVfc(vim);
VimInfo vimInfo = vimInfoProvider.getVimInfo(vim.getVimId());
}
private AdditionalParameters convertInstantiationAdditionalParams(String csarId, Object additionalParams) {
- JsonObject inputs = child(new Gson().toJsonTree(additionalParams).getAsJsonObject(), "inputs");
+ JsonObject root = new Gson().toJsonTree(additionalParams).getAsJsonObject();
+ if(root.has(PROPERTIES)){
+ JsonObject properties = new JsonParser().parse(root.get(PROPERTIES).getAsString()).getAsJsonObject();
+ if(properties.has(ETSI_CONFIG)){
+ JsonElement etsiConfig = properties.get(ETSI_CONFIG);
+ return new Gson().fromJson(etsiConfig.getAsString(), AdditionalParameters.class);
+ }
+ else{
+ logger.info("The instantiation input for VNF with {} CSAR id does not have an " + ETSI_CONFIG +" section", csarId);
+ }
+ }
+ else{
+ logger.info("The instantiation input for VNF with {} CSAR id does not have a properties section", csarId);
+ }
+ JsonObject inputs = child(root, "inputs");
if (!inputs.has(csarId)) {
- throw buildFatalFailure(logger, "The additional parameter section does not contain setting for VNF with " + csarId + " CSAR id");
+ throw buildFatalFailure(logger, "The additional parameter section does not contain settings for VNF with " + csarId + " CSAR id");
}
JsonElement additionalParamsForVnf = new JsonParser().parse(inputs.get(csarId).getAsString());
return new Gson().fromJson(additionalParamsForVnf, AdditionalParameters.class);
private String getFlavorId(String vnfdContent) {
JsonObject root = new Gson().toJsonTree(new Yaml().load(vnfdContent)).getAsJsonObject();
JsonObject capabilities = child(child(child(root, "topology_template"), "substitution_mappings"), "capabilities");
- JsonObject deploymentFlavorProperties = child(child(capabilities, "deployment_flavour"), "properties");
+ JsonObject deploymentFlavorProperties = child(child(capabilities, "deployment_flavour"), PROPERTIES);
return childElement(deploymentFlavorProperties, "flavour_id").getAsString();
}
private void addVnfdIdToVnfModifyableAttributeExtensions(String vnfmId, String vnfId, String onapCsarId) {
ModifyVnfInfoRequest request = new ModifyVnfInfoRequest();
+ request.setExtensions(new ArrayList<>());
VnfProperty onapCsarIdProperty = new VnfProperty();
onapCsarIdProperty.setName(ONAP_CSAR_ID);
onapCsarIdProperty.setValue(onapCsarId);
- request.setExtensions(new ArrayList<>());
request.getExtensions().add(onapCsarIdProperty);
VnfProperty externalVnfmIdProperty = new VnfProperty();
externalVnfmIdProperty.setName(EXTERNAL_VNFM_ID);
externalVnfmIdProperty.setValue(vnfmId);
request.getExtensions().add(externalVnfmIdProperty);
- request.setVnfConfigurableProperties(null);
+ executeModifyVnfInfo(vnfmId, vnfId, request);
+ }
+
+ private void executeModifyVnfInfo(String vnfmId, String vnfId, ModifyVnfInfoRequest request) {
try {
OperationExecution operationExecution = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdPatch(vnfId, request, NOKIA_LCM_API_VERSION).blockingFirst();
waitForOperationToFinish(vnfmId, vnfId, operationExecution.getId());
} catch (Exception e) {
- throw buildFatalFailure(logger, "Unable to set the " + ONAP_CSAR_ID + " property on the VNF", e);
+ String properties = Joiner.on(",").join(natural().sortedCopy(transform(request.getExtensions(), VnfProperty::getName)));
+ throw buildFatalFailure(logger, "Unable to set the " + properties + " properties on the VNF with " + vnfId + " identifier", e);
+ }
+ }
+
+ private void addSpecifiedExtensions(String vnfmId, String vnfId, AdditionalParameters additionalParameters){
+ if(!additionalParameters.getExtensions().isEmpty()){
+ ModifyVnfInfoRequest request = new ModifyVnfInfoRequest();
+ request.setExtensions(new ArrayList<>());
+ request.getExtensions().addAll(additionalParameters.getExtensions());
+ executeModifyVnfInfo(vnfmId, vnfId, request);
+ }
+ else{
+ logger.info("No extensions specified for VNF with {} identifier", vnfId);
}
}
import java.nio.file.Paths;
import java.util.*;
import javax.servlet.http.HttpServletResponse;
+import org.assertj.core.util.Lists;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@Test
public void testInstantiation() throws Exception {
//given
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
-
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO, true);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
assertTrue(actualVim.getInterfaceInfo().isSkipCertificateVerification());
assertTrue(actualVim.getInterfaceInfo().isSkipCertificateHostnameCheck());
- assertEquals(1, actualVnfModifyRequest.getAllValues().size());
- assertEquals(2, actualVnfModifyRequest.getValue().getExtensions().size());
- assertEquals(LifecycleManager.ONAP_CSAR_ID, actualVnfModifyRequest.getValue().getExtensions().get(0).getName());
- assertEquals(ONAP_CSAR_ID, actualVnfModifyRequest.getValue().getExtensions().get(0).getValue());
- assertEquals(LifecycleManager.EXTERNAL_VNFM_ID, actualVnfModifyRequest.getValue().getExtensions().get(1).getName());
- assertEquals(VNFM_ID, actualVnfModifyRequest.getValue().getExtensions().get(1).getValue());
+ assertEquals(2, actualVnfModifyRequest.getAllValues().size());
+ assertEquals(2, actualVnfModifyRequest.getAllValues().get(0).getExtensions().size());
+ assertEquals(LifecycleManager.ONAP_CSAR_ID, actualVnfModifyRequest.getAllValues().get(0).getExtensions().get(0).getName());
+ assertEquals(ONAP_CSAR_ID, actualVnfModifyRequest.getAllValues().get(0).getExtensions().get(0).getValue());
+ assertEquals(LifecycleManager.EXTERNAL_VNFM_ID, actualVnfModifyRequest.getAllValues().get(0).getExtensions().get(1).getName());
+ assertEquals(VNFM_ID, actualVnfModifyRequest.getAllValues().get(0).getExtensions().get(1).getValue());
+
+ assertEquals(3, actualVnfModifyRequest.getAllValues().get(1).getExtensions().size());
+
+ VnfProperty p1 = new VnfProperty();
+ p1.setName("n1");
+ p1.setValue(Lists.newArrayList("a", "b"));
+ VnfProperty p2 = new VnfProperty();
+ p2.setName("n2");
+ p2.setValue("a");
+ VnfProperty p3 = new VnfProperty();
+ p2.setName("n2");
+ JsonObject o = new JsonObject();
+ p2.setValue(o);
+ o.addProperty("a", "b");
+ assertEquals(p1, actualVnfModifyRequest.getAllValues().get(1).getExtensions().get(0));
+ assertEquals("n2", actualVnfModifyRequest.getAllValues().get(1).getExtensions().get(1).getName());
+ HashMap<String, String> expected = new HashMap<>();
+ expected.put("a", "b");
+ assertEquals(expected, actualVnfModifyRequest.getAllValues().get(1).getExtensions().get(1).getValue());
+ assertEquals(p3, actualVnfModifyRequest.getAllValues().get(1).getExtensions().get(2));
//the 3.2 API does not accept empty array
assertNull(actualVnfModifyRequest.getValue().getVnfConfigurableProperties());
verify(jobManager).spawnJob(VNF_ID, restResponse);
verify(logger).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("creation"), eq("not yet specified"), anyString());
verify(logger).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("instantiation"), eq(VNF_ID), anyString());
+ verify(logger).info("The instantiation input for VNF with {} CSAR id does not have a properties section", ONAP_CSAR_ID);
}
/**
@Test
public void testInstantiationWithInvalidVimType() throws Exception {
//given
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OTHER_VIM_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OTHER_VIM_INFO, false);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
when(logger.isInfoEnabled()).thenReturn(false);
//when
*/
@Test
public void testInstantiationV2WithSsl() throws Exception {
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO, false);
when(logger.isInfoEnabled()).thenReturn(false);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
*/
@Test
public void testInstantiationV2WithoutSsl() throws Exception {
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO, false);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
*/
@Test
public void testInstantiationV3() throws Exception {
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO, false);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
@Test
public void testInstantiationNoVimId() throws Exception {
//given
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO, false);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
*/
@Test
public void testInstantiationV3WithSsl() throws Exception {
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO, false);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
*/
@Test
public void testInstantiationV3WithNonSpecifiedSsl() throws Exception {
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO, false);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
public void testInstantiationV3WithNoDomain() throws Exception {
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
additionalParam.setDomain("myDomain");
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO, false);
vimInfo.setDomain(null);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
*/
@Test
public void testInstantiationV3WithNoDomainFail() throws Exception {
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO, false);
vimInfo.setDomain(null);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
*/
@Test
public void testInstantiationVcloud() throws Exception {
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.VMWARE_VCLOUD_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.VMWARE_VCLOUD_INFO, false);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
*/
@Test
public void testInstantiationVcloudWithSsl() throws Exception {
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.VMWARE_VCLOUD_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.VMWARE_VCLOUD_INFO, false);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
*/
@Test
public void testInstantiationVcloudWithNonSecifedSSl() throws Exception {
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.VMWARE_VCLOUD_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.VMWARE_VCLOUD_INFO, false);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
*/
@Test
public void testFailureInTheInstantiationRequest() throws Exception {
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO, false);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
*/
@Test
public void testVfcFailsToSendVimId() throws Exception {
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO, false);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
*/
@Test
public void testVfcFailsToSendAccessInfo() throws Exception {
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO, false);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
*/
@Test
public void testFailureInTheOperationExecutionPollingDuringInstantiationRequest() throws Exception {
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO, false);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
@Test
public void failureInVnfCreationIsPropagated() throws Exception {
//given
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO, false);
RuntimeException expectedException = new RuntimeException();
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenThrow(expectedException);
@Test
public void failureInVnfModificationIsPropagated() throws Exception {
//given
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO, false);
RuntimeException expectedException = new RuntimeException();
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
fail();
} catch (RuntimeException e) {
assertEquals(expectedException, e.getCause().getCause());
- verify(logger).error("Unable to set the onapCsarId property on the VNF", expectedException);
+ verify(logger).error("Unable to set the externalVnfmId,onapCsarId properties on the VNF with " + VNF_ID +" identifier", expectedException);
}
}
*/
@Test
public void testFailureInQueryVimInfo() throws Exception {
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO, false);
when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
grantResponse.setVimId(VIM_ID);
@Test
public void testMissingVnfParameters() throws Exception {
//given
- VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO);
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V2_INFO, false);
String src = "{ \"inputs\" : { \"vnfs\" : { \"" + ONAP_CSAR_ID + "invalid" + "\" : {}}}, \"vimId\" : \"" + VIM_ID + "\"}";
instantiationRequest.setAdditionalParam(new JsonParser().parse(src));
//when
VnfInstantiateResponse response = lifecycleManager.createAndInstantiate(VNFM_ID, instantiationRequest, restResponse);
fail();
} catch (Exception e) {
- assertEquals("The additional parameter section does not contain setting for VNF with myOnapCsarId CSAR id", e.getMessage());
- verify(logger).error("The additional parameter section does not contain setting for VNF with myOnapCsarId CSAR id");
+ assertEquals("The additional parameter section does not contain settings for VNF with myOnapCsarId CSAR id", e.getMessage());
+ verify(logger).error("The additional parameter section does not contain settings for VNF with myOnapCsarId CSAR id");
}
}
public Map<String,String> inputs = new HashMap<String,String>();
public String vimId;
+
+ public String properties;
}
- private VnfInstantiateRequest prepareInstantiationRequest(VimInfo.VimInfoTypeEnum cloudType) {
+ private VnfInstantiateRequest prepareInstantiationRequest(VimInfo.VimInfoTypeEnum cloudType, boolean addExtension) {
VnfInstantiateRequest instantiationRequest = new VnfInstantiateRequest();
instantiationRequest.setVnfPackageId(ONAP_CSAR_ID);
instantiationRequest.setVnfDescriptorId(ONAP_CSAR_ID);
instantiationRequest.setVnfInstanceDescription("myDescription");
instantiationRequest.setVnfInstanceName("vnfName");
+ externalVirtualLink.setCpdId("myCpdId");
+ externalVirtualLink.setResourceId("myNetworkProviderId");
+ externalVirtualLink.setVlInstanceId("myEVlId");
+ externalVirtualLink.setResourceSubnetId("notUsedSubnetId");
+ instantiationRequest.setExtVirtualLink(new ArrayList<>());
+ instantiationRequest.getExtVirtualLink().add(externalVirtualLink);
+ buildAdditionalParams(cloudType, addExtension);
+ String params = new Gson().toJson(additionalParam);
+ X x = new X();
+ x.inputs.put(ONAP_CSAR_ID, params);
+ x.vimId = VIM_ID;
+ JsonElement additionalParam = new Gson().toJsonTree(x);
+ instantiationRequest.setAdditionalParam(additionalParam);
+ return instantiationRequest;
+ }
+
+ private void buildAdditionalParams(VimInfo.VimInfoTypeEnum cloudType, boolean addExtensions) {
additionalParam.setInstantiationLevel("level1");
switch (cloudType) {
case OPENSTACK_V2_INFO:
ecp2.setNumDynamicAddresses(2);
evl.getExtCps().add(ecp2);
additionalParam.getExtVirtualLinks().add(evl);
- externalVirtualLink.setCpdId("myCpdId");
- externalVirtualLink.setResourceId("myNetworkProviderId");
- externalVirtualLink.setVlInstanceId("myEVlId");
- externalVirtualLink.setResourceSubnetId("notUsedSubnetId");
- instantiationRequest.setExtVirtualLink(new ArrayList<>());
- instantiationRequest.getExtVirtualLink().add(externalVirtualLink);
additionalParam.getExtManagedVirtualLinks().add(extManVl);
ZoneInfo zone = new ZoneInfo();
zone.setId("zoneId");
image.setVnfdSoftwareImageId("imageId");
additionalParam.getSoftwareImages().add(image);
additionalParam.setAdditionalParams(new JsonParser().parse("{ \"a\" : \"b\" }"));
- String params = new Gson().toJson(additionalParam);
- X x = new X();
- x.inputs.put(ONAP_CSAR_ID, params);
- x.vimId = VIM_ID;
- JsonElement additionalParam = new Gson().toJsonTree(x);
- instantiationRequest.setAdditionalParam(additionalParam);
- return instantiationRequest;
+ if(addExtensions) {
+ VnfProperty p1 = new VnfProperty();
+ p1.setName("n1");
+ p1.setValue(Lists.newArrayList("a", "b"));
+ VnfProperty p2 = new VnfProperty();
+ p2.setName("n2");
+ p2.setValue("a");
+ VnfProperty p3 = new VnfProperty();
+ p2.setName("n2");
+ JsonObject o = new JsonObject();
+ p2.setValue(o);
+ o.addProperty("a", "b");
+ additionalParam.getExtensions().add(p1);
+ additionalParam.getExtensions().add(p2);
+ additionalParam.getExtensions().add(p3);
+ }
}
/**
assertEquals("regionId", LifecycleManager.getRegionName("cloudOwner_regionId"));
assertEquals("cloudOwner", LifecycleManager.getCloudOwner("cloudOwner_regionId"));
}
+
+ /**
+ * additional params of instantiation may be passed as VNF property
+ */
+ @Test
+ public void testVnfConfigurationBasedOnPackageParameters() throws Exception {
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO, false);
+ when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
+ additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
+ when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
+ grantResponse.setVimId(VIM_ID);
+ GrantVNFResponseVimAccessInfo accessInfo = new GrantVNFResponseVimAccessInfo();
+ accessInfo.setTenant(TENANT);
+ grantResponse.setAccessInfo(accessInfo);
+ ArgumentCaptor<InstantiateVnfRequest> actualInstantiationRequest = ArgumentCaptor.forClass(InstantiateVnfRequest.class);
+ when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(instantiationOperationExecution));
+ X x = new X();
+ JsonObject root = new JsonObject();
+ root.addProperty(LifecycleManager.ETSI_CONFIG, new Gson().toJson(additionalParam));
+ x.properties = new Gson().toJson(root);
+ x.vimId = VIM_ID;
+ JsonElement additionalParam = new Gson().toJsonTree(x);
+ instantiationRequest.setAdditionalParam(additionalParam);
+ //when
+ VnfInstantiateResponse response = lifecycleManager.createAndInstantiate(VNFM_ID, instantiationRequest, restResponse);
+ waitForJobToFinishInJobManager(finished);
+ assertEquals(1, actualInstantiationRequest.getValue().getVims().size());
+ //verify
+ OPENSTACKV3INFO actualVim = (OPENSTACKV3INFO) actualInstantiationRequest.getValue().getVims().get(0);
+ assertEquals(VIM_ID, actualVim.getId());
+ assertEquals(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO, actualVim.getVimInfoType());
+ assertEquals(Boolean.valueOf(parseBoolean(vimInfo.getSslInsecure())), actualVim.getInterfaceInfo().isSkipCertificateVerification());
+ assertEquals("cloudUrl", actualVim.getInterfaceInfo().getEndpoint());
+ //FIXME assertEquals();actualVim.getInterfaceInfo().getTrustedCertificates());
+ assertEquals("vimPassword", actualVim.getAccessInfo().getPassword());
+ assertEquals("regionId", actualVim.getAccessInfo().getRegion());
+ assertEquals("myTenant", actualVim.getAccessInfo().getProject());
+ assertEquals("myDomain", actualVim.getAccessInfo().getDomain());
+ assertEquals("vimUsername", actualVim.getAccessInfo().getUsername());
+ assertTrue(actualVim.getInterfaceInfo().isSkipCertificateVerification());
+ assertTrue(actualVim.getInterfaceInfo().isSkipCertificateHostnameCheck());
+ }
+
+ /**
+ * additional params of instantiation may be passed as VNF property
+ */
+ @Test
+ public void testVnfConfigurationBasedOnPackageParametersMissingPropertiesEtsiConfig() throws Exception {
+ VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO, false);
+ when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(vnfInfo));
+ additionalParam.setInstantiationLevel(INSTANTIATION_LEVEL);
+ when(vfcGrantManager.requestGrantForInstantiate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, INSTANTIATION_LEVEL, cbamVnfdContent, JOB_ID)).thenReturn(grantResponse);
+ grantResponse.setVimId(VIM_ID);
+ GrantVNFResponseVimAccessInfo accessInfo = new GrantVNFResponseVimAccessInfo();
+ accessInfo.setTenant(TENANT);
+ grantResponse.setAccessInfo(accessInfo);
+ ArgumentCaptor<InstantiateVnfRequest> actualInstantiationRequest = ArgumentCaptor.forClass(InstantiateVnfRequest.class);
+ when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(buildObservable(instantiationOperationExecution));
+ X x = new X();
+ JsonObject root = new JsonObject();
+ root.addProperty(LifecycleManager.ETSI_CONFIG, new Gson().toJson(additionalParam));
+ x.properties = "{ }";
+ new Gson().toJson(root);
+ x.inputs.put(ONAP_CSAR_ID, new Gson().toJson(additionalParam));
+ x.vimId = VIM_ID;
+ JsonElement additionalParam = new Gson().toJsonTree(x);
+ instantiationRequest.setAdditionalParam(additionalParam);
+ //when
+ VnfInstantiateResponse response = lifecycleManager.createAndInstantiate(VNFM_ID, instantiationRequest, restResponse);
+ waitForJobToFinishInJobManager(finished);
+ assertEquals(1, actualInstantiationRequest.getValue().getVims().size());
+ //verify
+ OPENSTACKV3INFO actualVim = (OPENSTACKV3INFO) actualInstantiationRequest.getValue().getVims().get(0);
+ assertEquals(VIM_ID, actualVim.getId());
+ assertEquals(VimInfo.VimInfoTypeEnum.OPENSTACK_V3_INFO, actualVim.getVimInfoType());
+ assertEquals(Boolean.valueOf(parseBoolean(vimInfo.getSslInsecure())), actualVim.getInterfaceInfo().isSkipCertificateVerification());
+ assertEquals("cloudUrl", actualVim.getInterfaceInfo().getEndpoint());
+ //FIXME assertEquals();actualVim.getInterfaceInfo().getTrustedCertificates());
+ assertEquals("vimPassword", actualVim.getAccessInfo().getPassword());
+ assertEquals("regionId", actualVim.getAccessInfo().getRegion());
+ assertEquals("myTenant", actualVim.getAccessInfo().getProject());
+ assertEquals("myDomain", actualVim.getAccessInfo().getDomain());
+ assertEquals("vimUsername", actualVim.getAccessInfo().getUsername());
+ assertTrue(actualVim.getInterfaceInfo().isSkipCertificateVerification());
+ assertTrue(actualVim.getInterfaceInfo().isSkipCertificateHostnameCheck());
+ verify(logger).info("The instantiation input for VNF with {} CSAR id does not have an " + LifecycleManager.ETSI_CONFIG + " section", ONAP_CSAR_ID);
+ }
}