2 * Copyright 2016-2017, Nokia Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification;
18 import com.google.gson.JsonObject;
19 import com.nokia.cbam.lcm.v32.model.*;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.mockito.InOrder;
23 import org.mockito.Mock;
24 import org.mockito.Mockito;
25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedConnectionPoints;
27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedCp;
29 import java.util.ArrayList;
30 import java.util.UUID;
32 import static com.nokia.cbam.lcm.v32.model.ChangeType.*;
33 import static java.util.Optional.empty;
34 import static java.util.Optional.of;
35 import static org.mockito.Mockito.never;
36 import static org.mockito.Mockito.verify;
37 import static org.springframework.test.util.ReflectionTestUtils.setField;
39 public class TestAAINotificationProcessor extends TestBase {
41 private GenericVnfManager genericVnfManager;
43 private L3NetworkManager l3NetworkManager;
45 private LInterfaceManager lInterfaceManager;
47 private VnfcManager vnfcManager;
49 private VserverManager vserverManager;
50 private AAINotificationProcessor aaiNotificationProcessor;
54 aaiNotificationProcessor = new AAINotificationProcessor(genericVnfManager, l3NetworkManager, lInterfaceManager, vnfcManager, vserverManager);
55 setField(AAINotificationProcessor.class, "logger", logger);
59 * test objects are manipulated in correct order in AAA
60 * (other is dependency between the objects though relations)
63 public void testObjectManipulationOrder() throws Exception {
64 VnfLifecycleChangeNotification recievenNotification = new VnfLifecycleChangeNotification();
65 recievenNotification.setAffectedVnfcs(new ArrayList<>());
66 recievenNotification.setAffectedVirtualLinks(new ArrayList<>());
67 ArrayList<AffectedVirtualStorage> affectedVirtualStorages = new ArrayList<>();
68 recievenNotification.setAffectedVirtualStorages(affectedVirtualStorages);
69 recievenNotification.setVnfInstanceId(VNF_ID);
70 recievenNotification.setStatus(OperationStatus.STARTED);
71 AffectedVirtualLink addedLink = buildVl(recievenNotification, ADDED);
72 AffectedVirtualLink removedLink = buildVl(recievenNotification, REMOVED);
73 AffectedVirtualLink modifiedLink = buildVl(recievenNotification, MODIFIED);
74 AffectedVnfc addedVnfc = buildVnfc(recievenNotification, ADDED, "tenantId1");
75 AffectedVnfc removedVnfc = buildVnfc(recievenNotification, REMOVED, "tenantId2");
76 AffectedVnfc modifedVnfc = buildVnfc(recievenNotification, MODIFIED, "tenantId3");
77 boolean inMaintenance = true;
78 ReportedAffectedConnectionPoints affectedConnectionPoints = new ReportedAffectedConnectionPoints();
80 ReportedAffectedCp removedCp = buildCp();
81 removedCp.setServerProviderId("serverId");
82 affectedConnectionPoints.getPre().add(removedCp);
84 ReportedAffectedCp removedCpWithoutServer = buildCp();
85 removedCpWithoutServer.setServerProviderId(null);
86 affectedConnectionPoints.getPre().add(removedCpWithoutServer);
88 ReportedAffectedCp addedCp = buildCp();
89 addedCp.setServerProviderId("serverId");
90 affectedConnectionPoints.getPost().add(addedCp);
92 aaiNotificationProcessor.processNotification(recievenNotification, null, of(affectedConnectionPoints), VIM_ID);
94 InOrder inOrder = Mockito.inOrder(genericVnfManager, l3NetworkManager, lInterfaceManager, vnfcManager, vserverManager);
95 inOrder.verify(l3NetworkManager).update(VIM_ID, VNF_ID, addedLink);
96 inOrder.verify(l3NetworkManager).update(VIM_ID, VNF_ID, modifiedLink);
97 inOrder.verify(vserverManager).update(VIM_ID, VNF_ID, addedVnfc, affectedVirtualStorages, inMaintenance);
98 inOrder.verify(vnfcManager).update(VIM_ID, "tenantId1", VNF_ID, addedVnfc, inMaintenance);
99 inOrder.verify(vserverManager).update(VIM_ID, VNF_ID, modifedVnfc, affectedVirtualStorages, inMaintenance);
100 inOrder.verify(vnfcManager).update(VIM_ID, "tenantId3", VNF_ID, modifedVnfc, inMaintenance);
101 inOrder.verify(lInterfaceManager).delete(VIM_ID, removedCp);
102 inOrder.verify(lInterfaceManager).update(VNF_ID, VIM_ID, addedCp, inMaintenance);
103 inOrder.verify(vnfcManager).delete(VNF_ID, removedVnfc);
104 inOrder.verify(vserverManager).delete(VIM_ID, removedVnfc);
105 inOrder.verify(l3NetworkManager).delete(VNF_ID, removedLink);
106 verify(lInterfaceManager, never()).update(VNF_ID, VIM_ID, removedCpWithoutServer, inMaintenance);
107 verify(lInterfaceManager, never()).delete(VIM_ID, removedCpWithoutServer);
111 * - unchanged CP is updated
112 * - changed CP is updated
115 public void testCps() throws Exception {
116 VnfLifecycleChangeNotification recievenNotification = new VnfLifecycleChangeNotification();
117 recievenNotification.setAffectedVnfcs(new ArrayList<>());
118 recievenNotification.setAffectedVirtualLinks(new ArrayList<>());
119 recievenNotification.setVnfInstanceId(VNF_ID);
120 recievenNotification.setStatus(OperationStatus.STARTED);
121 ArrayList<AffectedVirtualStorage> affectedVirtualStorages = new ArrayList<>();
122 recievenNotification.setAffectedVirtualStorages(affectedVirtualStorages);
123 boolean inMaintenance = true;
124 ReportedAffectedConnectionPoints affectedConnectionPoints = new ReportedAffectedConnectionPoints();
126 ReportedAffectedCp unchangedCp = buildCp();
127 unchangedCp.setCpId("unchanged");
128 affectedConnectionPoints.getPre().add(unchangedCp);
129 affectedConnectionPoints.getPost().add(unchangedCp);
131 ReportedAffectedCp changedCpBefore = buildCp();
132 changedCpBefore.setCpId("changedBefore");
133 ReportedAffectedCp changedCpAfter = buildCp();
134 changedCpAfter.setCpId("changedAfter");
135 changedCpAfter.setCpId(changedCpBefore.getCpId());
136 affectedConnectionPoints.getPre().add(changedCpBefore);
137 affectedConnectionPoints.getPost().add(changedCpAfter);
140 aaiNotificationProcessor.processNotification(recievenNotification, null, of(affectedConnectionPoints), VIM_ID);
142 verify(lInterfaceManager).update(VNF_ID, VIM_ID, unchangedCp, inMaintenance);
143 verify(lInterfaceManager, never()).update(VNF_ID, VIM_ID, changedCpBefore, inMaintenance);
144 verify(lInterfaceManager).update(VNF_ID, VIM_ID, changedCpAfter, inMaintenance);
148 * the end notification calls resource managers with not in maintenance state
151 public void testEndNotification() throws Exception {
152 VnfLifecycleChangeNotification recievenNotification = new VnfLifecycleChangeNotification();
153 recievenNotification.setAffectedVnfcs(new ArrayList<>());
154 recievenNotification.setAffectedVirtualLinks(new ArrayList<>());
155 ArrayList<AffectedVirtualStorage> affectedVirtualStorages = new ArrayList<>();
156 recievenNotification.setAffectedVirtualStorages(affectedVirtualStorages);
157 recievenNotification.setVnfInstanceId(VNF_ID);
158 recievenNotification.setStatus(OperationStatus.FINISHED);
159 AffectedVirtualLink addedLink = buildVl(recievenNotification, ADDED);
160 AffectedVirtualLink removedLink = buildVl(recievenNotification, REMOVED);
161 AffectedVirtualLink modifiedLink = buildVl(recievenNotification, MODIFIED);
162 AffectedVnfc addedVnfc = buildVnfc(recievenNotification, ADDED, "tenantId1");
163 AffectedVnfc removedVnfc = buildVnfc(recievenNotification, REMOVED, "tenantId2");
164 AffectedVnfc modifedVnfc = buildVnfc(recievenNotification, MODIFIED, "tenantId3");
165 boolean inMaintenance = false;
166 ReportedAffectedConnectionPoints affectedConnectionPoints = new ReportedAffectedConnectionPoints();
168 ReportedAffectedCp removedCp = buildCp();
169 removedCp.setServerProviderId("serverId");
170 affectedConnectionPoints.getPre().add(removedCp);
172 ReportedAffectedCp removedCpWithoutServer = buildCp();
173 removedCpWithoutServer.setServerProviderId(null);
174 affectedConnectionPoints.getPre().add(removedCpWithoutServer);
176 ReportedAffectedCp addedCp = buildCp();
177 addedCp.setServerProviderId("serverId");
178 affectedConnectionPoints.getPost().add(addedCp);
180 ReportedAffectedCp cpWithoutServer = buildCp();
181 cpWithoutServer.setServerProviderId(null);
182 affectedConnectionPoints.getPost().add(cpWithoutServer);
185 aaiNotificationProcessor.processNotification(recievenNotification, null, of(affectedConnectionPoints), VIM_ID);
187 InOrder inOrder = Mockito.inOrder(genericVnfManager, l3NetworkManager, lInterfaceManager, vnfcManager, vserverManager);
188 inOrder.verify(l3NetworkManager).update(VIM_ID, VNF_ID, addedLink);
189 inOrder.verify(l3NetworkManager).update(VIM_ID, VNF_ID, modifiedLink);
190 inOrder.verify(vserverManager).update(VIM_ID, VNF_ID, addedVnfc, affectedVirtualStorages, inMaintenance);
191 inOrder.verify(vnfcManager).update(VIM_ID, "tenantId1", VNF_ID, addedVnfc, inMaintenance);
192 inOrder.verify(vserverManager).update(VIM_ID, VNF_ID, modifedVnfc, affectedVirtualStorages, inMaintenance);
193 inOrder.verify(vnfcManager).update(VIM_ID, "tenantId3", VNF_ID, modifedVnfc, inMaintenance);
194 inOrder.verify(lInterfaceManager).delete(VIM_ID, removedCp);
195 inOrder.verify(lInterfaceManager).update(VNF_ID, VIM_ID, addedCp, inMaintenance);
196 inOrder.verify(vnfcManager).delete(VNF_ID, removedVnfc);
197 inOrder.verify(vserverManager).delete(VIM_ID, removedVnfc);
198 inOrder.verify(l3NetworkManager).delete(VNF_ID, removedLink);
199 verify(lInterfaceManager, never()).update(VNF_ID, VIM_ID, removedCpWithoutServer, inMaintenance);
200 verify(lInterfaceManager, never()).delete(VIM_ID, removedCpWithoutServer);
201 verify(logger).warn("The changed {} connection point is not linked to any server", cpWithoutServer.getCpId());
206 * if changes connection points are not present a warning is logged
209 public void testMissingChangedConnectionPoints() throws Exception {
210 VnfLifecycleChangeNotification recievenNotification = new VnfLifecycleChangeNotification();
211 recievenNotification.setAffectedVnfcs(new ArrayList<>());
212 recievenNotification.setAffectedVirtualLinks(new ArrayList<>());
213 recievenNotification.setVnfInstanceId(VNF_ID);
215 aaiNotificationProcessor.processNotification(recievenNotification, null, empty(), VIM_ID);
217 verify(logger).warn("The changed connection points are not present in VNF with {} identifier", VNF_ID);
220 private ReportedAffectedCp buildCp() {
221 ReportedAffectedCp cp = new ReportedAffectedCp();
222 cp.setServerProviderId(UUID.randomUUID().toString());
223 cp.setName(UUID.randomUUID().toString());
224 cp.setEcpdId(UUID.randomUUID().toString());
225 cp.setMacAddress(UUID.randomUUID().toString());
226 cp.setNetworkProviderId(UUID.randomUUID().toString());
227 cp.setCpdId(UUID.randomUUID().toString());
228 cp.setCpId(UUID.randomUUID().toString());
229 cp.setTenantId(UUID.randomUUID().toString());
233 private AffectedVirtualLink buildVl(VnfLifecycleChangeNotification recievenNotification, ChangeType changeType) {
234 AffectedVirtualLink affectedVirtualLink = new AffectedVirtualLink();
235 affectedVirtualLink.setChangeType(changeType);
236 recievenNotification.getAffectedVirtualLinks().add(affectedVirtualLink);
237 return affectedVirtualLink;
240 private AffectedVnfc buildVnfc(VnfLifecycleChangeNotification recievenNotification, ChangeType changeType, String tenantId) {
241 AffectedVnfc addedVnfc = new AffectedVnfc();
242 addedVnfc.setChangeType(changeType);
243 JsonObject additionalData = new JsonObject();
244 additionalData.addProperty("tenantId", tenantId);
245 addedVnfc.setComputeResource(new ResourceHandle());
246 addedVnfc.getComputeResource().setAdditionalData(additionalData);
247 recievenNotification.getAffectedVnfcs().add(addedVnfc);