diff options
Diffstat (limited to 'nokiav2/driver/src/test')
10 files changed, 484 insertions, 71 deletions
diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java index 17cf8258..a0d4ea4d 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/core/TestGenericExternalSystemInfoProvider.java @@ -87,29 +87,11 @@ public class TestGenericExternalSystemInfoProvider extends TestBase { verify(genericExternalSystemInfoProvider, Mockito.times(2)).queryVnfmInfoFromSource(VNFM_ID); } - class TestClass extends GenericExternalSystemInfoProvider { - - TestClass(Environment environment) { - super(environment); - } - - @Override - public VnfmInfo queryVnfmInfoFromSource(String vnfmId) { - return null; - } - - @Override - public VimInfo getVimInfo(String vimId) { - return null; - } - } - - /** * Unable to query VNFM results is propagated */ @Test - public void testUnableToQueryVnfmInfoProvider() throws Exception{ + public void testUnableToQueryVnfmInfoProvider() throws Exception { class TestClass extends GenericExternalSystemInfoProvider { TestClass(Environment environment) { @@ -129,10 +111,26 @@ public class TestGenericExternalSystemInfoProvider extends TestBase { try { new TestClass(null).getVnfmInfo(VNFM_ID); fail(); - } - catch (Exception e){ + } catch (Exception e) { assertEquals("Unable to query VNFM info for myVnfmId", e.getMessage()); verify(logger).error(eq("Unable to query VNFM info for myVnfmId"), any(RuntimeException.class)); } } + + class TestClass extends GenericExternalSystemInfoProvider { + + TestClass(Environment environment) { + super(environment); + } + + @Override + public VnfmInfo queryVnfmInfoFromSource(String vnfmId) { + return null; + } + + @Override + public VimInfo getVimInfo(String vimId) { + return null; + } + } } diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java index a2bf0305..4bbf0764 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcGrantManager.java @@ -159,6 +159,32 @@ public class TestVfcGrantManager extends TestBase { } /** + * grant is requested for termination if the the VNF is instantiated even if has no VNFCs + */ + @Test + public void testGrantIsRequestedIfInstantiatedWithNoVnfcs() { + VnfInfo vnf = new VnfInfo(); + vnf.setId(VNF_ID); + vnf.setInstantiationState(InstantiationState.INSTANTIATED); + InstantiatedVnfInfo instantiatedVnfInfo = new InstantiatedVnfInfo(); + vnf.setInstantiatedVnfInfo(instantiatedVnfInfo); + VnfProperty prop = new VnfProperty(); + prop.setName(LifecycleManager.ONAP_CSAR_ID); + prop.setValue(ONAP_CSAR_ID); + vnf.setVnfConfigurableProperties(new ArrayList<>()); + vnf.getVnfConfigurableProperties().add(prop); + //when + vfcGrantManager.requestGrantForTerminate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, vnf, JOB_ID); + //verify + assertEquals(1, grantRequest.getAllValues().size()); + GrantVNFRequest request = grantRequest.getValue(); + assertVduInGrant(request.getRemoveResource(), "vdu1", 0); + assertVduInGrant(request.getRemoveResource(), "vdu2", 0); + assertEquals(0, request.getAddResource().size()); + assertBasicGrantAttributes(request, org.onap.vnfmdriver.model.OperationType.TERMINAL); + } + + /** * test failure logging & propagation during grant request for instantiation */ @Test @@ -179,7 +205,7 @@ public class TestVfcGrantManager extends TestBase { } /** - * failuire is to request grant is logged + * failure is to request grant is logged */ @Test public void testFailureToRequestGrantIsLogged() throws Exception { @@ -211,7 +237,7 @@ public class TestVfcGrantManager extends TestBase { } /** - * failuire is to request grant is logged + * failure is to request grant is logged */ @Test public void testFailureToRequestGrantForScaleIsLogged() throws Exception { @@ -259,6 +285,54 @@ public class TestVfcGrantManager extends TestBase { } /** + * test grant request for scale out without VDUs + */ + @Test + public void testGrantDuringScaleOutWithoutVdus() throws Exception { + String cbamVnfdContent = new String(readAllBytes(Paths.get(TestVfcGrantManager.class.getResource("/unittests/vnfd.scale.yaml").toURI()))); + VnfScaleRequest scaleRequest = new VnfScaleRequest(); + scaleRequest.setType(ScaleDirection.OUT); + scaleRequest.setAspectId("aspectWithOutVdu"); + scaleRequest.setNumberOfSteps("2"); + VnfInfo vnf = new VnfInfo(); + when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnf); + vnf.setVnfdId(CBAM_VNFD_ID); + when(cbamCatalogManager.getCbamVnfdContent(VNFM_ID, CBAM_VNFD_ID)).thenReturn(cbamVnfdContent); + //when + vfcGrantManager.requestGrantForScale(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, scaleRequest, JOB_ID); + //verify + assertEquals(1, grantRequest.getAllValues().size()); + GrantVNFRequest request = grantRequest.getValue(); + assertVduInGrant(request.getAddResource(), "vdu1", 0); + assertVduInGrant(request.getAddResource(), "vdu2", 0); + assertEquals(0, request.getRemoveResource().size()); + assertBasicGrantAttributes(request, org.onap.vnfmdriver.model.OperationType.SCALEOUT); + } + + /** + * test grant request for scale out without resources + */ + @Test + public void testGrantDuringScaleOutForEmptyAspect() throws Exception { + String cbamVnfdContent = new String(readAllBytes(Paths.get(TestVfcGrantManager.class.getResource("/unittests/vnfd.scale.yaml").toURI()))); + VnfScaleRequest scaleRequest = new VnfScaleRequest(); + scaleRequest.setType(ScaleDirection.OUT); + scaleRequest.setAspectId("emptyAspect"); + scaleRequest.setNumberOfSteps("2"); + VnfInfo vnf = new VnfInfo(); + when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(vnf); + vnf.setVnfdId(CBAM_VNFD_ID); + when(cbamCatalogManager.getCbamVnfdContent(VNFM_ID, CBAM_VNFD_ID)).thenReturn(cbamVnfdContent); + //when + try { + vfcGrantManager.requestGrantForScale(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, scaleRequest, JOB_ID); + fail(); + } catch (Exception e) { + assertEquals("Missing child emptyAspect", e.getMessage()); + } + } + + /** * test grant request for scale in */ @Test diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java index 008d8272..d28e224f 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/onap/vfc/TestVfcNotificationSender.java @@ -41,6 +41,8 @@ import org.threeten.bp.OffsetDateTime; import java.util.ArrayList; import java.util.List; +import static java.util.Optional.empty; +import static java.util.Optional.of; import static junit.framework.TestCase.*; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; @@ -114,7 +116,7 @@ public class TestVfcNotificationSender extends TestBase { recievedLcn.setStatus(OperationStatus.STARTED); recievedLcn.setOperation(OperationType.INSTANTIATE); //when - vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, affectedCp, VIM_ID); + vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, empty(), VIM_ID); //verify assertEquals(1, sentLcnToVfc.getAllValues().size()); assertNull(sentLcnToVfc.getValue().getAffectedVl()); @@ -188,7 +190,7 @@ public class TestVfcNotificationSender extends TestBase { JsonElement additionalData = new Gson().toJsonTree(operationResult); instantiationOperation.setAdditionalData(additionalData); //when - vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, affectedConnectionPoints, VIM_ID); + vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, of(affectedConnectionPoints), VIM_ID); //verify assertEquals(1, sentLcnToVfc.getAllValues().size()); @@ -271,7 +273,7 @@ public class TestVfcNotificationSender extends TestBase { JsonElement additionalData = new Gson().toJsonTree(operationResult); instantiationOperation.setAdditionalData(additionalData); //when - vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, affectedConnectionPoints, VIM_ID); + vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, of(affectedConnectionPoints), VIM_ID); //verify assertEquals(1, sentLcnToVfc.getAllValues().size()); @@ -352,7 +354,7 @@ public class TestVfcNotificationSender extends TestBase { JsonElement additionalData = new Gson().toJsonTree(operationResult); instantiationOperation.setAdditionalData(additionalData); //when - vfcNotificationSender.processNotification(recievedLcn, terminationOperation, affectedConnectionPoints, VIM_ID); + vfcNotificationSender.processNotification(recievedLcn, terminationOperation, of(affectedConnectionPoints), VIM_ID); //verify assertEquals(1, sentLcnToVfc.getAllValues().size()); @@ -473,7 +475,7 @@ public class TestVfcNotificationSender extends TestBase { JsonElement additionalData = new Gson().toJsonTree(operationResult); instantiationOperation.setAdditionalData(additionalData); //when - vfcNotificationSender.processNotification(recievedLcn, healOperation, affectedConnectionPoints, VIM_ID); + vfcNotificationSender.processNotification(recievedLcn, healOperation, of(affectedConnectionPoints), VIM_ID); //verify assertEquals(1, sentLcnToVfc.getAllValues().size()); @@ -585,7 +587,7 @@ public class TestVfcNotificationSender extends TestBase { JsonElement additionalData = new Gson().toJsonTree(operationResult); scaleOperation.setAdditionalData(additionalData); //when - vfcNotificationSender.processNotification(recievedLcn, scaleOperation, affectedConnectionPoints, VIM_ID); + vfcNotificationSender.processNotification(recievedLcn, scaleOperation, of(affectedConnectionPoints), VIM_ID); //verify assertEquals(1, sentLcnToVfc.getAllValues().size()); @@ -698,7 +700,7 @@ public class TestVfcNotificationSender extends TestBase { scaleOperation.setAdditionalData(additionalData); scaleOperation.setOperationType(OperationType.SCALE); //when - vfcNotificationSender.processNotification(recievedLcn, scaleOperation, affectedConnectionPoints, VIM_ID); + vfcNotificationSender.processNotification(recievedLcn, scaleOperation, of(affectedConnectionPoints), VIM_ID); //verify assertEquals(1, sentLcnToVfc.getAllValues().size()); @@ -742,6 +744,99 @@ public class TestVfcNotificationSender extends TestBase { assertEquals(VNF_ID, sentLcnToVfc.getValue().getVnfInstanceId()); } + + /** + * en empty LCN is sent even if nothing has changed + */ + @Test + public void testNothingChanged() { + //given + recievedLcn.setOperation(OperationType.SCALE); + recievedLcn.setStatus(OperationStatus.FINISHED); + recievedLcn.setLifecycleOperationOccurrenceId(scaleOperation.getId()); + ScaleVnfRequest request = new ScaleVnfRequest(); + request.setAdditionalParams(new JsonParser().parse("{ \"jobId\" : \"" + JOB_ID + "\" }")); + request.setType(ScaleDirection.IN); + scaleOperation.setOperationParams(request); + OperationResult operationResult = new OperationResult(); + JsonElement additionalData = new Gson().toJsonTree(operationResult); + scaleOperation.setAdditionalData(additionalData); + scaleOperation.setOperationType(OperationType.SCALE); + when(logger.isInfoEnabled()).thenReturn(false); + //when + vfcNotificationSender.processNotification(recievedLcn, scaleOperation, empty(), VIM_ID); + //verify + assertEquals(1, sentLcnToVfc.getAllValues().size()); + + assertNull(sentLcnToVfc.getValue().getAffectedVl()); + assertNull(sentLcnToVfc.getValue().getAffectedVnfc()); + assertNull(sentLcnToVfc.getValue().getAffectedCp()); + assertNull(sentLcnToVfc.getValue().getAffectedVirtualStorage()); + assertEquals(JOB_ID, sentLcnToVfc.getValue().getJobId()); + assertEquals(org.onap.vnfmdriver.model.OperationType.SCALEIN, sentLcnToVfc.getValue().getOperation()); + assertEquals(VnfLcmNotificationStatus.RESULT, sentLcnToVfc.getValue().getStatus()); + assertEquals(VNF_ID, sentLcnToVfc.getValue().getVnfInstanceId()); + verify(logger, never()).info(eq("Sending LCN: {}"), anyString()); + } + + /** + * If a connection point is not modified it is not contained in the LCN + */ + @Test + public void testNonModifiedCP() { + //given + recievedLcn.setOperation(OperationType.HEAL); + recievedLcn.setStatus(OperationStatus.FINISHED); + + ReportedAffectedConnectionPoints affectedConnectionPoints = new ReportedAffectedConnectionPoints(); + ReportedAffectedCp affectedCp = new ReportedAffectedCp(); + affectedCp.setCpdId("cpVnfdId"); + affectedCp.setIpAddress("1.2.3.4"); + affectedCp.setMacAddress("myMac"); + affectedCp.setName("myPortName"); + affectedCp.setCpId("cpId"); + + // affectedCp.setEcpdId("ecpdId"); + affectedCp.setNetworkProviderId("networkProviderId"); + affectedCp.setProviderId("portProviderId"); + affectedCp.setServerProviderId("serverProviderId"); + affectedCp.setTenantId("tenantId"); + affectedConnectionPoints.getPre().add(affectedCp); + + ReportedAffectedCp after = new ReportedAffectedCp(); + after.setCpdId("cpVnfdId"); + after.setIpAddress("1.2.3.4"); + after.setMacAddress("myMac"); + after.setName("myPortName"); + after.setCpId("cpId"); + + // affectedCp.setEcpdId("ecpdId"); + after.setNetworkProviderId("networkProviderId"); + after.setProviderId("portProviderId"); + after.setServerProviderId("serverProviderId"); + after.setTenantId("tenantId"); + affectedConnectionPoints.getPost().add(after); + + + OperationResult operationResult = new OperationResult(); + operationResult.operationResult = affectedConnectionPoints; + JsonElement additionalData = new Gson().toJsonTree(operationResult); + instantiationOperation.setAdditionalData(additionalData); + //when + vfcNotificationSender.processNotification(recievedLcn, healOperation, of(affectedConnectionPoints), VIM_ID); + //verify + assertEquals(1, sentLcnToVfc.getAllValues().size()); + + assertNull(sentLcnToVfc.getValue().getAffectedVl()); + assertNull(sentLcnToVfc.getValue().getAffectedVnfc()); + assertEquals(0, sentLcnToVfc.getValue().getAffectedCp().size()); + assertNull(sentLcnToVfc.getValue().getAffectedVirtualStorage()); + assertEquals(JOB_ID, sentLcnToVfc.getValue().getJobId()); + assertEquals(org.onap.vnfmdriver.model.OperationType.HEAL, sentLcnToVfc.getValue().getOperation()); + assertEquals(VnfLcmNotificationStatus.RESULT, sentLcnToVfc.getValue().getStatus()); + assertEquals(VNF_ID, sentLcnToVfc.getValue().getVnfInstanceId()); + } + /** * Unable to send notification to VF-C results in error */ @@ -753,7 +848,7 @@ public class TestVfcNotificationSender extends TestBase { recievedLcn.setOperation(OperationType.INSTANTIATE); //when try { - vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, affectedCp, VIM_ID); + vfcNotificationSender.processNotification(recievedLcn, instantiationOperation, empty(), VIM_ID); //verify fail(); } catch (Exception e) { diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java index fd93dce2..5001eedf 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java @@ -15,6 +15,7 @@ */ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer; +import org.junit.Before; import org.junit.Test; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; @@ -23,11 +24,19 @@ import java.util.NoSuchElementException; import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.fail; +import static org.mockito.Mockito.verify; +import static org.springframework.test.util.ReflectionTestUtils.setField; public class TestOnapVnfdBuilder extends TestBase { private OnapVnfdBuilder packageTransformer = new OnapVnfdBuilder(); + + @Before + public void init() { + setField(OnapVnfdBuilder.class, "logger", logger); + } + @Test public void indent() { assertEquals(" x", packageTransformer.indent("x", 2)); @@ -51,6 +60,17 @@ public class TestOnapVnfdBuilder extends TestBase { @Test public void testNodes() { assertEquals(new String(TestUtil.loadFile("unittests/packageconverter/nodes.vnfd.onap.yaml")), packageTransformer.toOnapVnfd(new String(TestUtil.loadFile("unittests/packageconverter/nodes.vnfd.cbam.yaml")))); + verify(logger).warn("The {} ecp does not have an internal connection point", "myEcpWithoutIcp"); + verify(logger).warn("The {} ecp does not have an requirements section", "ecpWithIcpWithOutRequirements"); + verify(logger).warn("The {} internal connection point of the {} ecp does not have a VDU", "icpWithoutVdu", "myEcpWithoutIcpWithoutVdu"); + + verify(logger).warn("The {} internal connection point of the {} ecp does not have a requirements section", "icpWithOutRequiements", "myEcpWithoutIcpWithoutIcpReq"); + + + verify(logger).warn("The {} internal connection point does not have a VDU", "icpWithOutVdu"); + verify(logger).warn("The {} internal connection point does not have a requirements section", "icpWithOutRequiements"); + verify(logger).warn("The {} internal connection point does not have a VL", "icpWithOutVl"); + } /** diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java index 95bdc5f4..218c478e 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java @@ -17,7 +17,6 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi; import com.google.common.collect.Lists; -import junit.framework.TestCase; import org.apache.http.entity.ContentType; import org.junit.Before; import org.junit.Test; @@ -41,9 +40,9 @@ import java.io.IOException; import java.io.PrintStream; import java.util.Arrays; -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertTrue; -import static junit.framework.TestCase.fail; +import static junit.framework.TestCase.*; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CatalogManager.getFileInZip; @@ -121,17 +120,33 @@ public class TestConverterApi extends TestBase { * error is propagated if unable to extract package from HTTP request */ @Test - public void testUnableToExtractPackageToBeConverted() throws Exception{ + public void testUnableToExtractPackageToBeConverted() throws Exception { IOException expectedException = new IOException(); when(httpRequest.getParts()).thenThrow(expectedException); try { converterApi.convert(httpResponse, httpRequest); fail(); - } - catch (Exception e){ + } catch (Exception e) { verify(logger).error("Unable to extract package from REST parameters", expectedException); assertEquals("Unable to extract package from REST parameters", e.getMessage()); assertEquals(expectedException, e.getCause()); } } + + /** + * error is propagated if unable to extract package from HTTP request + */ + @Test + public void testUnableToConvertPackage() throws Exception { + Part part = Mockito.mock(Part.class); + when(part.getInputStream()).thenReturn(new ByteArrayInputStream(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip"))); + when(httpRequest.getParts()).thenReturn(Lists.newArrayList(part)); + try { + converterApi.convert(httpResponse, httpRequest); + fail(); + } catch (Exception e) { + verify(logger).error(eq("Unable to convert VNF package"), any(RuntimeException.class)); + assertEquals("Unable to convert VNF package", e.getMessage()); + } + } } diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java index 3ff53643..c601f7ee 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java @@ -52,6 +52,7 @@ import static java.nio.file.Files.readAllBytes; import static junit.framework.TestCase.*; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.*; +import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.child; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider.NOKIA_LCM_API_VERSION; import static org.springframework.test.util.ReflectionTestUtils.setField; @@ -251,8 +252,8 @@ public class TestLifecycleManager extends TestBase { //the 3.2 API does not accept empty array assertNull(actualVnfModifyRequest.getValue().getVnfConfigurableProperties()); verify(jobManager).spawnJob(VNF_ID, restResponse); - //verify(logger).info(eq("Additional parameters for instantiation: {}"), anyString()); - //FIXME + 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()); } /** @@ -263,7 +264,7 @@ public class TestLifecycleManager extends TestBase { //given VnfInstantiateRequest instantiationRequest = prepareInstantiationRequest(VimInfo.VimInfoTypeEnum.OTHER_VIM_INFO); when(vnfApi.vnfsPost(createRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(vnfInfo); - when(logger.isDebugEnabled()).thenReturn(false); + when(logger.isInfoEnabled()).thenReturn(false); //when try { lifecycleManager.createAndInstantiate(VNFM_ID, instantiationRequest, restResponse); @@ -273,7 +274,8 @@ public class TestLifecycleManager extends TestBase { assertEquals("Only OPENSTACK_V2_INFO, OPENSTACK_V3_INFO and VMWARE_VCLOUD_INFO is the supported VIM types", e.getMessage()); } verify(vnfApi, never()).vnfsPost(Mockito.any(), Mockito.any()); - verify(logger, never()).debug(eq("Additional parameters for instantiation: {}"), anyString()); + verify(logger, never()).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("creation"), eq("not yet specified"), anyString()); + verify(logger, never()).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("instantiation"), eq(VNF_ID), anyString()); verify(logger).error("Only OPENSTACK_V2_INFO, OPENSTACK_V3_INFO and VMWARE_VCLOUD_INFO is the supported VIM types"); } @@ -296,6 +298,9 @@ public class TestLifecycleManager extends TestBase { grantResponse.setAccessInfo(accessInfo); ArgumentCaptor<InstantiateVnfRequest> actualInstantiationRequest = ArgumentCaptor.forClass(InstantiateVnfRequest.class); when(vnfApi.vnfsVnfInstanceIdInstantiatePost(eq(VNF_ID), actualInstantiationRequest.capture(), eq(NOKIA_LCM_API_VERSION))).thenReturn(instantiationOperationExecution); + JsonObject inputs = child((JsonObject) instantiationRequest.getAdditionalParam(), "inputs"); + JsonObject vnfs = child(child(inputs, "vnfs"), ONAP_CSAR_ID); + vnfs.remove("additionalParams"); //when VnfInstantiateResponse response = lifecycleManager.createAndInstantiate(VNFM_ID, instantiationRequest, restResponse); waitForJobToFinishInJobManager(finished); @@ -305,9 +310,9 @@ public class TestLifecycleManager extends TestBase { assertEquals(StoreLoader.getCertifacates(caCert).iterator().next(), new String(actualVim.getInterfaceInfo().getTrustedCertificates().get(0))); assertTrue(!actualVim.getInterfaceInfo().isSkipCertificateVerification()); assertTrue(!actualVim.getInterfaceInfo().isSkipCertificateHostnameCheck()); + verify(logger).warn("No additional parameters were specified for the operation"); } - /** * non specified SSL verification means not verified */ @@ -753,6 +758,7 @@ public class TestLifecycleManager extends TestBase { notificationIsProcessedBeforeDeletingTheVnf.verify(notificationManager).waitForTerminationToBeProcessed("terminationId"); notificationIsProcessedBeforeDeletingTheVnf.verify(vnfApi).vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION); verify(jobManager).spawnJob(VNF_ID, restResponse); + verify(logger).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("termination"), eq(VNF_ID), anyString()); } /** @@ -1158,6 +1164,8 @@ public class TestLifecycleManager extends TestBase { assertEquals(Integer.valueOf(2), sRequest.getNumberOfSteps()); 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()); + } /** @@ -1322,6 +1330,7 @@ public class TestLifecycleManager extends TestBase { assertEquals("vmName", root.get("vmName").getAsString()); assertEquals(JOB_ID, root.get("jobId").getAsString()); verify(jobManager).spawnJob(VNF_ID, restResponse); + verify(logger).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("heal"), eq(VNF_ID), anyString()); } /** diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java index 18567f4c..7121bea6 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java @@ -31,10 +31,8 @@ import org.threeten.bp.OffsetDateTime; import java.util.ArrayList; import java.util.List; import java.util.NoSuchElementException; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; +import java.util.Optional; +import java.util.concurrent.*; import static com.nokia.cbam.lcm.v32.model.OperationType.*; import static junit.framework.TestCase.*; @@ -56,7 +54,7 @@ public class TestLifecycleChangeNotificationManager extends TestBase { private OperationExecution terminationOperation = new OperationExecution(); private ArgumentCaptor<OperationExecution> currentOperationExecution = ArgumentCaptor.forClass(OperationExecution.class); - private ArgumentCaptor<ReportedAffectedConnectionPoints> affectedConnectionPoints = ArgumentCaptor.forClass(ReportedAffectedConnectionPoints.class); + private ArgumentCaptor<Optional> affectedConnectionPoints = ArgumentCaptor.forClass(Optional.class); private List<VnfInfo> vnfs = new ArrayList<>(); private VnfInfo vnf = new VnfInfo(); @@ -240,6 +238,19 @@ public class TestLifecycleChangeNotificationManager extends TestBase { } /** + * LCN is not logged in case of non info log level + */ + @Test + public void testNoLogging() throws Exception { + vnf.getExtensions().clear(); + when(logger.isInfoEnabled()).thenReturn(false); + //when + lifecycleChangeNotificationManager.handleLcn(recievedLcn); + //verify + verify(logger, never()).info(eq("Received LCN: {}"), anyString()); + } + + /** * if the VNF is not managed by this VNFM the LCN is dropped */ @Test @@ -345,6 +356,38 @@ public class TestLifecycleChangeNotificationManager extends TestBase { } /** + * the processing of the start notification does not trigger the deletion of the VNF + */ + @Test + public void testStartLcnForTerminate() throws Exception { + recievedLcn.setOperation(OperationType.TERMINATE); + recievedLcn.setStatus(OperationStatus.STARTED); + recievedLcn.setLifecycleOperationOccurrenceId(terminationOperation.getId()); + ExecutorService executorService = Executors.newCachedThreadPool(); + Future<Boolean> waitExitedWithSuccess = executorService.submit(() -> { + try { + lifecycleChangeNotificationManager.waitForTerminationToBeProcessed(terminationOperation.getId()); + return true; + } catch (Exception e) { + return false; + } + }); + //processing the start notification + lifecycleChangeNotificationManager.handleLcn(recievedLcn); + //verify + try { + waitExitedWithSuccess.get(10, TimeUnit.MILLISECONDS); + fail(); + } catch (Exception e) { + } + recievedLcn.setStatus(OperationStatus.FINISHED); + //when + lifecycleChangeNotificationManager.handleLcn(recievedLcn); + //verify + assertTrue(waitExitedWithSuccess.get()); + } + + /** * Forceful termination results in an empty affected connection points */ @Test @@ -361,11 +404,50 @@ public class TestLifecycleChangeNotificationManager extends TestBase { terminationOperation.setOperationType(OperationType.TERMINATE); //when lifecycleChangeNotificationManager.handleLcn(recievedLcn); - assertNull(affectedConnectionPoints.getValue()); + assertFalse(affectedConnectionPoints.getValue().isPresent()); verify(logger).warn("Unable to send information related to affected connection points during forceful termination"); } /** + * Failures in affected connection point processing are tolerated for failed operation + * (because the POST script was not able to run) + */ + @Test + public void testFailedOperations() throws Exception { + //given + recievedLcn.setOperation(OperationType.INSTANTIATE); + recievedLcn.setStatus(OperationStatus.FAILED); + recievedLcn.setLifecycleOperationOccurrenceId(instantiationOperation.getId()); + instantiationOperation.setAdditionalData(null); + instantiationOperation.setStatus(OperationStatus.FAILED); + //when + lifecycleChangeNotificationManager.handleLcn(recievedLcn); + //verify + assertFalse(affectedConnectionPoints.getValue().isPresent()); + verify(logger).warn("The operation failed and the affected connection points were not reported"); + } + + /** + * Failures in affected connection point processing are tolerated for failed operation + * (because the POST script was not able to run) + */ + @Test + public void testMissingOperationResult() throws Exception { + //given + recievedLcn.setOperation(OperationType.INSTANTIATE); + recievedLcn.setStatus(OperationStatus.FAILED); + recievedLcn.setLifecycleOperationOccurrenceId(instantiationOperation.getId()); + instantiationOperation.setStatus(OperationStatus.FAILED); + JsonObject additionalData = (JsonObject) instantiationOperation.getAdditionalData(); + additionalData.remove("operationResult"); + //when + lifecycleChangeNotificationManager.handleLcn(recievedLcn); + //verify + assertFalse(affectedConnectionPoints.getValue().isPresent()); + verify(logger).warn("The operation failed and the affected connection points were not reported"); + } + + /** * test end notification scenario for failed scale-out * - LCN is sent to VF-C, but the */ @@ -384,12 +466,58 @@ public class TestLifecycleChangeNotificationManager extends TestBase { scaleOperation.setOperationType(OperationType.SCALE); //when lifecycleChangeNotificationManager.handleLcn(recievedLcn); - assertEquals(0, affectedConnectionPoints.getValue().getPost().size()); - assertEquals(0, affectedConnectionPoints.getValue().getPre().size()); + assertFalse(affectedConnectionPoints.getValue().isPresent()); + verify(logger).warn("The operation failed and the affected connection points were not reported"); + } + + /** + * if the cbam_post is missing error handling should be applied + */ + @Test + public void testMissingPostResultForFailedOperation() { + //given + recievedLcn.setOperation(OperationType.SCALE); + recievedLcn.setStatus(OperationStatus.FAILED); + recievedLcn.setLifecycleOperationOccurrenceId(scaleOperation.getId()); + ScaleVnfRequest request = new ScaleVnfRequest(); + request.setAdditionalParams(new JsonParser().parse("{ \"type\" : \"IN\", \"jobId\" : \"" + JOB_ID + "\" }")); + request.setType(ScaleDirection.OUT); + scaleOperation.setOperationParams(request); + scaleOperation.setStatus(OperationStatus.FAILED); + ((JsonObject) scaleOperation.getAdditionalData()).get("operationResult").getAsJsonObject().remove("cbam_post"); + scaleOperation.setOperationType(OperationType.SCALE); + //when + lifecycleChangeNotificationManager.handleLcn(recievedLcn); + assertFalse(affectedConnectionPoints.getValue().isPresent()); verify(logger).warn("The operation failed and the affected connection points were not reported"); } /** + * if invalid type is specified for cbam_post error handling should be applied + */ + @Test + public void testInvalidPost() { + //given + recievedLcn.setOperation(OperationType.SCALE); + recievedLcn.setStatus(OperationStatus.FAILED); + recievedLcn.setLifecycleOperationOccurrenceId(scaleOperation.getId()); + ScaleVnfRequest request = new ScaleVnfRequest(); + request.setAdditionalParams(new JsonParser().parse("{ \"type\" : \"IN\", \"jobId\" : \"" + JOB_ID + "\" }")); + request.setType(ScaleDirection.OUT); + scaleOperation.setOperationParams(request); + scaleOperation.setStatus(OperationStatus.FAILED); + JsonObject operationResult = ((JsonObject) scaleOperation.getAdditionalData()).get("operationResult").getAsJsonObject(); + operationResult.remove("cbam_post"); + operationResult.addProperty("cbam_post", ""); + scaleOperation.setOperationType(OperationType.SCALE); + //when + lifecycleChangeNotificationManager.handleLcn(recievedLcn); + assertFalse(affectedConnectionPoints.getValue().isPresent()); + verify(logger).warn("The operation failed and the affected connection points were not reported"); + } + + + /** * test end notification success scenario for scale-out * - LCN is sent to VF-C */ @@ -419,24 +547,6 @@ public class TestLifecycleChangeNotificationManager extends TestBase { } } - /** - * missing connection points are tolerated in case of failed operations - */ - @Test - public void testMissingConnectionPoints() { - //given - recievedLcn.setOperation(OperationType.INSTANTIATE); - recievedLcn.setStatus(OperationStatus.FAILED); - recievedLcn.setLifecycleOperationOccurrenceId(instantiationOperation.getId()); - instantiationOperation.setAdditionalData(null); - instantiationOperation.setStatus(OperationStatus.FAILED); - //when - lifecycleChangeNotificationManager.handleLcn(recievedLcn); - assertEquals(0, affectedConnectionPoints.getValue().getPost().size()); - assertEquals(0, affectedConnectionPoints.getValue().getPre().size()); - verify(logger).warn("The operation failed and the affected connection points were not reported"); - } - private JsonObject buildTerminationParams() { JsonObject root = new JsonObject(); root.add("terminationType", new JsonPrimitive("GRACEFULL")); diff --git a/nokiav2/driver/src/test/resources/unittests/packageconverter/nodes.vnfd.cbam.yaml b/nokiav2/driver/src/test/resources/unittests/packageconverter/nodes.vnfd.cbam.yaml index a5e18eec..4f8415e6 100644 --- a/nokiav2/driver/src/test/resources/unittests/packageconverter/nodes.vnfd.cbam.yaml +++ b/nokiav2/driver/src/test/resources/unittests/packageconverter/nodes.vnfd.cbam.yaml @@ -18,6 +18,7 @@ topology_template: - virtual_compute: myCompute - virtual_storage: myStorage1 - virtual_storage: myStorage2 + - unhandled_type: unknown myCompute: @@ -64,6 +65,30 @@ topology_template: - virtual_binding: vduNode - virtual_link: myNetwork1 + icpWithOutDescription: + type: tosca.nodes.nfv.ICP + properties: + layer_protocol: ipv4 + requirements: + - virtual_binding: vduNode + - virtual_link: myNetwork1 + + icpWithoutVdu: + type: tosca.nodes.nfv.ICP + properties: + layer_protocol: ipv4 + description: myDescription + requirements: + - virtual_link: myNetwork1 + + icpWithOutVl: + type: tosca.nodes.nfv.ICP + properties: + layer_protocol: ipv4 + description: myDescription + requirements: + - virtual_binding: vduNode + myEcp: type: tosca.nodes.nfv.ECP properties: @@ -71,15 +96,56 @@ topology_template: requirements: - internal_connection_point: icpWithEcp + myEcpWithDescription: + type: tosca.nodes.nfv.ECP + properties: + layer_protocol: ipv4 + requirements: + - internal_connection_point: icpWithOutDescription + + myEcpWithoutIcpWithoutVdu: + type: tosca.nodes.nfv.ECP + properties: + layer_protocol: ipv4 + requirements: + - internal_connection_point: icpWithoutVdu + + myEcpWithoutIcpWithoutIcpReq: + type: tosca.nodes.nfv.ECP + properties: + layer_protocol: ipv4 + requirements: + - internal_connection_point: icpWithOutRequiements + + myEcpWithoutIcp: + type: tosca.nodes.nfv.ECP + properties: + layer_protocol: ipv4 + requirements: + - not_valid: d + icpWithOutVdu: type: tosca.nodes.nfv.ICP properties: layer_protocol: ipv4 description: myDescription + requirements: + - not_valid: a + + icpWithOutRequiements: + type: tosca.nodes.nfv.ICP + properties: + layer_protocol: ipv4 + description: myDescription ecpWithIcpWithOutVdu: type: tosca.nodes.nfv.ECP properties: layer_protocol: ipv4 requirements: - - internal_connection_point: icpWithOutVdu
\ No newline at end of file + - internal_connection_point: icpWithOutVdu + + ecpWithIcpWithOutRequirements: + type: tosca.nodes.nfv.ECP + properties: + layer_protocol: ipv4
\ No newline at end of file diff --git a/nokiav2/driver/src/test/resources/unittests/packageconverter/nodes.vnfd.onap.yaml b/nokiav2/driver/src/test/resources/unittests/packageconverter/nodes.vnfd.onap.yaml index ddb96bf0..51842a87 100644 --- a/nokiav2/driver/src/test/resources/unittests/packageconverter/nodes.vnfd.onap.yaml +++ b/nokiav2/driver/src/test/resources/unittests/packageconverter/nodes.vnfd.onap.yaml @@ -70,6 +70,14 @@ topology_template: requirements: - virtual_binding: vduNode - virtual_link: myNetwork1 + icpWithOutDescription: + type: tosca.nodes.nfv.VduCpd + properties: + layer_protocol: ipv4 + role: leaf + requirements: + - virtual_binding: vduNode + - virtual_link: myNetwork1 myEcp: type: tosca.nodes.nfv.VduCpd properties: @@ -78,3 +86,10 @@ topology_template: description: myDescription requirements: - virtual_binding: vduNode + myEcpWithDescription: + type: tosca.nodes.nfv.VduCpd + properties: + layer_protocol: ipv4 + role: leaf + requirements: + - virtual_binding: vduNode diff --git a/nokiav2/driver/src/test/resources/unittests/vnfd.scale.yaml b/nokiav2/driver/src/test/resources/unittests/vnfd.scale.yaml index 478fedaf..87493f58 100644 --- a/nokiav2/driver/src/test/resources/unittests/vnfd.scale.yaml +++ b/nokiav2/driver/src/test/resources/unittests/vnfd.scale.yaml @@ -1,5 +1,13 @@ topology_template: policies: + - unkown_policy: + properties: + aspects: + aspect1: + vdus: + vdu1: + - heatResource: wrapper_rg.0.server + - heatResource: wrapper_rg.1.server - heat_mapping: properties: aspects: @@ -9,4 +17,7 @@ topology_template: - heatResource: wrapper_rg.0.server - heatResource: wrapper_rg.1.server vdu2: - - heatResource: wrapper_rg2.0.server
\ No newline at end of file + - heatResource: wrapper_rg2.0.server + emptyAspect: # does not make sense + aspectWithOutVdu: # does not make sense + network:
\ No newline at end of file |