Address vf module missing configuration property 39/110639/2
authorParthasarathy, Ramesh <ramesh.parthasarathy@att.com>
Tue, 28 Jul 2020 01:34:25 +0000 (21:34 -0400)
committerBenjamin, Max (mb388a) <mb388a@att.com>
Wed, 26 Aug 2020 15:50:02 +0000 (11:50 -0400)
Address vf module missing configuration property
added unit tests to handle missing vnfc configuration

Issue-ID: SO-3102
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: Id5f471177afe78569d435ad28f3c4c6a09bfdcca

bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java
bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java

index 75d3ddf..84f5c68 100644 (file)
@@ -568,6 +568,10 @@ public class WorkflowAction {
             WorkflowResourceIds workflowIdsCopy = SerializationUtils.clone(dataObj.getWorkflowResourceIds());
             org.onap.aai.domain.yang.Configuration configuration = getRelatedResourcesInVnfc(vnfc,
                     org.onap.aai.domain.yang.Configuration.class, AAIObjectType.CONFIGURATION);
+            if (configuration == null) {
+                logger.warn(String.format("No configuration found for VNFC %s in AAI", vnfc.getVnfcName()));
+                continue;
+            }
             workflowIdsCopy.setConfigurationId(configuration.getConfigurationId());
             for (OrchestrationFlow orchFlow : result) {
                 dataObj.getResourceKey().setVfModuleCustomizationId(vfModuleCustomizationUUID);
@@ -584,7 +588,6 @@ public class WorkflowAction {
                         dataObj.getRequestAction(), dataObj.isaLaCarte(), dataObj.getVnfType(), workflowIdsCopy,
                         dataObj.getRequestDetails(), false, null, vnfcName, true, null);
                 flowsToExecuteConfigs.add(ebb);
-
             }
         }
         return flowsToExecuteConfigs;
index 407a844..c1970ec 100644 (file)
@@ -1600,6 +1600,79 @@ public class WorkflowActionTest extends BaseTaskTest {
         assertEquals("zauk53avetd02tvm001", results.get(1).getConfigurationResourceKeys().getVnfcName());
     }
 
+    @Test
+    public void getConfigBuildingBlocksNullConfigurationTest() throws Exception {
+        String gAction = "deleteInstance";
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
+
+        WorkflowType resourceType = WorkflowType.VFMODULE;
+        execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
+        execution.setVariable("requestAction", gAction);
+        String bpmnRequest =
+                new String(Files.readAllBytes(Paths.get("src/test/resources/__files/VfModuleCreateWithFabric.json")));
+        execution.setVariable("bpmnRequest", bpmnRequest);
+        execution.setVariable("vnfId", "1234");
+        execution.setVariable("vfModuleId", "vfModuleId1234");
+        execution.setVariable("requestUri",
+                "v7/serviceInstances/f647e3ef-6d2e-4cd3-bff4-8df4634208de/vnfs/b80b16a5-f80d-4ffa-91c8-bd47c7438a3d/vfModules");
+        ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class);
+        RequestDetails requestDetails = sIRequest.getRequestDetails();
+        String requestAction = "deleteInstance";
+        String requestId = "9c944122-d161-4280-8594-48c06a9d96d5";
+        boolean aLaCarte = true;
+        String apiVersion = "7";
+        String vnfType = "vnfType";
+        String key = "00d15ebb-c80e-43c1-80f0-90c40dde70b0";
+        String resourceId = "d1d35800-783d-42d3-82f6-d654c5054a6e";
+        Resource resourceKey = new Resource(resourceType, key, aLaCarte);
+        WorkflowResourceIds workflowResourceIds = SPY_workflowAction.populateResourceIdsFromApiHandler(execution);
+
+        List<OrchestrationFlow> orchFlows = createFlowList("DeactivateVfModuleBB", "DeleteVfModuleBB",
+                "UnassignVfModuleBB", "DeleteFabricConfigurationBB");
+
+        ConfigBuildingBlocksDataObject dataObj = new ConfigBuildingBlocksDataObject().setsIRequest(sIRequest)
+                .setOrchFlows(orchFlows).setRequestId(requestId).setResourceKey(resourceKey).setApiVersion(apiVersion)
+                .setResourceId(resourceId).setRequestAction(requestAction).setaLaCarte(aLaCarte).setVnfType(vnfType)
+                .setWorkflowResourceIds(workflowResourceIds).setRequestDetails(requestDetails).setExecution(execution);
+
+        org.onap.aai.domain.yang.GenericVnf vnf = new org.onap.aai.domain.yang.GenericVnf();
+        vnf.setVnfId("vnf0");
+        vnf.setModelCustomizationId("modelCustomizationId");
+        when(bbSetupUtils.getAAIGenericVnf(any())).thenReturn(vnf);
+
+        org.onap.aai.domain.yang.VfModule vfModule = new org.onap.aai.domain.yang.VfModule();
+        vfModule.setModelCustomizationId("modelCustomizationId");
+
+        /* this is a test case where configuration for vnfc is null */
+        org.onap.aai.domain.yang.Configuration config1 = null;
+        org.onap.aai.domain.yang.Configuration config2 = new org.onap.aai.domain.yang.Configuration();
+        config2.setConfigurationId("config2");
+
+        List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
+        org.onap.aai.domain.yang.Vnfc vnfc1 = new org.onap.aai.domain.yang.Vnfc();
+        vnfc1.setVnfcName("zauk53avetd02svm001");
+        org.onap.aai.domain.yang.Vnfc vnfc2 = new org.onap.aai.domain.yang.Vnfc();
+        vnfc2.setVnfcName("zauk53avetd02tvm001");
+        vnfcs.add(vnfc1);
+        vnfcs.add(vnfc2);
+
+        when(bbSetupUtils.getAAIVfModule(any(), any())).thenReturn(vfModule);
+        doReturn(vnfcs).when(SPY_workflowAction).getRelatedResourcesInVfModule(any(), any(),
+                eq(org.onap.aai.domain.yang.Vnfc.class), eq(AAIObjectType.VNFC));
+        doReturn(config1).when(SPY_workflowAction).getRelatedResourcesInVnfc(eq(vnfc1),
+                eq(org.onap.aai.domain.yang.Configuration.class), eq(AAIObjectType.CONFIGURATION));
+        doReturn(config2).when(SPY_workflowAction).getRelatedResourcesInVnfc(eq(vnfc2),
+                eq(org.onap.aai.domain.yang.Configuration.class), eq(AAIObjectType.CONFIGURATION));
+
+        List<ExecuteBuildingBlock> results = SPY_workflowAction.getConfigBuildingBlocks(dataObj);
+
+        assertFalse(results.isEmpty());
+        assertEquals(1, results.size());
+        assertEquals("config2", results.get(0).getWorkflowResourceIds().getConfigurationId());
+        assertEquals("zauk53avetd02tvm001", results.get(0).getConfigurationResourceKeys().getVnfcName());
+    }
+
     @Test
     public void selectExecutionListALaCarteVfModuleNoFabricDeleteTest() throws Exception {
         String gAction = "deleteInstance";