summaryrefslogtreecommitdiffstats
path: root/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm
diff options
context:
space:
mode:
authorDenes Nemeth <denes.nemeth@nokia.com>2018-03-08 21:44:02 +0100
committerDenes Nemeth <denes.nemeth@nokia.com>2018-03-08 21:44:02 +0100
commitf6228e56abb06a36212216bc5674e69e6c0d9610 (patch)
treee4f212d8c47c2484343989794fa93f6bd5566392 /nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm
parent270744e18b624e750e3a5f4fac59780068196147 (diff)
Adding missing tests
Change-Id: I2b0de4c101535259f133436d6997ae393ba6c8ef Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com> Issue-ID: VFC-728
Diffstat (limited to 'nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm')
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestLifecycleManager.java19
-rw-r--r--nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/notification/TestLifecycleChangeNotificationManager.java162
2 files changed, 150 insertions, 31 deletions
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"));