From a339f93a736c9503888d05e47d79b173229042fc Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Tue, 5 Mar 2019 16:56:09 -0500 Subject: improvements to audit inventory feature Adjust test data to add tenant mapping Remove unused unit test already renamed Update logic, to pass hostname not pservername remove unused file that has been refactored Add project to ignore, remove class Address issues in comments on pull request Remove logging that is not needed, used UPdate BPMN to use Boolean Value, change timings Adjust BPMN to not hit deadlock scenario put error message in execution before checking rollback - removed extra code for vnf resource processing found in onap environment. Fix improper use of inclusive gateway causing deadlock Fix flakey unit tests from ONAP Remove qualifier on bean, as it breaks callbacks Adjust pom version of external camunda client Fix polling timers to be more reasonable Updated Junit test for delete vf module in onap. Changed auditInventoryNeeded variable to a boolean to prevent bpmn from erroring out in the event this variable is not found on the execution. Update logic to support writing of self link Change-Id: I2f784a0a58a09f303775282c9be6019031668570 Issue-ID: SO-1597 Signed-off-by: Benjamin, Max (mb388a) --- .../audit/AuditCreateStackServiceTest.java | 150 +++++++++++++++++++++ .../adapters/audit/AuditStackServiceDataTest.java | 150 --------------------- .../onap/so/adapters/audit/AuditVServerTest.java | 42 ++++-- .../onap/so/adapters/audit/HeatStackAuditTest.java | 2 +- .../vnf/MsoVnfMulticloudAdapterImplTest.java | 2 +- 5 files changed, 184 insertions(+), 162 deletions(-) create mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditCreateStackServiceTest.java delete mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java (limited to 'adapters/mso-openstack-adapters/src/test/java/org') diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditCreateStackServiceTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditCreateStackServiceTest.java new file mode 100644 index 0000000000..bcf126d887 --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditCreateStackServiceTest.java @@ -0,0 +1,150 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.audit; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; + +import java.io.IOException; +import java.util.Optional; + +import org.camunda.bpm.client.task.ExternalTask; +import org.camunda.bpm.client.task.ExternalTaskService; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.aai.domain.yang.LInterface; +import org.onap.so.audit.beans.AuditInventory; +import org.springframework.core.env.Environment; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; + +public class AuditCreateStackServiceTest extends AuditCreateStackService { + + @InjectMocks + AuditCreateStackService auditStackService = new AuditCreateStackService(); + + @Mock + HeatStackAudit heatStackAuditMock; + + @Mock + Environment mockEnv; + + @Mock + ExternalTask mockExternalTask; + + @Mock + ExternalTaskService mockExternalTaskService; + + AuditInventory auditInventory = new AuditInventory(); + + @Before + public void setup() { + auditInventory.setCloudOwner("cloudOwner"); + auditInventory.setCloudRegion("cloudRegion"); + auditInventory.setTenantId("tenantId"); + auditInventory.setHeatStackName("stackName"); + MockitoAnnotations.initMocks(this); + doReturn(auditInventory).when(mockExternalTask).getVariable("auditInventory"); + doReturn("6000").when(mockEnv).getProperty("mso.workflow.topics.retryMultiplier","6000"); + doReturn("aasdfasdf").when(mockExternalTask).getId(); + } + + @Test + public void execute_external_task_audit_success_Test() { + doReturn(true).when(heatStackAuditMock).auditHeatStackCreate("cloudRegion", "cloudOwner", "tenantId", "stackName"); + auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); + Mockito.verify(mockExternalTaskService).complete(mockExternalTask); + } + + @Test + public void execute_external_task_audit_first_failure_Test() { + doReturn(false).when(heatStackAuditMock).auditHeatStackCreate("cloudRegion", "cloudOwner", "tenantId", "stackName"); + doReturn(null).when(mockExternalTask).getRetries(); + auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); + Mockito.verify(mockExternalTaskService).handleFailure(mockExternalTask, + "Unable to find all VServers and L-Interaces in A&AI", + "Unable to find all VServers and L-Interaces in A&AI", 8, 10000L); + } + + @Test + public void execute_external_task_audit_intermediate_failure_Test() { + doReturn(false).when(heatStackAuditMock).auditHeatStackCreate("cloudRegion", "cloudOwner", "tenantId", "stackName"); + doReturn(6).when(mockExternalTask).getRetries(); + auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); + Mockito.verify(mockExternalTaskService).handleFailure(mockExternalTask, + "Unable to find all VServers and L-Interaces in A&AI", + "Unable to find all VServers and L-Interaces in A&AI", 5, 12000L); + + } + + @Test + public void execute_external_task_audit_final_failure_Test() { + doReturn(false).when(heatStackAuditMock).auditHeatStackCreate("cloudRegion", "cloudOwner", "tenantId", "stackName"); + doReturn(1).when(mockExternalTask).getRetries(); + auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); + Mockito.verify(mockExternalTaskService).handleBpmnError(mockExternalTask, + "AuditAAIInventoryFailure", "Number of Retries Exceeded auditing inventory"); + } + + @Test + public void retry_sequence_calculation_Test() { + long firstRetry = auditStackService.calculateRetryDelay(8); + assertEquals(6000L, firstRetry); + long secondRetry = auditStackService.calculateRetryDelay(7); + assertEquals(6000L, secondRetry); + long thirdRetry = auditStackService.calculateRetryDelay(6); + assertEquals(12000L, thirdRetry); + long fourthRetry = auditStackService.calculateRetryDelay(5); + assertEquals(18000L, fourthRetry); + long fifthRetry = auditStackService.calculateRetryDelay(4); + assertEquals(30000L, fifthRetry); + long sixRetry = auditStackService.calculateRetryDelay(3); + assertEquals(48000L, sixRetry); + long seventhRetry = auditStackService.calculateRetryDelay(2); + assertEquals(78000L, seventhRetry); + long eigthRetry = auditStackService.calculateRetryDelay(1); + assertEquals(120000L, eigthRetry); + } + + @Test + public void retry_sequence_Test() { + long firstRetry = auditStackService.calculateRetryDelay(8); + assertEquals(6000L, firstRetry); + long secondRetry = auditStackService.calculateRetryDelay(7); + assertEquals(6000L, secondRetry); + long thirdRetry = auditStackService.calculateRetryDelay(6); + assertEquals(12000L, thirdRetry); + long fourthRetry = auditStackService.calculateRetryDelay(5); + assertEquals(18000L, fourthRetry); + long fifthRetry = auditStackService.calculateRetryDelay(4); + assertEquals(30000L, fifthRetry); + long sixRetry = auditStackService.calculateRetryDelay(3); + assertEquals(48000L, sixRetry); + long seventhRetry = auditStackService.calculateRetryDelay(2); + assertEquals(78000L, seventhRetry); + long eigthRetry = auditStackService.calculateRetryDelay(1); + assertEquals(120000L, eigthRetry); + } +} diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java deleted file mode 100644 index d7739e56f6..0000000000 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java +++ /dev/null @@ -1,150 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.audit; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doReturn; - -import java.io.IOException; -import java.util.Optional; - -import org.camunda.bpm.client.task.ExternalTask; -import org.camunda.bpm.client.task.ExternalTaskService; -import org.junit.Before; -import org.junit.Test; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.onap.aai.domain.yang.LInterface; -import org.onap.so.audit.beans.AuditInventory; -import org.springframework.core.env.Environment; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; - -public class AuditStackServiceDataTest extends AuditStackServiceData { - - @InjectMocks - AuditStackServiceData auditStackService = new AuditStackServiceData(); - - @Mock - HeatStackAudit heatStackAuditMock; - - @Mock - Environment mockEnv; - - @Mock - ExternalTask mockExternalTask; - - @Mock - ExternalTaskService mockExternalTaskService; - - AuditInventory auditInventory = new AuditInventory(); - - @Before - public void setup() { - auditInventory.setCloudOwner("cloudOwner"); - auditInventory.setCloudRegion("cloudRegion"); - auditInventory.setTenantId("tenantId"); - auditInventory.setHeatStackName("stackName"); - MockitoAnnotations.initMocks(this); - doReturn(auditInventory).when(mockExternalTask).getVariable("auditInventory"); - doReturn("6000").when(mockEnv).getProperty("mso.workflow.topics.retryMultiplier","6000"); - doReturn("aasdfasdf").when(mockExternalTask).getId(); - } - - @Test - public void execute_external_task_audit_success_Test() { - doReturn(true).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", "stackName"); - auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); - Mockito.verify(mockExternalTaskService).complete(mockExternalTask); - } - - @Test - public void execute_external_task_audit_first_failure_Test() { - doReturn(false).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", "stackName"); - doReturn(null).when(mockExternalTask).getRetries(); - auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); - Mockito.verify(mockExternalTaskService).handleFailure(mockExternalTask, - "Unable to find all VServers and L-Interaces in A&AI", - "Unable to find all VServers and L-Interaces in A&AI", 8, 10000L); - } - - @Test - public void execute_external_task_audit_intermediate_failure_Test() { - doReturn(false).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", "stackName"); - doReturn(6).when(mockExternalTask).getRetries(); - auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); - Mockito.verify(mockExternalTaskService).handleFailure(mockExternalTask, - "Unable to find all VServers and L-Interaces in A&AI", - "Unable to find all VServers and L-Interaces in A&AI", 5, 12000L); - - } - - @Test - public void execute_external_task_audit_final_failure_Test() { - doReturn(false).when(heatStackAuditMock).auditHeatStack("cloudRegion", "cloudOwner", "tenantId", "stackName"); - doReturn(1).when(mockExternalTask).getRetries(); - auditStackService.executeExternalTask(mockExternalTask, mockExternalTaskService); - Mockito.verify(mockExternalTaskService).handleBpmnError(mockExternalTask, - "AuditAAIInventoryFailure"); - } - - @Test - public void retry_sequence_calculation_Test() { - long firstRetry = auditStackService.calculateRetryDelay(8); - assertEquals(6000L, firstRetry); - long secondRetry = auditStackService.calculateRetryDelay(7); - assertEquals(6000L, secondRetry); - long thirdRetry = auditStackService.calculateRetryDelay(6); - assertEquals(12000L, thirdRetry); - long fourthRetry = auditStackService.calculateRetryDelay(5); - assertEquals(18000L, fourthRetry); - long fifthRetry = auditStackService.calculateRetryDelay(4); - assertEquals(30000L, fifthRetry); - long sixRetry = auditStackService.calculateRetryDelay(3); - assertEquals(48000L, sixRetry); - long seventhRetry = auditStackService.calculateRetryDelay(2); - assertEquals(78000L, seventhRetry); - long eigthRetry = auditStackService.calculateRetryDelay(1); - assertEquals(120000L, eigthRetry); - } - - @Test - public void retry_sequence_Test() { - long firstRetry = auditStackService.calculateRetryDelay(8); - assertEquals(6000L, firstRetry); - long secondRetry = auditStackService.calculateRetryDelay(7); - assertEquals(6000L, secondRetry); - long thirdRetry = auditStackService.calculateRetryDelay(6); - assertEquals(12000L, thirdRetry); - long fourthRetry = auditStackService.calculateRetryDelay(5); - assertEquals(18000L, fourthRetry); - long fifthRetry = auditStackService.calculateRetryDelay(4); - assertEquals(30000L, fifthRetry); - long sixRetry = auditStackService.calculateRetryDelay(3); - assertEquals(48000L, sixRetry); - long seventhRetry = auditStackService.calculateRetryDelay(2); - assertEquals(78000L, seventhRetry); - long eigthRetry = auditStackService.calculateRetryDelay(1); - assertEquals(120000L, eigthRetry); - } -} diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java index 02557d8c20..9176b58de8 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditVServerTest.java @@ -58,8 +58,6 @@ import com.woorea.openstack.heat.model.Resources; @RunWith(MockitoJUnitRunner.Silent.class) public class AuditVServerTest extends AuditVServer { - private ObjectMapper objectMapper = new ObjectMapper(); - @InjectMocks private AuditVServer auditNova = new AuditVServer(); @@ -225,9 +223,13 @@ public class AuditVServerTest extends AuditVServer { @Test public void audit_Vserver_Empty_HashSet() throws JsonParseException, JsonMappingException, IOException { - boolean exists = auditNova.auditVservers(new HashSet(), tenantId, cloudOwner, cloudRegion); + boolean exists = auditNova.auditAllVserversDoExist(new HashSet(), tenantId, cloudOwner, cloudRegion); assertEquals(false, exists); + + boolean doNotExist = auditNova.auditAllVserversDoNotExist(new HashSet(), tenantId, cloudOwner, cloudRegion); + assertEquals(true, doNotExist); } + @Test public void audit_Vserver_Found_Test() throws JsonParseException, JsonMappingException, IOException { @@ -246,8 +248,11 @@ public class AuditVServerTest extends AuditVServer { doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri); doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri); - boolean exists = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + boolean exists = auditNova.auditAllVserversDoExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); assertEquals(true, exists); + + boolean doNotExist = auditNova.auditAllVserversDoNotExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); + assertEquals(false, doNotExist); } @Test @@ -268,8 +273,11 @@ public class AuditVServerTest extends AuditVServer { doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri); doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri); - boolean exists = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + boolean exists = auditNova.auditAllVserversDoExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); assertEquals(false, exists); + + boolean doNotExist = auditNova.auditAllVserversDoNotExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); + assertEquals(false, doNotExist); } @Test @@ -288,16 +296,23 @@ public class AuditVServerTest extends AuditVServer { doReturn(true).when(aaiResourcesMock).exists(service2_sub_1_uri); doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri); doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri); - boolean exists = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + boolean exists = auditNova.auditAllVserversDoExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); assertEquals(false, exists); + + boolean doNotExist = auditNova.auditAllVserversDoNotExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); + assertEquals(false, doNotExist); } @Test - public void audit_Vserver_Not_Found_Test() throws JsonParseException, JsonMappingException, IOException { + public void audit_Vservers_Not_Found_Test() throws JsonParseException, JsonMappingException, IOException { doReturn(false).when(aaiResourcesMock).exists(vserverURI); doReturn(false).when(aaiResourcesMock).exists(vserverURI2); - boolean exists = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + + boolean exists = auditNova.auditAllVserversDoExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); assertEquals(false, exists); + + boolean doNotExist = auditNova.auditAllVserversDoNotExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); + assertEquals(true, doNotExist); } @Test @@ -306,8 +321,11 @@ public class AuditVServerTest extends AuditVServer { doReturn(true).when(aaiResourcesMock).exists(vserverURI2); doReturn(Optional.of(test_port_1_plural)).when(aaiResourcesMock).get(LInterface.class,test_port_1_uri); doReturn(Optional.of(test_port_2_plural)).when(aaiResourcesMock).get(LInterface.class,test_port_2_uri); - boolean exists = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + boolean exists = auditNova.auditAllVserversDoExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); assertEquals(false, exists); + + boolean doNotExist = auditNova.auditAllVserversDoNotExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); + assertEquals(false, doNotExist); } @Test @@ -325,8 +343,12 @@ public class AuditVServerTest extends AuditVServer { doReturn(true).when(aaiResourcesMock).exists(service1_sub_0_uri); doReturn(true).when(aaiResourcesMock).exists(service1_sub_1_uri); doReturn(false).when(aaiResourcesMock).exists(vserverURI2); - boolean exists = auditNova.auditVservers(vserversToAudit, tenantId, cloudOwner, cloudRegion); + + boolean exists = auditNova.auditAllVserversDoExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); assertEquals(false, exists); + + boolean doNotExist = auditNova.auditAllVserversDoNotExist(vserversToAudit, tenantId, cloudOwner, cloudRegion); + assertEquals(false, doNotExist); } } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java index 696784110b..5eea46d09f 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java @@ -203,7 +203,7 @@ public class HeatStackAuditTest extends HeatStackAudit { Resources getResource = objectMapper.readValue(new File("src/test/resources/Service1ResourceGroupResponse.json"), Resources.class); doReturn(getResource).when(msoHeatUtilsMock).queryStackResources(cloudRegion, tenantId, "heatStackName"); - boolean actual = heatStackAudit.auditHeatStack(cloudRegion, "cloudOwner", tenantId, "heatStackName"); + boolean actual = heatStackAudit.auditHeatStackCreate(cloudRegion, "cloudOwner", tenantId, "heatStackName"); assertEquals(true, actual); } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java index 75cea9eafc..376076a0a0 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/MsoVnfMulticloudAdapterImplTest.java @@ -65,7 +65,7 @@ public class MsoVnfMulticloudAdapterImplTest extends BaseRestTestUtils{ @Test public void createVfModule() throws Exception { - //expectedException.expect(VnfException.class); + Map stackInputs = new HashMap<>(); stackInputs.put("oof_directives", "{}"); stackInputs.put("sdnc_directives", "{}"); -- cgit 1.2.3-korg