Fix non ietf-netconf* mounted RPC invocation from Restconf 95/31495/2
authorMaros Marsalek <mmarsale@cisco.com>
Thu, 17 Dec 2015 11:21:42 +0000 (12:21 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 21 Jan 2016 13:49:20 +0000 (13:49 +0000)
Invoked RPCs from modules other than iet-netconf* were executed on ODL itself
instead of a mountpoint regardless of whether they were aimed at a mountpoint
or not.

Change-Id: I8ac4fea41e553680f270825376b57a534b2ffa95
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/RestconfImpl.java
opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java

index bd09fababa90bf7540c6016e970b44408acae7d5..98b75e7f06c3c9196c4f3b4e1594e42875ebecc0 100644 (file)
@@ -109,8 +109,6 @@ public class RestconfImpl implements RestconfService {
 
     private static final int CHAR_NOT_FOUND = -1;
 
-    private static final String MOUNT_POINT_MODULE_NAME = "ietf-netconf";
-
     private static final String SAL_REMOTE_NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:remote";
 
     private static final String SAL_REMOTE_RPC_SUBSRCIBE = "create-data-change-event-subscription";
@@ -435,7 +433,7 @@ public class RestconfImpl implements RestconfService {
         final CheckedFuture<DOMRpcResult, DOMRpcException> response;
         final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
         final SchemaContext schemaContext;
-        if (identifier.contains(MOUNT_POINT_MODULE_NAME) && mountPoint != null) {
+        if (mountPoint != null) {
             final Optional<DOMRpcService> mountRpcServices = mountPoint.getService(DOMRpcService.class);
             if ( ! mountRpcServices.isPresent()) {
                 LOG.debug("Error: Rpc service is missing.");
index fa878b68e51d3bc939d949af3df9d8f1687f3e92..c60ba01a5a2d04fef15feba09acb6f3142c5b46d 100644 (file)
@@ -10,23 +10,40 @@ package org.opendaylight.controller.sal.restconf.impl.test;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.Futures;
 import java.io.FileNotFoundException;
 import java.text.ParseException;
 import java.util.Set;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.UriInfo;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
 import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
+import org.opendaylight.controller.sal.restconf.impl.InstanceIdentifierContext;
+import org.opendaylight.controller.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.controller.sal.restconf.impl.RestconfImpl;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 
 /**
  * @See {@link InvokeRpcMethodTest}
@@ -65,4 +82,26 @@ public class RestconfImplTest {
                 brokerFacade.readOperationalData(null));
     }
 
+    @Test
+    public void testRpcForMountpoint() throws Exception {
+        final UriInfo uriInfo = mock(UriInfo.class);
+        doReturn(new MultivaluedHashMap<>()).when(uriInfo).getQueryParameters(anyBoolean());
+
+        final NormalizedNodeContext ctx = mock(NormalizedNodeContext.class);
+        final InstanceIdentifierContext iiCtx = mock(InstanceIdentifierContext.class);
+        doReturn(iiCtx).when(ctx).getInstanceIdentifierContext();
+        final SchemaNode schemaNode = mock(RpcDefinition.class);
+        doReturn(schemaNode).when(iiCtx).getSchemaNode();
+        doReturn(mock(SchemaPath.class)).when(schemaNode).getPath();
+        doReturn(QName.create("namespace", "2010-10-10", "localname")).when(schemaNode).getQName();
+
+        final DOMMountPoint mount = mock(DOMMountPoint.class);
+        doReturn(mount).when(iiCtx).getMountPoint();
+        final DOMRpcService rpcService = mock(DOMRpcService.class);
+        doReturn(Optional.of(rpcService)).when(mount).getService(DOMRpcService.class);
+        doReturn(Futures.immediateCheckedFuture(mock(DOMRpcResult.class))).when(rpcService).invokeRpc(any(SchemaPath.class), any(NormalizedNode.class));
+        restconfImpl.invokeRpc("randomId", ctx, uriInfo);
+        restconfImpl.invokeRpc("ietf-netconf", ctx, uriInfo);
+        verify(rpcService, times(2)).invokeRpc(any(SchemaPath.class), any(NormalizedNode.class));
+    }
 }