2 * Copyright © 2018 Orange Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.transportpce.renderer.provisiondevice;
12 import static org.junit.jupiter.api.Assertions.assertEquals;
13 import static org.mockito.ArgumentMatchers.any;
14 import static org.mockito.ArgumentMatchers.anyString;
15 import static org.mockito.ArgumentMatchers.eq;
16 import static org.mockito.Mockito.doReturn;
17 import static org.mockito.Mockito.times;
18 import static org.mockito.Mockito.verify;
19 import static org.mockito.Mockito.when;
21 import com.google.common.util.concurrent.ListenableFuture;
23 import java.util.concurrent.ExecutionException;
24 import java.util.concurrent.TimeoutException;
25 import org.junit.jupiter.api.BeforeEach;
26 import org.junit.jupiter.api.Test;
27 import org.junit.jupiter.api.extension.ExtendWith;
28 import org.mockito.Mock;
29 import org.mockito.junit.jupiter.MockitoExtension;
30 import org.opendaylight.mdsal.binding.api.DataBroker;
31 import org.opendaylight.mdsal.binding.api.MountPoint;
32 import org.opendaylight.mdsal.binding.api.MountPointService;
33 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
34 import org.opendaylight.mdsal.binding.api.RpcService;
35 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
36 import org.opendaylight.transportpce.common.ResponseCodes;
37 import org.opendaylight.transportpce.common.StringConstants;
38 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
39 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
40 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
41 import org.opendaylight.transportpce.common.mapping.PortMapping;
42 import org.opendaylight.transportpce.renderer.provisiondevice.notification.NotificationSender;
43 import org.opendaylight.transportpce.renderer.utils.NotificationPublishServiceMock;
44 import org.opendaylight.transportpce.renderer.utils.ServiceDeleteDataUtils;
45 import org.opendaylight.transportpce.renderer.utils.TransactionUtils;
46 import org.opendaylight.transportpce.test.AbstractTest;
47 import org.opendaylight.transportpce.test.stub.MountPointServiceStub;
48 import org.opendaylight.transportpce.test.stub.MountPointStub;
49 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.device.renderer.rev211004.ServicePathOutputBuilder;
50 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndown;
51 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutputBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInputBuilder;
53 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutput;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.node.types.rev210528.NodeIdType;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ConnectionType;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.ServiceAEnd;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.ServiceAEndBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.endpoint.TxDirectionBuilder;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.endpoint.TxDirectionKey;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.service.port.PortBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.format.rev191129.ServiceFormat;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.Services;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.service.list.ServicesBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev220118.service.handler.header.ServiceHandlerHeaderBuilder;
65 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.ServicePathList;
66 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePaths;
67 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsBuilder;
68 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev171017.service.path.list.ServicePathsKey;
69 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
70 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
71 import org.opendaylight.yangtools.yang.common.Uint32;
72 import org.opendaylight.yangtools.yang.common.Uint8;
74 @ExtendWith(MockitoExtension.class)
75 public class RendererServiceOperationsImplDeleteTest extends AbstractTest {
77 private DeviceTransactionManager deviceTransactionManager;
79 private DeviceRendererService deviceRenderer;
81 private OtnDeviceRendererService otnDeviceRendererService;
82 private DataBroker dataBroker;
84 private PortMapping portMapping;
86 private RpcService rpcService;
88 private CrossConnect crossConnect;
90 private ServicePowerTurndown servicePowerTurndown;
91 private RendererServiceOperationsImpl rendererServiceOperations;
93 private void setMountPoint(MountPoint mountPoint) {
94 MountPointService mountPointService = new MountPointServiceStub(mountPoint);
95 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
100 dataBroker = getNewDataBroker();
101 setMountPoint(new MountPointStub(dataBroker));
102 NotificationPublishService notificationPublishService = new NotificationPublishServiceMock();
103 this.rendererServiceOperations = new RendererServiceOperationsImpl(deviceRenderer,
104 otnDeviceRendererService, dataBroker, new NotificationSender(notificationPublishService), portMapping,
110 void serviceDeleteOperationPp() throws ExecutionException, InterruptedException, TimeoutException {
111 writePathDescription();
112 ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
113 serviceDeleteInputBuilder.setServiceName("service 1");
114 serviceDeleteInputBuilder.setServiceHandlerHeader((new ServiceHandlerHeaderBuilder())
115 .setRequestId("request1").build());
116 ServiceAEnd serviceAEnd = new ServiceAEndBuilder()
117 .setServiceFormat(ServiceFormat.Ethernet)
118 .setServiceRate(Uint32.valueOf("100"))
119 .setTxDirection(Map.of(new TxDirectionKey(Uint8.ZERO),
120 new TxDirectionBuilder().setIndex(Uint8.ZERO).setPort(new PortBuilder().setPortName("port-name")
122 .setNodeId(new NodeIdType("optical-node1"))
124 Services service = new ServicesBuilder()
125 .setServiceName("service 1")
126 .setConnectionType(ConnectionType.Service)
127 .setServiceAEnd(serviceAEnd)
129 when(portMapping.getMapping(anyString(), anyString())).thenReturn(null);
130 when(deviceRenderer.deleteServicePath(any()))
131 .thenReturn(new ServicePathOutputBuilder().setSuccess(true).build());
132 when(rpcService.getRpc(ServicePowerTurndown.class)).thenReturn(servicePowerTurndown);
133 doReturn(RpcResultBuilder
134 .success(new ServicePowerTurndownOutputBuilder().setResult(ResponseCodes.SUCCESS_RESULT).build())
136 .when(servicePowerTurndown).invoke(any());
137 ServiceDeleteOutput serviceDeleteOutput = this.rendererServiceOperations
138 .serviceDelete(serviceDeleteInputBuilder.build(), service).get();
139 assertEquals(ResponseCodes.RESPONSE_OK, serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
143 void serviceDeleteOperationWithoutPathDescription() throws InterruptedException, ExecutionException {
144 ServiceDeleteInputBuilder serviceDeleteInputBuilder = new ServiceDeleteInputBuilder();
145 serviceDeleteInputBuilder.setServiceName("service 1");
146 Services service = new ServicesBuilder()
147 .setServiceName("service 1")
148 .setServiceAEnd(new ServiceAEndBuilder()
149 .setServiceFormat(ServiceFormat.Ethernet)
150 .setServiceRate(Uint32.valueOf(100))
151 .setTxDirection(Map.of(
152 new TxDirectionKey(Uint8.ZERO),
153 new TxDirectionBuilder().setIndex(Uint8.ZERO).setPort(new PortBuilder()
154 .setPortName("port-name").build()).build()))
155 .setNodeId(new NodeIdType("optical-node1"))
158 ServiceDeleteOutput serviceDeleteOutput
159 = this.rendererServiceOperations.serviceDelete(serviceDeleteInputBuilder.build(), service).get();
161 ResponseCodes.RESPONSE_FAILED,
162 serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
163 verify(this.crossConnect, times(0)).deleteCrossConnect(any(), any(), eq(false));
167 void serviceDeleteOperationTearDownFailedAtoZ() throws ExecutionException, InterruptedException {
168 writePathDescription();
169 Services service = new ServicesBuilder()
170 .setServiceName("service 1")
171 .setConnectionType(ConnectionType.Service)
172 .setServiceAEnd(new ServiceAEndBuilder()
173 .setServiceFormat(ServiceFormat.Ethernet)
174 .setServiceRate(Uint32.valueOf("100"))
175 .setTxDirection(Map.of(
176 new TxDirectionKey(Uint8.ZERO),
177 new TxDirectionBuilder()
178 .setIndex(Uint8.ZERO)
179 .setPort(new PortBuilder().setPortName("port-name").build())
181 .setNodeId(new NodeIdType("optical-node1"))
184 when(portMapping.getMapping(anyString(), anyString()))
186 when(rpcService.getRpc(ServicePowerTurndown.class)).thenReturn(servicePowerTurndown);
187 doReturn(RpcResultBuilder
188 .success(new ServicePowerTurndownOutputBuilder().setResult(ResponseCodes.FAILED_RESULT).build())
190 .when(servicePowerTurndown).invoke(any());
192 ListenableFuture<ServiceDeleteOutput> serviceDeleteOutput = this.rendererServiceOperations
194 new ServiceDeleteInputBuilder()
195 .setServiceName("service 1")
196 .setServiceHandlerHeader((new ServiceHandlerHeaderBuilder()).setRequestId("request1").build())
199 ServiceDeleteOutput output = serviceDeleteOutput.get();
200 assertEquals(ResponseCodes.RESPONSE_FAILED,
201 output.getConfigurationResponseCommon().getResponseCode());
202 verify(this.crossConnect, times(0)).deleteCrossConnect(eq("node1"), any(), eq(false));
203 verify(this.crossConnect, times(0)).deleteCrossConnect(eq("node2"), any(), eq(false));
207 void serviceDeleteOperationTearDownFailedZtoA() throws ExecutionException, InterruptedException {
208 writePathDescription();
209 when(rpcService.getRpc(ServicePowerTurndown.class)).thenReturn(servicePowerTurndown);
210 when(servicePowerTurndown.invoke(any()))
211 .thenReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder()).setResult("Success").build())
213 .thenReturn(RpcResultBuilder.success((new ServicePowerTurndownOutputBuilder()).setResult("Failed").build())
215 when(portMapping.getMapping(anyString(), anyString()))
217 ServiceDeleteOutput serviceDeleteOutput = this.rendererServiceOperations.serviceDelete(
218 new ServiceDeleteInputBuilder()
219 .setServiceName("service 1")
220 .setServiceHandlerHeader((new ServiceHandlerHeaderBuilder()).setRequestId("request1").build())
222 new ServicesBuilder()
223 .setServiceName("service 1")
224 .setConnectionType(ConnectionType.Service)
225 .setServiceAEnd(new ServiceAEndBuilder()
226 .setServiceFormat(ServiceFormat.Ethernet)
227 .setServiceRate(Uint32.valueOf("100"))
228 .setTxDirection(Map.of(
229 new TxDirectionKey(Uint8.ZERO),
230 new TxDirectionBuilder()
231 .setIndex(Uint8.ZERO)
232 .setPort(new PortBuilder().setPortName("port-name").build())
234 .setNodeId(new NodeIdType("optical-node1"))
238 assertEquals(ResponseCodes.RESPONSE_FAILED,
239 serviceDeleteOutput.getConfigurationResponseCommon().getResponseCode());
240 verify(servicePowerTurndown, times(2)).invoke(any());
241 verify(this.crossConnect, times(0)).deleteCrossConnect(eq("node1"), any(),eq(false));
242 verify(this.crossConnect, times(0)).deleteCrossConnect(eq("node2"), any(),eq(false));
245 private void writePathDescription() throws ExecutionException, InterruptedException {
246 TransactionUtils.writeTransaction(
247 this.deviceTransactionManager,
248 "node1" + StringConstants.PP_TOKEN,
249 LogicalDatastoreType.OPERATIONAL,
250 InstanceIdentifier.create(ServicePathList.class)
251 .child(ServicePaths.class, new ServicePathsKey("service 1")),
252 new ServicePathsBuilder()
253 .setPathDescription(ServiceDeleteDataUtils
254 .createTransactionPathDescription(StringConstants.PP_TOKEN))
255 .setServiceAEnd(ServiceDeleteDataUtils.getServiceAEndBuild().build())
256 .setServiceZEnd(ServiceDeleteDataUtils.getServiceZEndBuild().build())
257 .withKey(new ServicePathsKey("service 1"))
258 .setServiceHandlerHeader(new ServiceHandlerHeaderBuilder().setRequestId("Request 1").build())