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.jetbrains.annotations.NotNull;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.mockito.InOrder;
24 import org.mockito.Mock;
25 import org.mockito.Mockito;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedConnectionPoints;
28 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.ReportedAffectedCp;
30 import java.util.ArrayList;
31 import java.util.UUID;
33 import static com.nokia.cbam.lcm.v32.model.ChangeType.*;
34 import static java.util.Optional.empty;
35 import static java.util.Optional.of;
36 import static org.mockito.Mockito.never;
37 import static org.mockito.Mockito.verify;
38 import static org.springframework.test.util.ReflectionTestUtils.setField;
40 public class TestAAINotificationProcessor extends TestBase {
42 private GenericVnfManager genericVnfManager;
44 private L3NetworkManager l3NetworkManager;
46 private LInterfaceManager lInterfaceManager;
48 private VnfcManager vnfcManager;
50 private VserverManager vserverManager;
51 private AAINotificationProcessor aaiNotificationProcessor;
55 aaiNotificationProcessor = new AAINotificationProcessor(genericVnfManager, l3NetworkManager, lInterfaceManager, vnfcManager, vserverManager);
56 setField(AAINotificationProcessor.class, "logger", logger);
60 * test objects are manipulated in correct order in AAA
61 * (other is dependency between the objects though relations)
64 public void testObjectManipulationOrder() throws Exception {
65 VnfLifecycleChangeNotification recievenNotification = new VnfLifecycleChangeNotification();
66 recievenNotification.setAffectedVnfcs(new ArrayList<>());
67 recievenNotification.setAffectedVirtualLinks(new ArrayList<>());
68 ArrayList<AffectedVirtualStorage> affectedVirtualStorages = new ArrayList<>();
69 recievenNotification.setAffectedVirtualStorages(affectedVirtualStorages);
70 recievenNotification.setVnfInstanceId(VNF_ID);
71 recievenNotification.setStatus(OperationStatus.STARTED);
72 AffectedVirtualLink addedLink = buildVl(recievenNotification, ADDED);
73 AffectedVirtualLink removedLink = buildVl(recievenNotification, REMOVED);
74 AffectedVirtualLink modifiedLink = buildVl(recievenNotification, MODIFIED);
75 AffectedVnfc addedVnfc = buildVnfc(recievenNotification, ADDED, "tenantId1");
76 AffectedVnfc removedVnfc = buildVnfc(recievenNotification, REMOVED, "tenantId2");
77 AffectedVnfc modifedVnfc = buildVnfc(recievenNotification, MODIFIED, "tenantId3");
78 boolean inMaintenance = true;
79 ReportedAffectedConnectionPoints affectedConnectionPoints = new ReportedAffectedConnectionPoints();
81 ReportedAffectedCp removedCp = buildCp();
82 removedCp.setServerProviderId("serverId");
83 affectedConnectionPoints.getPre().add(removedCp);
85 ReportedAffectedCp removedCpWithoutServer = buildCp();
86 removedCpWithoutServer.setServerProviderId(null);
87 affectedConnectionPoints.getPre().add(removedCpWithoutServer);
89 ReportedAffectedCp addedCp = buildCp();
90 addedCp.setServerProviderId("serverId");
91 affectedConnectionPoints.getPost().add(addedCp);
93 aaiNotificationProcessor.processNotification(recievenNotification, null, of(affectedConnectionPoints), VIM_ID);
95 InOrder inOrder = Mockito.inOrder(genericVnfManager, l3NetworkManager, lInterfaceManager, vnfcManager, vserverManager);
96 inOrder.verify(l3NetworkManager).update(VIM_ID, VNF_ID, addedLink);
97 inOrder.verify(l3NetworkManager).update(VIM_ID, VNF_ID, modifiedLink);
98 inOrder.verify(vserverManager).update(VIM_ID, VNF_ID, addedVnfc, affectedVirtualStorages, inMaintenance);
99 inOrder.verify(vnfcManager).update(VIM_ID, "tenantId1", VNF_ID, addedVnfc, inMaintenance);
100 inOrder.verify(vserverManager).update(VIM_ID, VNF_ID, modifedVnfc, affectedVirtualStorages, inMaintenance);
101 inOrder.verify(vnfcManager).update(VIM_ID, "tenantId3", VNF_ID, modifedVnfc, inMaintenance);
102 inOrder.verify(lInterfaceManager).delete(VIM_ID, removedCp);
103 inOrder.verify(lInterfaceManager).update(VNF_ID, VIM_ID, addedCp, inMaintenance);
104 inOrder.verify(vnfcManager).delete(VNF_ID, removedVnfc);
105 inOrder.verify(vserverManager).delete(VIM_ID, removedVnfc);
106 inOrder.verify(l3NetworkManager).delete(VNF_ID, removedLink);
107 verify(lInterfaceManager, never()).update(VNF_ID, VIM_ID, removedCpWithoutServer, inMaintenance);
108 verify(lInterfaceManager, never()).delete(VIM_ID, removedCpWithoutServer);
112 * - unchanged CP is updated
113 * - changed CP is updated
116 public void testCps() throws Exception {
117 VnfLifecycleChangeNotification recievenNotification = new VnfLifecycleChangeNotification();
118 recievenNotification.setAffectedVnfcs(new ArrayList<>());
119 recievenNotification.setAffectedVirtualLinks(new ArrayList<>());
120 recievenNotification.setVnfInstanceId(VNF_ID);
121 recievenNotification.setStatus(OperationStatus.STARTED);
122 ArrayList<AffectedVirtualStorage> affectedVirtualStorages = new ArrayList<>();
123 recievenNotification.setAffectedVirtualStorages(affectedVirtualStorages);
124 boolean inMaintenance = true;
125 ReportedAffectedConnectionPoints affectedConnectionPoints = new ReportedAffectedConnectionPoints();
127 ReportedAffectedCp unchangedCp = buildCp();
128 unchangedCp.setCpId("unchanged");
129 affectedConnectionPoints.getPre().add(unchangedCp);
130 affectedConnectionPoints.getPost().add(unchangedCp);
132 ReportedAffectedCp changedCpBefore = buildCp();
133 changedCpBefore.setCpId("changedBefore");
134 ReportedAffectedCp changedCpAfter = buildCp();
135 changedCpAfter.setCpId("changedAfter");
136 changedCpAfter.setCpId(changedCpBefore.getCpId());
137 affectedConnectionPoints.getPre().add(changedCpBefore);
138 affectedConnectionPoints.getPost().add(changedCpAfter);
141 aaiNotificationProcessor.processNotification(recievenNotification, null, of(affectedConnectionPoints), VIM_ID);
143 verify(lInterfaceManager).update(VNF_ID, VIM_ID, unchangedCp, inMaintenance);
144 verify(lInterfaceManager, never()).update(VNF_ID, VIM_ID, changedCpBefore, inMaintenance);
145 verify(lInterfaceManager).update(VNF_ID, VIM_ID, changedCpAfter, inMaintenance);
149 * the end notification calls resource managers with not in maintenance state
152 public void testEndNotification() throws Exception {
153 VnfLifecycleChangeNotification recievenNotification = new VnfLifecycleChangeNotification();
154 recievenNotification.setAffectedVnfcs(new ArrayList<>());
155 recievenNotification.setAffectedVirtualLinks(new ArrayList<>());
156 ArrayList<AffectedVirtualStorage> affectedVirtualStorages = new ArrayList<>();
157 recievenNotification.setAffectedVirtualStorages(affectedVirtualStorages);
158 recievenNotification.setVnfInstanceId(VNF_ID);
159 recievenNotification.setStatus(OperationStatus.FINISHED);
160 AffectedVirtualLink addedLink = buildVl(recievenNotification, ADDED);
161 AffectedVirtualLink removedLink = buildVl(recievenNotification, REMOVED);
162 AffectedVirtualLink modifiedLink = buildVl(recievenNotification, MODIFIED);
163 AffectedVnfc addedVnfc = buildVnfc(recievenNotification, ADDED, "tenantId1");
164 AffectedVnfc removedVnfc = buildVnfc(recievenNotification, REMOVED, "tenantId2");
165 AffectedVnfc modifedVnfc = buildVnfc(recievenNotification, MODIFIED, "tenantId3");
166 boolean inMaintenance = false;
167 ReportedAffectedConnectionPoints affectedConnectionPoints = new ReportedAffectedConnectionPoints();
169 ReportedAffectedCp removedCp = buildCp();
170 removedCp.setServerProviderId("serverId");
171 affectedConnectionPoints.getPre().add(removedCp);
173 ReportedAffectedCp removedCpWithoutServer = buildCp();
174 removedCpWithoutServer.setServerProviderId(null);
175 affectedConnectionPoints.getPre().add(removedCpWithoutServer);
177 ReportedAffectedCp addedCp = buildCp();
178 addedCp.setServerProviderId("serverId");
179 affectedConnectionPoints.getPost().add(addedCp);
181 ReportedAffectedCp cpWithoutServer = buildCp();
182 cpWithoutServer.setServerProviderId(null);
183 affectedConnectionPoints.getPost().add(cpWithoutServer);
186 aaiNotificationProcessor.processNotification(recievenNotification, null, of(affectedConnectionPoints), VIM_ID);
188 InOrder inOrder = Mockito.inOrder(genericVnfManager, l3NetworkManager, lInterfaceManager, vnfcManager, vserverManager);
189 inOrder.verify(l3NetworkManager).update(VIM_ID, VNF_ID, addedLink);
190 inOrder.verify(l3NetworkManager).update(VIM_ID, VNF_ID, modifiedLink);
191 inOrder.verify(vserverManager).update(VIM_ID, VNF_ID, addedVnfc, affectedVirtualStorages, inMaintenance);
192 inOrder.verify(vnfcManager).update(VIM_ID, "tenantId1", VNF_ID, addedVnfc, inMaintenance);
193 inOrder.verify(vserverManager).update(VIM_ID, VNF_ID, modifedVnfc, affectedVirtualStorages, inMaintenance);
194 inOrder.verify(vnfcManager).update(VIM_ID, "tenantId3", VNF_ID, modifedVnfc, inMaintenance);
195 inOrder.verify(lInterfaceManager).delete(VIM_ID, removedCp);
196 inOrder.verify(lInterfaceManager).update(VNF_ID, VIM_ID, addedCp, inMaintenance);
197 inOrder.verify(vnfcManager).delete(VNF_ID, removedVnfc);
198 inOrder.verify(vserverManager).delete(VIM_ID, removedVnfc);
199 inOrder.verify(l3NetworkManager).delete(VNF_ID, removedLink);
200 verify(lInterfaceManager, never()).update(VNF_ID, VIM_ID, removedCpWithoutServer, inMaintenance);
201 verify(lInterfaceManager, never()).delete(VIM_ID, removedCpWithoutServer);
202 verify(logger).warn("The changed {} connection point is not linked to any server", cpWithoutServer.getCpId());
208 * if changes connection points are not present a warning is logged
211 public void testMissingChangedConnectionPoints() throws Exception {
212 VnfLifecycleChangeNotification recievenNotification = new VnfLifecycleChangeNotification();
213 recievenNotification.setAffectedVnfcs(new ArrayList<>());
214 recievenNotification.setAffectedVirtualLinks(new ArrayList<>());
215 recievenNotification.setVnfInstanceId(VNF_ID);
217 aaiNotificationProcessor.processNotification(recievenNotification, null, empty(), VIM_ID);
219 verify(logger).warn("The changed connection points are not present in VNF with {} identifier", VNF_ID);
223 private ReportedAffectedCp buildCp() {
224 ReportedAffectedCp cp = new ReportedAffectedCp();
225 cp.setServerProviderId(UUID.randomUUID().toString());
226 cp.setName(UUID.randomUUID().toString());
227 cp.setEcpdId(UUID.randomUUID().toString());
228 cp.setMacAddress(UUID.randomUUID().toString());
229 cp.setNetworkProviderId(UUID.randomUUID().toString());
230 cp.setCpdId(UUID.randomUUID().toString());
231 cp.setCpId(UUID.randomUUID().toString());
232 cp.setTenantId(UUID.randomUUID().toString());
236 private AffectedVirtualLink buildVl(VnfLifecycleChangeNotification recievenNotification, ChangeType changeType) {
237 AffectedVirtualLink affectedVirtualLink = new AffectedVirtualLink();
238 affectedVirtualLink.setChangeType(changeType);
239 recievenNotification.getAffectedVirtualLinks().add(affectedVirtualLink);
240 return affectedVirtualLink;
243 private AffectedVnfc buildVnfc(VnfLifecycleChangeNotification recievenNotification, ChangeType changeType, String tenantId) {
244 AffectedVnfc addedVnfc = new AffectedVnfc();
245 addedVnfc.setChangeType(changeType);
246 JsonObject additionalData = new JsonObject();
247 additionalData.addProperty("tenantId", tenantId);
248 addedVnfc.setComputeResource(new ResourceHandle());
249 addedVnfc.getComputeResource().setAdditionalData(additionalData);
250 recievenNotification.getAffectedVnfcs().add(addedVnfc);