public void deRegister() {
try {
logger.info("Cancelling micro service registration");
- systemFunctions().blockingFirst(msbApiProvider.getMsbApi().deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null));
+ msbApiProvider.getMsbApi().deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null).blockingFirst();
} catch (Exception e) {
//ONAP throws 500 internal server error, but deletes the micro service
boolean serviceFoundAfterDelete = false;
for (Subscription subscription : lcnApi.subscriptionsGet(NOKIA_LCN_API_VERSION).blockingFirst()) {
if (subscription.getCallbackUrl().equals(callbackUrl)) {
logger.info("Deleting subscription with {} identifier", subscription.getId());
- systemFunctions().blockingFirst(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION));
+ lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION).blockingFirst();
}
}
} catch (Exception e) {
import org.onap.aai.model.Relationship;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.AAIRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.Conditions;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties;
import org.slf4j.Logger;
//FIXME whould be good to know if this parameter is relevant or not? (mandatory)
vnf.setVnfType("NokiaVNF");
vnf.setIsClosedLoopDisabled(inMaintenance);
- SystemFunctions.systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkGenericVnfsGenericVnf(vnf.getVnfId(), vnf));
+ aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkGenericVnfsGenericVnf(vnf.getVnfId(), vnf).blockingFirst();
}
private GenericVnf waitForVnfToAppearInAai(String vnfId) {
import org.springframework.stereotype.Component;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
void delete(String vnfId, AffectedVirtualLink removedVl) {
L3Network l3Network = getNetwork(vnfId, removedVl).blockingFirst();
- systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().deleteNetworkL3NetworksL3Network(l3Network.getNetworkId(), l3Network.getResourceVersion()));
+ aaiRestApiProvider.getNetworkApi().deleteNetworkL3NetworksL3Network(l3Network.getNetworkId(), l3Network.getResourceVersion()).blockingFirst();
}
private void updateNetworkFields(String vimId, String vnfId, AffectedVirtualLink affectedVirtualLink, L3Network network) {
addMissingRelation(network.getRelationshipList(), GenericVnfManager.linkTo(vnfId));
addSingletonRelation(network.getRelationshipList(), getRegionLink(vimId));
addSingletonRelation(network.getRelationshipList(), getTenantLink(vimId, extractMandatoryValue(affectedVirtualLink.getResource().getAdditionalData(), "tenantId")));
- systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkL3NetworksL3Network(network.getNetworkId(), network));
+ aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkL3NetworksL3Network(network.getNetworkId(), network).blockingFirst();
}
private String buildNetworkId(String vnfId, AffectedVirtualLink affectedVirtualLink) {
import static java.lang.String.format;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
String tenantId = affectedCp.getTenantId();
String vServerId = affectedCp.getServerProviderId();
String cpId = affectedCp.getCpId();
- systemFunctions().blockingFirst(aaiRestApiProvider.getCloudInfrastructureApi().createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(cloudOwner, regionName, tenantId, vServerId, cpId, logicalInterface));
+ aaiRestApiProvider.getCloudInfrastructureApi().createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(cloudOwner, regionName, tenantId, vServerId, cpId, logicalInterface).blockingFirst();
}
}
import org.springframework.stereotype.Component;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
/**
* Responsible for managing {@link Vnfc} in AAI
void delete(String vnfId, com.nokia.cbam.lcm.v32.model.AffectedVnfc cbamVnfc) {
Vnfc vnfc = getVnfc(buildId(vnfId, cbamVnfc.getId())).blockingFirst();
- systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().deleteNetworkVnfcsVnfc(vnfc.getVnfcName(), vnfc.getResourceVersion()));
+ aaiRestApiProvider.getNetworkApi().deleteNetworkVnfcsVnfc(vnfc.getVnfcName(), vnfc.getResourceVersion()).blockingFirst();
}
private Observable<Vnfc> getVnfc(String vnfcId) {
}
addSingletonRelation(aaiVnfc.getRelationshipList(), VserverManager.linkTo(vimId, tenantId, cbamVnfc.getComputeResource().getResourceId()));
addSingletonRelation(aaiVnfc.getRelationshipList(), GenericVnfManager.linkTo(vnfId));
- systemFunctions().blockingFirst(aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkVnfcsVnfc(aaiVnfc.getVnfcName(), aaiVnfc));
+ aaiRestApiProvider.getNetworkApi().createOrUpdateNetworkVnfcsVnfc(aaiVnfc.getVnfcName(), aaiVnfc).blockingFirst();
}
}
\ No newline at end of file
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties;
import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;
import static com.google.common.collect.Iterables.find;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.childElement;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getCloudOwner;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.LifecycleManager.getRegionName;
@Component
@Conditional(value = Conditions.UseForDirect.class)
class VserverManager extends AbstractManager {
- private static Logger logger = org.slf4j.LoggerFactory.getLogger(AbstractManager.class);
+ private static Logger logger = LoggerFactory.getLogger(AbstractManager.class);
@Autowired
VserverManager(AAIRestApiProvider aaiRestApiProvider, CbamRestApiProvider cbamRestApiProvider, DriverProperties driverProperties) {
server.setVserverName(additionalData.getAsJsonObject().get("name").getAsString());
server.setVserverId(cbamVnfc.getComputeResource().getResourceId());
server.setProvStatus("active");
- server.setRelationshipList(new ArrayList<>());
server.setVserverId(cbamVnfc.getComputeResource().getResourceId());
server.setVserverSelflink(extractSelfLink(cbamVnfc.getComputeResource().getAdditionalData()));
+ if (server.getRelationshipList() == null) {
+ server.setRelationshipList(new ArrayList<>());
+ }
addSingletonRelation(server.getRelationshipList(), GenericVnfManager.linkTo(vnfId));
+ server.setVolumes(new ArrayList<>());
if (cbamVnfc.getStorageResourceIds() != null) {
- if (server.getVolumes() == null) {
- server.setVolumes(new ArrayList<>());
- }
for (String virtualStorageId : cbamVnfc.getStorageResourceIds()) {
Volume volume = new Volume();
AffectedVirtualStorage affectedStorage = find(affectedVirtualStorages, storage -> virtualStorageId.equals(storage.getId()));
volume.setVolumeId(affectedStorage.getResource().getResourceId());
server.getVolumes().add(volume);
}
- } else {
- server.setVolumes(new ArrayList<>());
}
String tenantId = getTenantId(cbamVnfc);
String cloudOwner = getCloudOwner(vimId);
String regionName = getRegionName(vimId);
- systemFunctions().blockingFirst(aaiRestApiProvider.getCloudInfrastructureApi().createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(cloudOwner, regionName, tenantId, server.getVserverId(), server));
+ aaiRestApiProvider.getCloudInfrastructureApi().createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(cloudOwner, regionName, tenantId, server.getVserverId(), server).blockingFirst();
}
private String extractSelfLink(Object additionalData) {
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer;
import com.google.gson.*;
-import java.io.IOException;
import java.io.StringReader;
import org.yaml.snakeyaml.Yaml;
* @param cbamVnfdContent the original CBAM VNFD
* @return the modified content CBAM VNFD
*/
- public String build(String cbamVnfdContent) throws IOException {
+ public String build(String cbamVnfdContent) {
JsonObject root = new Gson().toJsonTree(new Yaml().load(cbamVnfdContent)).getAsJsonObject();
JsonObject substitutionMappings = child(child(root, "topology_template"), "substitution_mappings");
JsonObject extensions = addChild(addChild(addChild(addChild(addChild(substitutionMappings, "capabilities"), "vnf"), "properties"), "modifiable_attributes"), "extensions");
package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util;
import com.google.common.io.ByteStreams;
-import io.reactivex.Observable;
import java.io.InputStream;
import java.io.PrintStream;
-import java.util.NoSuchElementException;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
public CloseableHttpClient getHttpClient() {
return HttpClients.createDefault();
}
-
- /**
- * Execute blocking first
- *
- * @param observable the observable
- */
- public void blockingFirst(Observable<Void> observable) {
- try {
- observable.blockingFirst();
- } catch (NoSuchElementException e) {
- //swallow void returns null :)
- }
- }
-
}
\ No newline at end of file
import org.springframework.stereotype.Component;
/**
- * Responsible for providing SSL factories for AAI
+ * Responsible for providing SSL factories for CBAM
*/
@Component
public class CbamSecurityProvider extends GenericSecurityProvider {
accessInfov3.setProject(vim.getAccessInfo().getTenant());
accessInfov3.setRegion(getRegionName(vimId));
accessInfov3.setUsername(vimInfo.getUserName());
- EndpointInfo interfaceInfoV3 = new EndpointInfo();
- interfaceInfoV3.setEndpoint(vimInfo.getUrl());
- if (!isEmpty(vimInfo.getSslInsecure())) {
- interfaceInfoV3.setSkipCertificateVerification(Boolean.parseBoolean(vimInfo.getSslInsecure()));
- interfaceInfoV3.setSkipCertificateHostnameCheck(Boolean.parseBoolean(vimInfo.getSslInsecure()));
- } else {
- interfaceInfoV3.setSkipCertificateHostnameCheck(true);
- interfaceInfoV3.setSkipCertificateVerification(true);
- }
- if (!interfaceInfoV3.isSkipCertificateVerification()) {
- interfaceInfoV3.setTrustedCertificates(new ArrayList<>());
- for (String trustedCertificate : StoreLoader.getCertifacates(vimInfo.getSslCacert())) {
- interfaceInfoV3.getTrustedCertificates().add(trustedCertificate.getBytes(UTF_8));
- }
- }
- openstackv3INFO.setInterfaceInfo(interfaceInfoV3);
+ openstackv3INFO.setInterfaceInfo(getEndpointInfo(vimInfo));
openstackv3INFO.setId(vimId);
return openstackv3INFO;
}
accessInfo.setTenant(vim.getAccessInfo().getTenant());
accessInfo.setUsername(vimInfo.getUserName());
accessInfo.setRegion(getRegionName(vimId));
+ EndpointInfo interfaceEndpoint = getEndpointInfo(vimInfo);
+ openstackv2INFO.setInterfaceInfo(interfaceEndpoint);
+ openstackv2INFO.setId(vimId);
+ return openstackv2INFO;
+ }
+
+ private EndpointInfo getEndpointInfo(VimInfo vimInfo) {
EndpointInfo interfaceEndpoint = new EndpointInfo();
if (!isEmpty(vimInfo.getSslInsecure())) {
interfaceEndpoint.setSkipCertificateHostnameCheck(Boolean.parseBoolean(vimInfo.getSslInsecure()));
interfaceEndpoint.getTrustedCertificates().add(trustedCertificate.getBytes(UTF_8));
}
}
- openstackv2INFO.setInterfaceInfo(interfaceEndpoint);
- openstackv2INFO.setId(vimId);
- return openstackv2INFO;
+ return interfaceEndpoint;
}
private VMWAREVCLOUDINFO buildVcloudInfo(String vimId, org.onap.vnfmdriver.model.VimInfo vimInfo) {
accessInfo.setPassword(vimInfo.getPassword());
accessInfo.setUsername(vimInfo.getUserName());
accessInfo.setOrganization(getRegionName(vimId));
- EndpointInfo interfaceEndpoint = new EndpointInfo();
- if (!isEmpty(vimInfo.getSslInsecure())) {
- interfaceEndpoint.setSkipCertificateHostnameCheck(Boolean.parseBoolean(vimInfo.getSslInsecure()));
- interfaceEndpoint.setSkipCertificateVerification(Boolean.parseBoolean(vimInfo.getSslInsecure()));
- } else {
- interfaceEndpoint.setSkipCertificateHostnameCheck(true);
- interfaceEndpoint.setSkipCertificateVerification(true);
- }
- interfaceEndpoint.setEndpoint(vimInfo.getUrl());
- if (!interfaceEndpoint.isSkipCertificateVerification()) {
- interfaceEndpoint.setTrustedCertificates(new ArrayList<>());
- for (String trustedCertificate : StoreLoader.getCertifacates(vimInfo.getSslCacert())) {
- interfaceEndpoint.getTrustedCertificates().add(trustedCertificate.getBytes(UTF_8));
- }
- }
- vcloudInfo.setInterfaceInfo(interfaceEndpoint);
+ vcloudInfo.setInterfaceInfo(getEndpointInfo(vimInfo));
vcloudInfo.setId(vimId);
return vcloudInfo;
}
if (vnf.getInstantiationState() == INSTANTIATED) {
terminateVnf(vnfmId, vnfId, jobInfo, cbamRequest, vnf);
} else {
- systemFunctions().blockingFirst(cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION));
+ cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
}
});
}
if (finishedOperation.getStatus() == FINISHED) {
notificationManager.waitForTerminationToBeProcessed(finishedOperation.getId());
logger.info("Deleting VNF with {}", vnfId);
- systemFunctions().blockingFirst(cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION));
+ cbamRestApiProvider.getCbamLcmApi(vnfmId).vnfsVnfInstanceIdDelete(vnfId, NOKIA_LCM_API_VERSION).blockingFirst();
logger.info("VNF with {} has been deleted", vnfId);
} else {
//calculated from operation execution result
logger.warn("Unable to send information related to affected connection points during forceful termination");
return empty();
+ } else {
+ //graceful termination should be handled as any other operation
}
}
try {
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.onap.msb.ApiClient;
import org.onap.msb.api.ServiceResourceApi;
import org.onap.msb.model.MicroServiceFullInfo;
}
}
+ /**
+ * Test API wrapping for LCM
+ * (questionable benefit [ this is more less ensured by Java type safety) ]
+ */
+ @Test
+ public void testOperationExecutionsApiAPiWrapping() {
+ ApiClient c = Mockito.mock(ApiClient.class);
+ class TestClasss extends MsbApiProvider {
+
+ TestClasss(Environment environment) {
+ super(environment);
+ }
+
+ @Override
+ ApiClient buildApiClient() {
+ return c;
+ }
+ }
+ ServiceResourceApi defaultApi = Mockito.mock(ServiceResourceApi.class);
+ when(c.createService(ServiceResourceApi.class)).thenReturn(defaultApi);
+ //verify
+ TestClasss testInstnace = new TestClasss(environment);
+ assertEquals(defaultApi, testInstnace.getMsbApi());
+ }
+
}
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSocketFactory;
+import okhttp3.Interceptor;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.Response;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.onap.aai.api.CloudInfrastructureApi;
import org.onap.aai.api.ExternalSystemApi;
import org.onap.aai.api.NetworkApi;
+import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
import static junit.framework.TestCase.assertEquals;
assertEquals("http://1.2.3.4/a/", apiClient.getAdapterBuilder().build().baseUrl().toString());
assertEquals(sslSocketFactoryResultCaptor.getResult(), apiClient.getOkBuilder().build().sslSocketFactory());
assertEquals(hostnameVerifier, apiClient.getOkBuilder().build().hostnameVerifier());
+
+ //given
Response resp = new Response.Builder().message("a").code(200).protocol(Protocol.HTTP_1_0).request(new Request.Builder().url("http://1.2.3.4/d").build()).build();
+ //when
Request authenticate = apiClient.getOkBuilder().build().authenticator().authenticate(null, resp);
+ //verify
assertEquals("Basic dXNlcm5hbWU6YWFpUGFzc3dvcmQ=", authenticate.headers().get("Authorization"));
+
+ //given
+ Interceptor.Chain chain = Mockito.mock(Interceptor.Chain.class);
+ when(chain.request()).thenReturn(new Request.Builder().url("http://1.2.3.4/d").build());
+ ArgumentCaptor<Request> modifedRequest = ArgumentCaptor.forClass(Request.class);
+ when(chain.proceed(modifedRequest.capture())).thenReturn(resp);
+ //when
+ apiClient.getOkBuilder().interceptors().get(0).intercept(chain);
+ //verify
+ assertEquals(SelfRegistrationManager.SERVICE_NAME, modifedRequest.getValue().header("X-FromAppId"));
+
}
/**
when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenAnswer(invocation -> {
vnfs.add(vnfInAaai);
- return null;
+ return VOID_OBSERVABLE.value();
});
vnfInfo.setName("vnfName");
//when
assertEquals("vnfName", vnfSentToAai.getVnfName());
verify(systemFunctions, times(10)).sleep(3000);
verify(networkApi, times(10)).getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
+ VOID_OBSERVABLE.assertCalled();
}
/**
vnfInAaai.setResourceVersion("v1");
when(networkApi.getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(vnfInAaai));
when(cbamRestApiProvider.getCbamLcmApi(VNFM_ID).vnfsVnfInstanceIdGet(VNF_ID, CbamRestApiProvider.NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(vnfInfo));
- when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenReturn(null);
+ when(networkApi.createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
vnfInfo.setName("vnfName");
//when
genericVnfManager.createOrUpdate(VNF_ID, true);
assertEquals(TRUE, vnfSentToAai.isIsClosedLoopDisabled());
assertEquals("vnfName", vnfSentToAai.getVnfName());
verify(systemFunctions, never()).sleep(anyLong());
+ VOID_OBSERVABLE.assertCalled();
verify(networkApi, times(1)).getNetworkGenericVnfsGenericVnf(VNF_ID, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
}
if (vnfSentToAAi.getResourceVersion() == null) {
throw runtimeException;
}
- return null;
+ return VOID_OBSERVABLE.value();
});
vnfInfo.setName("vnfName");
//when
verify(networkApi, times(2)).createOrUpdateNetworkGenericVnfsGenericVnf(eq(VNF_ID), any());
verify(logger).warn(eq("The VNF with myVnfId identifier did not appear in time"), any(NoSuchElementException.class));
verify(logger).warn("The VNF with myVnfId identifier has been created since after the maximal wait for VNF to appear timeout", runtimeException);
+ VOID_OBSERVABLE.assertCalled();
}
/**
affectedVirtualLink.getResource().setResourceId("netProviderId");
L3Network existingNetwork = new L3Network();
when(networkApi.getNetworkL3NetworksL3Network("myVnfId_vlId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingNetwork));
- when(networkApi.createOrUpdateNetworkL3NetworksL3Network(eq("myVnfId_vlId"), payload.capture())).thenReturn(null);
+ when(networkApi.createOrUpdateNetworkL3NetworksL3Network(eq("myVnfId_vlId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
//when
l3NetworkManager.update(VIM_ID, VNF_ID, affectedVirtualLink);
//verify
assertRelation(payload.getValue().getRelationshipList(), "cloud-region", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)));
assertRelation(payload.getValue().getRelationshipList(), "tenant", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)), buildRelationshipData("tenant.tenant-id", "myTenantId"));
assertRelation(payload.getValue().getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
+ VOID_OBSERVABLE.assertCalled();
}
/**
l3Network.setResourceVersion("v3");
l3Network.setRelationshipList(new ArrayList<>());
when(networkApi.getNetworkL3NetworksL3Network("myVnfId_vlId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(l3Network));
- when(networkApi.createOrUpdateNetworkL3NetworksL3Network(eq("myVnfId_vlId"), payload.capture())).thenReturn(null);
+ when(networkApi.createOrUpdateNetworkL3NetworksL3Network(eq("myVnfId_vlId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
//when
l3NetworkManager.update(VIM_ID, VNF_ID, affectedVirtualLink);
//verify
assertRelation(payload.getValue().getRelationshipList(), "cloud-region", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)));
assertRelation(payload.getValue().getRelationshipList(), "tenant", buildRelationshipData("cloud-region.cloud-owner", getCloudOwner(VIM_ID)), buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)), buildRelationshipData("tenant.tenant-id", "myTenantId"));
assertRelation(payload.getValue().getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
+ VOID_OBSERVABLE.assertCalled();
}
/**
affectedVirtualLink.setId("vlId");
L3Network l3Network = new L3Network();
l3Network.setResourceVersion("v3");
+ l3Network.setNetworkId("myVnfId_vlId");
when(networkApi.getNetworkL3NetworksL3Network("myVnfId_vlId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(l3Network));
+ when(networkApi.deleteNetworkL3NetworksL3Network("myVnfId_vlId", "v3")).thenReturn(VOID_OBSERVABLE.value());
//when
l3NetworkManager.delete(VNF_ID, affectedVirtualLink);
//verify
networkApi.deleteNetworkL3NetworksL3Network("myVnfId_vlId", "v3");
+ VOID_OBSERVABLE.assertCalled();
}
/**
lInterface.setResourceVersion("v3");
lInterface.setRelationshipList(new ArrayList<>());
when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(lInterface));
- when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(null);
+ when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
//when
lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, true);
//verify
assertEquals("networkProviderId", actualInterface.getL3InterfaceIpv4AddressList().get(0).getNeutronNetworkId());
assertEquals("1.2.3.4", actualInterface.getL3InterfaceIpv4AddressList().get(0).getL3InterfaceIpv4Address());
assertRelation(actualInterface.getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
+ VOID_OBSERVABLE.assertCalled();
}
/**
affectedCp.setCpId("cpId");
LInterface lInterface = new LInterface();
lInterface.setResourceVersion("v3");
- lInterface.setRelationshipList(new ArrayList<>());
when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(lInterface));
- when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(null);
+ when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
//when
lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, true);
//verify
assertEquals(null, actualInterface.getL3InterfaceIpv6AddressList());
assertEquals(null, actualInterface.getL3InterfaceIpv4AddressList());
assertRelation(actualInterface.getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
+ VOID_OBSERVABLE.assertCalled();
}
/**
LInterface lInterface = new LInterface();
lInterface.setResourceVersion("v3");
lInterface.setRelationshipList(new ArrayList<>());
+ lInterface.getRelationshipList().add(VserverManager.linkTo(VIM_ID, "b", "c"));
when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(lInterface));
- when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(null);
+ when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
//when
lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, true);
//verify
assertEquals("1.2.3.4", actualInterface.getL3InterfaceIpv4AddressList().get(0).getL3InterfaceIpv4Address());
assertEquals("v3", lInterface.getResourceVersion());
assertRelation(actualInterface.getRelationshipList(), "generic-vnf", buildRelationshipData("generic-vnf.vnf-id", VNF_ID));
+ assertEquals(2, lInterface.getRelationshipList().size());
+ VOID_OBSERVABLE.assertCalled();
}
/**
lInterface.setResourceVersion("v3");
lInterface.setRelationshipList(new ArrayList<>());
when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", null, null, null, null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(lInterface));
- when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(null);
+ when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), eq("cpId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
//when
lInterfaceManager.update(VNF_ID, VIM_ID, affectedCp, false);
//verify
lInterfaceManager.delete(VIM_ID, affectedCp);
//verify
cloudInfrastructureApi.deleteCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserverLInterfacesLInterface("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "cpId", "v3");
+ VOID_OBSERVABLE.assertCalled();
}
/**
import com.nokia.cbam.lcm.v32.model.AffectedVnfc;
import com.nokia.cbam.lcm.v32.model.ResourceHandle;
+import java.util.ArrayList;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
affectedVnfc.getComputeResource().setResourceId("serverProviderId");
affectedVnfc.setId("vnfcId");
Vnfc existingVnfc = new Vnfc();
+ existingVnfc.setRelationshipList(new ArrayList<>());
+ existingVnfc.getRelationshipList().add(GenericVnfManager.linkTo("any"));
when(networkApi.getNetworkVnfcsVnfc("myVnfId_vnfcId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVnfc));
- when(networkApi.createOrUpdateNetworkVnfcsVnfc(eq("myVnfId_vnfcId"), payload.capture())).thenReturn(null);
+ when(networkApi.createOrUpdateNetworkVnfcsVnfc(eq("myVnfId_vnfcId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
//when
vnfcManager.update(VIM_ID, "myTenantPrivderId", VNF_ID, affectedVnfc, true);
//verify
buildRelationshipData("cloud-region.cloud-region-id", getRegionName(VIM_ID)),
buildRelationshipData("tenant.tenant-id", "myTenantPrivderId"),
buildRelationshipData("vserver.vserver-id", "serverProviderId"));
+ assertEquals(2, vnfc.getRelationshipList().size());
+ VOID_OBSERVABLE.assertCalled();
}
/**
existingVnfc.setResourceVersion("v3");
existingVnfc.setVnfcName("myVnfId_vnfcId");
when(networkApi.getNetworkVnfcsVnfc("myVnfId_vnfcId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVnfc));
+ when(networkApi.deleteNetworkVnfcsVnfc("myVnfId_vnfcId", "v3")).thenReturn(VOID_OBSERVABLE.value());
//when
vnfcManager.delete(VNF_ID, affectedVnfc);
//verify
verify(networkApi).deleteNetworkVnfcsVnfc("myVnfId_vnfcId", "v3");
+ VOID_OBSERVABLE.assertCalled();
}
/**
affectedVnfc.setStorageResourceIds(new ArrayList<>());
affectedVnfc.getStorageResourceIds().add("sId");
- String url = "/cloud-regions/cloud-region///tenants/tenant//vservers/vserver/";
-
Vserver existingVserver = new Vserver();
- existingVserver.setVolumes(new ArrayList<>());
+ existingVserver.setRelationshipList(new ArrayList<>());
+ existingVserver.getRelationshipList().add(VserverManager.linkTo(VIM_ID, "tenantId", "serverId2"));
when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVserver));
- when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(null);
+ when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
//when
vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
//verify
assertEquals("url", vserver.getVserverSelflink());
assertEquals(1, vserver.getVolumes().size());
assertEquals("storageProviderId", vserver.getVolumes().get(0).getVolumeId());
+ assertEquals(2, vserver.getRelationshipList().size());
+ VOID_OBSERVABLE.assertCalled();
}
/**
Vserver existingVserver = new Vserver();
existingVserver.setVolumes(new ArrayList<>());
when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVserver));
- when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(null);
+ when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
//when
vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
//verify
assertEquals("unknown", vserver.getVserverSelflink());
assertEquals(1, vserver.getVolumes().size());
assertEquals("storageProviderId", vserver.getVolumes().get(0).getVolumeId());
+ VOID_OBSERVABLE.assertCalled();
}
/**
Vserver existingVserver = new Vserver();
existingVserver.setVolumes(new ArrayList<>());
when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVserver));
- when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(null);
+ when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
//when
vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
//verify
assertEquals("unknown", vserver.getVserverSelflink());
assertEquals(1, vserver.getVolumes().size());
assertEquals("storageProviderId", vserver.getVolumes().get(0).getVolumeId());
+ VOID_OBSERVABLE.assertCalled();
}
/**
Vserver existingVserver = new Vserver();
existingVserver.setVolumes(new ArrayList<>());
when(cloudInfrastructureApi.getCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", null, null, null, null, null, null, null, null, null)).thenReturn(buildObservable(existingVserver));
- when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(null);
+ when(cloudInfrastructureApi.createOrUpdateCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver(eq("myCloudOwnerId"), eq("myRegionName"), eq("myTenantId"), eq("serverProviderId"), payload.capture())).thenReturn(VOID_OBSERVABLE.value());
//when
vserverManager.update(VIM_ID, VNF_ID, affectedVnfc, affectedStorages, true);
//verify
vserverManager.delete(VIM_ID, affectedVnfc);
//verify
verify(cloudInfrastructureApi).deleteCloudInfrastructureCloudRegionsCloudRegionTenantsTenantVserversVserver("myCloudOwnerId", "myRegionName", "myTenantId", "serverProviderId", "v3");
+ VOID_OBSERVABLE.assertCalled();
}
@Test
import com.nokia.cbam.lcm.v32.api.VnfsApi;
import com.nokia.cbam.lcn.v32.api.SubscriptionsApi;
import io.reactivex.Observable;
+import io.reactivex.internal.operators.observable.ObservableFromCallable;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.Callable;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.servlet.http.HttpServletResponse;
+import junit.framework.TestCase;
import okhttp3.RequestBody;
import okio.Buffer;
import org.apache.commons.lang3.ArrayUtils;
import static org.mockito.Mockito.when;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CatalogManager.getFileInZip;
+
public class TestBase {
+
public static final String VNF_ID = "myVnfId";
public static final String VNFM_ID = "myVnfmId";
public static final String ONAP_CSAR_ID = "myOnapCsarId";
public static final String JOB_ID = "myJobId";
public static final String CBAM_VNFD_ID = "cbamVnfdId";
protected static Call<Void> VOID_CALL = buildCall(null);
+ protected static VoidObservable VOID_OBSERVABLE = new VoidObservable();
@Mock
protected CbamRestApiProvider cbamRestApiProvider;
@Mock
}
}
}
+
+ protected static class VoidObservable {
+ boolean called = false;
+ ObservableFromCallable<Void> s = new ObservableFromCallable(new Callable() {
+ @Override
+ public Object call() throws Exception {
+ called = true;
+ return "";
+ }
+ });
+
+ public void assertCalled() {
+ TestCase.assertTrue(called);
+ }
+
+ public Observable<Void> value() {
+ return s;
+ }
+ }
}
assertTrue(jobManager.hasOngoingJobs());
}
+ /**
+ * the modify attribute job is skipped, since it is not explicitly triggered by any external job
+ */
+ @Test
+ public void testModifyAttributesOperationExecutionIsSkipped() throws Exception {
+ String jobId = jobManager.spawnJob(VNF_ID, httpResponse);
+ VnfInfo vnf = new VnfInfo();
+ vnf.setId(VNF_ID);
+ vnfs.add(vnf);
+ VnfInfo detailedVnf = new VnfInfo();
+ detailedVnf.setId(VNF_ID);
+ when(vnfApi.vnfsVnfInstanceIdGet(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(detailedVnf));
+ OperationExecution olderOperation = new OperationExecution();
+ olderOperation.setId(UUID.randomUUID().toString());
+ olderOperation.setStartTime(OffsetDateTime.now());
+ olderOperation.setStatus(OperationStatus.FINISHED);
+ olderOperation.setOperationType(OperationType.TERMINATE);
+ OperationExecution newerOperation = new OperationExecution();
+ newerOperation.setId(UUID.randomUUID().toString());
+ newerOperation.setStartTime(OffsetDateTime.now().plusDays(1));
+ newerOperation.setStatus(OperationStatus.FINISHED);
+ newerOperation.setOperationType(OperationType.MODIFY_INFO);
+ detailedVnf.setOperationExecutions(new ArrayList<>());
+ detailedVnf.getOperationExecutions().add(olderOperation);
+ detailedVnf.getOperationExecutions().add(newerOperation);
+ JsonElement operationParams = new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + jobId + "\"}}");
+ List<String> queriedOperaionsInOrder = new ArrayList<>();
+ when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(Mockito.anyString(), Mockito.eq(NOKIA_LCM_API_VERSION)))
+ .then(new Answer<Observable<Object>>() {
+ @Override
+ public Observable<Object> answer(InvocationOnMock invocationOnMock) throws Throwable {
+ queriedOperaionsInOrder.add(invocationOnMock.getArguments()[0].toString());
+ if (invocationOnMock.getArguments()[0].equals(olderOperation.getId())) {
+ return buildObservable(new JsonParser().parse("{ \"additionalParams\" : { \"jobId\" : \"" + jobId + "\"}}"));
+ } else {
+ throw new RuntimeException(); //this should be never reached
+ }
+ }
+ });
+ JobDetailInfo job = jobManager.getJob(VNFM_ID, jobId);
+ //verify
+ assertEquals(Lists.newArrayList(olderOperation.getId()), queriedOperaionsInOrder);
+ assertTrue(jobManager.hasOngoingJobs());
+ }
+
/**
* if the registration process has not finished it is prevented to spawn jobs
*/
return buildObservable(terminationOperation);
}
});
- Observable<Void> delete = Mockito.mock(Observable.class);
- when(vnfApi.vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(delete);
+ when(vnfApi.vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION)).thenReturn(VOID_OBSERVABLE.value());
JsonElement instantiationParameters = new JsonParser().parse("{ \"vims\" : [ { \"id\" : \"" + VIM_ID + "\" } ] } ");
when(operationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet("operationExecutionId", NOKIA_LCM_API_VERSION)).thenReturn(buildObservable(instantiationParameters));
//when
notificationIsProcessedBeforeDeletingTheVnf.verify(vfcGrantManager).requestGrantForTerminate(VNFM_ID, VNF_ID, VIM_ID, ONAP_CSAR_ID, vnfInfo, JOB_ID);
notificationIsProcessedBeforeDeletingTheVnf.verify(notificationManager).waitForTerminationToBeProcessed("terminationId");
notificationIsProcessedBeforeDeletingTheVnf.verify(vnfApi).vnfsVnfInstanceIdDelete(VNF_ID, NOKIA_LCM_API_VERSION);
- verify(systemFunctions).blockingFirst(delete);
+ VOID_OBSERVABLE.assertCalled();
verify(jobManager).spawnJob(VNF_ID, restResponse);
verify(logger).info(eq("Starting {} operation on VNF with {} identifier with {} parameter"), eq("termination"), eq(VNF_ID), anyString());
}
import static org.mockito.Mockito.*;
import static org.onap.msb.model.MicroServiceInfo.ProtocolEnum.REST;
import static org.onap.msb.model.MicroServiceInfo.VisualRangeEnum._1;
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager.DRIVER_VERSION;
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager.SERVICE_NAME;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider.NOKIA_LCN_API_VERSION;
import static org.springframework.test.util.ReflectionTestUtils.setField;
assertEquals(REST, microserviceRequest.getProtocol());
assertNull(microserviceRequest.getMetadata());
//very strange, but it should be null for ONAP to work
- assertEquals(SelfRegistrationManager.SERVICE_NAME, microserviceRequest.getServiceName());
+ assertEquals(SERVICE_NAME, microserviceRequest.getServiceName());
assertEquals("/api/NokiaSVNFM/v1", microserviceRequest.getUrl());
assertEquals("v1", microserviceRequest.getVersion());
assertEquals(Boolean.FALSE, microserviceRequest.isEnableSsl());
subscription.setCallbackUrl("http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn");
subscription.setId(UUID.randomUUID().toString());
subscriptions.add(subscription);
+ when(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION)).thenReturn(VOID_OBSERVABLE.value());
return buildObservable(subscription);
});
MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo();
subscription.setId(UUID.randomUUID().toString());
subscriptions.add(subscription);
when(jobManager.hasOngoingJobs()).thenReturn(false);
- Observable delete = Mockito.mock(Observable.class);
- when(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION)).thenReturn(delete);
+ when(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION)).thenReturn(VOID_OBSERVABLE.value());
+ VoidObservable MSB_DELETE = new VoidObservable();
+ when(msbClient.deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null)).thenReturn(MSB_DELETE.value());
//when
selfRegistrationManager.deRegister();
//verify
InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi);
- inOrder.verify(msbClient).deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null);
+ inOrder.verify(msbClient).deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null);
inOrder.verify(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
assertServiceDown();
- verify(systemFunctions).blockingFirst(delete);
+ VOID_OBSERVABLE.assertCalled();
+ MSB_DELETE.assertCalled();
verify(logger).info("Deleting subscription with {} identifier", subscription.getId());
}
subscription.setId(UUID.randomUUID().toString());
subscriptions.add(subscription);
when(jobManager.hasOngoingJobs()).thenReturn(false);
- when(msbClient.deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null)).then(new Answer<Observable<Void>>() {
+ when(msbClient.deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null)).then(new Answer<Observable<Void>>() {
@Override
public Observable<Void> answer(InvocationOnMock invocationOnMock) throws Throwable {
- when(msbClient.getMicroService_0(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null, null, null, null)).thenThrow(new RuntimeException());
+ when(msbClient.getMicroService_0(SERVICE_NAME, DRIVER_VERSION, null, null, null, null, null)).thenThrow(new RuntimeException());
throw new RuntimeException();
}
});
- MicroServiceFullInfo returnedMicroService = new MicroServiceFullInfo();
+ when(lcnApi.subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION)).thenReturn(VOID_OBSERVABLE.value());
//when
selfRegistrationManager.deRegister();
//verify
InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi);
- inOrder.verify(msbClient).deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null);
- inOrder.verify(msbClient).getMicroService_0(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null, null, null, null);
+ inOrder.verify(msbClient).deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null);
+ inOrder.verify(msbClient).getMicroService_0(SERVICE_NAME, DRIVER_VERSION, null, null, null, null, null);
inOrder.verify(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
assertServiceDown();
+ VOID_OBSERVABLE.assertCalled();
}
/**
subscription.setCallbackUrl("http://5.6.7.8:12345/api/NokiaSVNFM/v1/lcn");
subscription.setId(UUID.randomUUID().toString());
subscriptions.add(subscription);
- when(msbClient.deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null)).then(new Answer<Observable<Void>>() {
+ when(msbClient.deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null)).then(new Answer<Observable<Void>>() {
@Override
public Observable<Void> answer(InvocationOnMock invocationOnMock) throws Throwable {
throw new RuntimeException();
}
//verify
InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi);
- inOrder.verify(msbClient).deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null);
- inOrder.verify(msbClient).getMicroService_0(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null, null, null, null);
+ inOrder.verify(msbClient).deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null);
+ inOrder.verify(msbClient).getMicroService_0(SERVICE_NAME, DRIVER_VERSION, null, null, null, null, null);
verify(lcnApi, Mockito.never()).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
assertServiceDown();
}
when(jobManager.hasOngoingJobs()).thenReturn(false);
RuntimeException expectedException = new RuntimeException();
doThrow(expectedException).when(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
+ when(msbClient.deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null)).thenReturn(VOID_OBSERVABLE.value());
//when
try {
selfRegistrationManager.deRegister();
}
//verify
InOrder inOrder = Mockito.inOrder(jobManager, msbClient, lcnApi);
- inOrder.verify(msbClient).deleteMicroService(SelfRegistrationManager.SERVICE_NAME, SelfRegistrationManager.DRIVER_VERSION, null, null);
+ inOrder.verify(msbClient).deleteMicroService(SERVICE_NAME, DRIVER_VERSION, null, null);
inOrder.verify(lcnApi).subscriptionsSubscriptionIdDelete(subscription.getId(), NOKIA_LCN_API_VERSION);
assertServiceDown();
}
verify(logger).warn("Unable to send information related to affected connection points during forceful termination");
}
+ /**
+ * Forceful termination results in an empty affected connection points
+ */
+ @Test
+ public void testGracefullTermination() {
+ //given
+ recievedLcn.setOperation(OperationType.INSTANTIATE);
+ recievedLcn.setStatus(OperationStatus.FINISHED);
+ recievedLcn.setLifecycleOperationOccurrenceId(terminationOperation.getId());
+ ((JsonObject) terminationOperation.getOperationParams()).addProperty("terminationType", "GRACEFUL");
+ addEmptyModifiedConnectionPoints(terminationOperation);
+ terminationOperation.setStatus(OperationStatus.FINISHED);
+ terminationOperation.setOperationType(OperationType.TERMINATE);
+ //when
+ lifecycleChangeNotificationManager.handleLcn(recievedLcn);
+ assertTrue(affectedConnectionPoints.getValue().isPresent());
+ }
+
/**
* Failures in affected connection point processing are tolerated for failed operation
* (because the POST script was not able to run)