Use the ETSI config from package 97/49297/3
authorDenes Nemeth <denes.nemeth@nokia.com>
Mon, 28 May 2018 09:24:13 +0000 (11:24 +0200)
committerDenes Nemeth <denes.nemeth@nokia.com>
Tue, 29 May 2018 07:28:14 +0000 (09:28 +0200)
Change-Id: I81c7a10c1c7e0f3e12531bc5a1196b22d0fcd774
Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com>
Issue-ID: VFC-728

nokiav2/docs/onboarding.rst
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcGrantManager.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/VfcRestApiProvider.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/CatalogManager.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/LifecycleManager.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamCatalogManager.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java
nokiav2/driver/src/test/resources/unittests/TestCbamCatalogManager.sample.csar
nokiav2/driver/src/test/resources/unittests/vnfd.full.yaml
nokiav2/driver/src/test/resources/unittests/vnfd.instantiation.yaml

index 3380e43..80aff0b 100644 (file)
@@ -161,9 +161,27 @@ The following section requires the CSAR and the ETSI configuration of the VNF to
 
     - Specify NokiaSVNFM for the nf_type property
 
+  - Click on Save on the middle
+
+  - Click on Inputs
+
     - Specify the ETSI configuration JSON for the etsi_config property
 
-  - Click on Save on the middle
+    - If the ETSI configuration is larger than the maximal allowed value for a field
+
+      - Instead of specifying it using a property click on Deployment Artifact at left
+
+      - Click on Add other artifact at bottom middle
+
+        - Specify etsiConfig as Artifact Label
+
+        - Choose OTHER for type
+
+        - Specify anything for Description
+
+        - Select the ETSI configuration file using Browse
+
+        - Click on Done
 
 - Click on Check in
 
index c2ba464..cf09063 100644 (file)
@@ -166,12 +166,14 @@ public class VfcGrantManager implements IGrantManager {
     }
 
     private Set<ResourceChange> calculateResourceChangeDuringInstantiate(String cbamVnfdContent, String instantiationLevelId) {
+        logger.info("Calculating resource changed {} {}", instantiationLevelId, cbamVnfdContent);
         JsonObject root = new Gson().toJsonTree(new Yaml().load(cbamVnfdContent)).getAsJsonObject();
         JsonObject capabilities = child(child(child(root, "topology_template"), "substitution_mappings"), "capabilities");
         JsonObject deploymentFlavorProperties = child(child(capabilities, "deployment_flavour"), "properties");
         JsonObject instantiationLevels = child(deploymentFlavorProperties, "instantiation_levels");
         Set<ResourceChange> resourceChanges = new HashSet<>();
-        for (Map.Entry<String, JsonElement> vdu_level : child(child(instantiationLevels, instantiationLevelId), ("vdu_levels")).entrySet()) {
+        JsonObject instantiationLevel = child(instantiationLevels, instantiationLevelId);
+        for (Map.Entry<String, JsonElement> vdu_level : child(instantiationLevel, "vdu_levels").entrySet()) {
             JsonElement numberOfInstances = vdu_level.getValue().getAsJsonObject().get("number_of_instances");
             for (int i = 0; i < numberOfInstances.getAsLong(); i++) {
                 ResourceChange resourceChange = new ResourceChange();
index 5c9dc54..6b19dd5 100644 (file)
@@ -16,6 +16,7 @@
 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc;
 
 import com.google.common.annotations.VisibleForTesting;
+import java.util.concurrent.TimeUnit;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.MsbApiProvider;
 import org.onap.vfccatalog.api.VnfpackageApi;
 import org.onap.vnfmdriver.ApiClient;
@@ -49,6 +50,10 @@ public class VfcRestApiProvider {
     @VisibleForTesting
     ApiClient buildNslcmApiClient() {
         ApiClient apiClient = new ApiClient();
+        //LCN processing in VF-C is very slow
+        apiClient.getOkBuilder().connectTimeout(3, TimeUnit.MINUTES);
+        apiClient.getOkBuilder().readTimeout(3, TimeUnit.MINUTES);
+        apiClient.getOkBuilder().writeTimeout(3, TimeUnit.MINUTES);
         String correctedUrl = fixIncorrectUrl();
         if (!correctedUrl.endsWith("/")) {
             correctedUrl = correctedUrl + "/";
index aeeae42..0993c6e 100644 (file)
@@ -16,6 +16,7 @@
 
 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
 
+import com.google.common.base.Charsets;
 import com.google.common.io.ByteStreams;
 import com.nokia.cbam.catalog.v1.api.DefaultApi;
 import com.nokia.cbam.catalog.v1.model.CatalogAdapterVnfpackage;
@@ -36,6 +37,7 @@ import static com.google.common.collect.Iterables.filter;
 import static okhttp3.MediaType.parse;
 import static okhttp3.RequestBody.create;
 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.ETSI_CONFIG;
 import static org.slf4j.LoggerFactory.getLogger;
 import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM;
 
@@ -50,6 +52,8 @@ public class CatalogManager {
      * The location of the CBAM package within the ONAP package
      */
     public static final String CBAM_PACKAGE_NAME_IN_ZIP = "Artifacts/Deployment/OTHER/cbam.package.zip";
+    public static final String ETSI_CONFIG_NAME_IN_ZIP = "Artifacts/Deployment/OTHER/" + ETSI_CONFIG +".json";
+
     private static final String TOSCA_META_PATH = "TOSCA-Metadata/TOSCA.meta";
     private static final String TOSCA_VNFD_KEY = "Entry-Definitions";
     private static Logger logger = getLogger(CatalogManager.class);
@@ -108,7 +112,7 @@ public class CatalogManager {
     public CatalogAdapterVnfpackage preparePackageInCbam(String vnfmId, String csarId) {
         String cbamVnfdId = packageProvider.getCbamVnfdId(csarId);
         DefaultApi cbamCatalogApi = cbamRestApiProvider.getCbamCatalogApi(vnfmId);
-        if (!isPackageReplicated(cbamVnfdId, cbamCatalogApi)) {
+            if (!isPackageReplicated(cbamVnfdId, cbamCatalogApi)) {
             try {
                 ByteArrayOutputStream cbamPackage = getFileInZip(new ByteArrayInputStream(packageProvider.getPackage(csarId)), CBAM_PACKAGE_NAME_IN_ZIP);
                 return cbamCatalogApi.create(create(parse(APPLICATION_OCTET_STREAM.toString()), cbamPackage.toByteArray())).blockingFirst();
@@ -127,6 +131,21 @@ public class CatalogManager {
         return queryPackageFromCBAM(cbamVnfdId, cbamCatalogApi);
     }
 
+    /**
+     * Download the ETSI configuration of the VNF
+     * @param csarId the CSAR identifier of the package in ONAP catalog
+     * @return the content of the ETSI configuration
+     */
+    public String getEtsiConfiguration(String csarId){
+        try {
+            ByteArrayOutputStream etsiConfig = getFileInZip(new ByteArrayInputStream(packageProvider.getPackage(csarId)), ETSI_CONFIG_NAME_IN_ZIP);
+            return new String(etsiConfig.toByteArray(), Charsets.UTF_8);
+        }
+        catch (Exception e){
+            throw buildFatalFailure(logger, "Unable to download the ETSI configuration file");
+        }
+    }
+
     /**
      * Gets the content of the VNFD from the CBAM package uploaded to CBAM
      *
index 5d65050..e36ede4 100644 (file)
@@ -18,6 +18,8 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm;
 
 
 import com.google.common.base.Joiner;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
 import com.google.gson.Gson;
 import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
@@ -28,6 +30,8 @@ import com.nokia.cbam.lcm.v32.model.ScaleDirection;
 import java.util.*;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 import javax.servlet.http.HttpServletResponse;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.IGrantManager;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.api.VimInfoProvider;
@@ -313,7 +317,7 @@ public class LifecycleManager {
         }
         JsonObject inputs = child(root, "inputs");
         if (!inputs.has(csarId)) {
-            throw buildFatalFailure(logger, "The additional parameter section does not contain settings for VNF with " + csarId + " CSAR id");
+            return new Gson().fromJson(catalogManager.getEtsiConfiguration(csarId), AdditionalParameters.class);
         }
         JsonElement additionalParamsForVnf = new JsonParser().parse(inputs.get(csarId).getAsString());
         return new Gson().fromJson(additionalParamsForVnf, AdditionalParameters.class);
@@ -326,11 +330,19 @@ public class LifecycleManager {
         return childElement(deploymentFlavorProperties, "flavour_id").getAsString();
     }
 
-    private Set<Map.Entry<String, JsonElement>> getAcceptableOperationParameters(String vnfdContent, String categoryOfOperation, String operationName) {
+    private Set<Map.Entry<String, JsonElement>> getAcceptableOperationParameters(String vnfdContent, String operationName) {
         JsonObject root = new Gson().toJsonTree(new Yaml().load(vnfdContent)).getAsJsonObject();
         JsonObject interfaces = child(child(child(root, "topology_template"), "substitution_mappings"), "interfaces");
-        JsonObject additionalParameters = child(child(child(child(interfaces, categoryOfOperation), operationName), "inputs"), "additional_parameters");
-        return additionalParameters.entrySet();
+        for (Map.Entry<String, JsonElement> categoryOfOperation : interfaces.entrySet()) {
+            for (Map.Entry<String, JsonElement> operation : categoryOfOperation.getValue().getAsJsonObject().entrySet()) {
+                if(operation.getKey().equals(operationName)){
+                    JsonObject additionalParameters = child(child(operation.getValue().getAsJsonObject(), "inputs"), "additional_parameters");
+                    return additionalParameters.entrySet();
+                }
+            }
+            logger.debug("The {} operation was not found in {} interface", operationName, categoryOfOperation.getKey());
+        }
+        throw buildFatalFailure(logger, "Unable to find operation named " + operationName);
     }
 
     private void addExternalLinksToRequest(List<ExtVirtualLinkInfo> extVirtualLinks, AdditionalParameters additionalParameters, InstantiateVnfRequest instantiationRequest, String vimId) {
@@ -596,7 +608,7 @@ public class LifecycleManager {
             JsonObject root = new Gson().toJsonTree(jobInfo).getAsJsonObject();
             com.nokia.cbam.lcm.v32.model.VnfInfo cbamVnfInfo = cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
             String vnfdContent = catalogManager.getCbamVnfdContent(vnfmId, cbamVnfInfo.getVnfdId());
-            Set<Map.Entry<String, JsonElement>> acceptableOperationParameters = getAcceptableOperationParameters(vnfdContent, "Basic", SCALE_OPERATION_NAME);
+            Set<Map.Entry<String, JsonElement>> acceptableOperationParameters = getAcceptableOperationParameters(vnfdContent, SCALE_OPERATION_NAME);
             buildAdditionalParameters(request, root, acceptableOperationParameters);
             cbamRequest.setAdditionalParams(root);
             grantManager.requestGrantForScale(vnfmId, vnfId, getVimIdFromInstantiationRequest(vnfmId, vnf), getVnfdIdFromModifyableAttributes(vnf), request, jobInfo.getJobId());
index f1ed1e1..a5a3c6c 100644 (file)
@@ -77,6 +77,7 @@ public class TestVfcGrantManager extends TestBase {
         assertBasicGrantAttributes(request, org.onap.vnfmdriver.model.OperationType.INSTANTIATE);
     }
 
+
     /**
      * test failure logging & propagation during grant request for instantiation
      */
index 439325e..28e4709 100644 (file)
@@ -251,6 +251,39 @@ public class TestCbamCatalogManager extends TestBase {
         }
     }
 
+    /**
+     * ETSI configuration extraction from the package
+     */
+    @Test
+    public void testEtsiConfigurationDownload() throws Exception{
+        //given
+        byte[] onapPackageContent = TestUtil.loadFile("unittests/TestCbamCatalogManager.sample.csar");
+        when(packageProvider.getPackage(CSAR_ID)).thenReturn(onapPackageContent);
+        //when
+        String etsiConfiguration = cbamCatalogManager.getEtsiConfiguration(CSAR_ID);
+
+        assertEquals("{ \"a\" : \"b\" }\n", etsiConfiguration);
+    }
+
+    /**
+     * ETSI configuration extraction from the package
+     */
+    @Test
+    public void testEtsiConfigurationMissing() throws Exception{
+        //given
+        byte[] onapPackageContent = TestUtil.loadFile("unittests/missing.vnfd.zip");
+        when(packageProvider.getPackage(CSAR_ID)).thenReturn(onapPackageContent);
+        //when
+        try {
+            cbamCatalogManager.getEtsiConfiguration(CSAR_ID);
+            fail();
+        }
+        catch (Exception e){
+            assertEquals("Unable to download the ETSI configuration file", e.getMessage());
+            verify(logger).error("Unable to download the ETSI configuration file");
+        }
+    }
+
     private ResponseBody buildResponse(byte[] content) throws IOException {
         Headers headers = new Headers.Builder().build();
         Buffer buffer = new Buffer();
index d91c847..02be5a8 100644 (file)
@@ -1198,26 +1198,7 @@ public class TestLifecycleManager extends TestBase {
         notificationIsProcessedBeforeDeletingTheVnf.verify(notificationManager).waitForTerminationToBeProcessed("terminationId");
         notificationIsProcessedBeforeDeletingTheVnf.verify(vnfApi).vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION);
     }
-
-    /**
-     * instantiation with missing ONAP csarId to instantiation extra param result in failure
-     */
-    @Test
-    public void testMissingVnfParameters() throws Exception {
-        //given
-        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
-        try {
-            VnfInstantiateResponse response = lifecycleManager.createAndInstantiate(VNFM_ID, instantiationRequest, restResponse);
-            fail();
-        } catch (Exception e) {
-            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");
-        }
-    }
-
+    
     /**
      * test explicit forceful termination
      */
@@ -1421,20 +1402,49 @@ public class TestLifecycleManager extends TestBase {
         assertTrue("{\"jobId\":\"myJobId\",\"a\":\"b\"}".equals(new Gson().toJson(sRequest.getAdditionalParams())) || "{\"a\":\"b\",\"jobId\":\"myJobId\"}".equals(new Gson().toJson(sRequest.getAdditionalParams())));
         verify(jobManager).spawnJob(VNF_ID, restResponse);
         verify(logger).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("scale"), eq(VNF_ID), anyString());
+    }
 
+    /**
+     * test scale a non scalable VNF
+     */
+    @Test
+    public void testScaleNonScalableVnf() throws Exception {
+        cbamVnfdContent = new String(readAllBytes(Paths.get(TestVfcGrantManager.class.getResource("/unittests/vnfd.instantiation.yaml").toURI())));
+        when(catalogManager.getCbamVnfdContent(VNFM_ID, CBAM_VNFD_ID)).thenReturn(cbamVnfdContent);
+        VnfScaleRequest scaleRequest = new VnfScaleRequest();
+        scaleRequest.setNumberOfSteps("2");
+        scaleRequest.setAspectId("myAspect");
+        scaleRequest.setType(ScaleDirection.IN);
+        scaleRequest.setAdditionalParam(new JsonParser().parse("{ \"a\" : \"b\", \"c\" : \"d\" }"));
+        scaleOperationExecution.setStatus(OperationStatus.FINISHED);
+        when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
+        VnfProperty prop = new VnfProperty();
+        prop.setValue(ONAP_CSAR_ID);
+        prop.setName(LifecycleManager.ONAP_CSAR_ID);
+        vnfInfo.getExtensions().add(prop);
+        vnfInfo.getOperationExecutions().add(instantiationOperationExecution);
+        String instantiationParams = "{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] }";
+        when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(instantiationOperationExecution.getId(), NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(new JsonParser().parse(instantiationParams)));
+        //when
+        JobInfo job = lifecycleManager.scaleVnf(VNFM_ID, VNF_ID, scaleRequest, restResponse);
+        //verify
+        waitForJobToFinishInJobManager(finished);
+        assertEquals(0, actualScaleRequest.getAllValues().size());
+        verify(logger).error("Unable to find operation named scale");
     }
 
     /**
      * the VNFM should tolerate that no additional params were supplied
      */
     @Test
-    public void testScaleWithoutAddtionalParams() throws Exception {
+    public void testScaleWithoutAdditionalParams() throws Exception {
         VnfScaleRequest scaleRequest = new VnfScaleRequest();
         scaleRequest.setNumberOfSteps("2");
         scaleRequest.setAspectId("myAspect");
         scaleRequest.setType(ScaleDirection.IN);
         scaleRequest.setAdditionalParam(null);
         scaleOperationExecution.setStatus(OperationStatus.FINISHED);
+
         when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
         VnfProperty prop = new VnfProperty();
         prop.setValue(ONAP_CSAR_ID);
@@ -1834,6 +1844,47 @@ public class TestLifecycleManager extends TestBase {
         assertTrue(actualVim.getInterfaceInfo().isSkipCertificateHostnameCheck());
     }
 
+
+    /**
+     * additional params of instantiation may be passed as directly attached artifact
+     */
+    @Test
+    public void testVnfConfigurationBasedOnArtifactParameters() 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));
+        when(catalogManager.getEtsiConfiguration(ONAP_CSAR_ID)).thenReturn(new Gson().toJson(additionalParam));
+        X x = new X();
+        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
      */
index 1a17916..de27687 100644 (file)
Binary files a/nokiav2/driver/src/test/resources/unittests/TestCbamCatalogManager.sample.csar and b/nokiav2/driver/src/test/resources/unittests/TestCbamCatalogManager.sample.csar differ
index 460f7f1..9490550 100644 (file)
@@ -17,8 +17,11 @@ topology_template:
                   number_of_instances: 2
     interfaces:
       Basic:
+        unknown:
+      Scl:
         scale:
           inputs:
             additional_parameters:
               jobId: kuku
-              a: valueInVnfd
\ No newline at end of file
+              a: valueInVnfd
+        unknown2:
\ No newline at end of file
index ef858db..50a407d 100644 (file)
@@ -14,3 +14,6 @@ topology_template:
               vdu_levels:
                 vdu1:
                   number_of_instances: 2
+    interfaces:
+      Basic:
+        unknown:
\ No newline at end of file