From: Maros Marsalek Date: Wed, 16 Dec 2015 13:28:54 +0000 (+0100) Subject: Fix non ietf-netconf* mounted RPC invocation from Restconf X-Git-Tag: release/beryllium~51^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=affadf797a5cf88cb5727292bca4b3bb1878d4f8;p=netconf.git Fix non ietf-netconf* mounted RPC invocation from Restconf 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: I2586ad77ec17c7542ba3ffd931684fb6f7c12685 Signed-off-by: Maros Marsalek --- diff --git a/opendaylight/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java b/opendaylight/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java index 6d19dfc923..18b02cfa34 100644 --- a/opendaylight/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java +++ b/opendaylight/restconf/sal-rest-connector/src/main/java/org/opendaylight/netconf/sal/restconf/impl/RestconfImpl.java @@ -108,8 +108,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 SimpleDateFormat REVISION_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); private static final String SAL_REMOTE_NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:remote"; @@ -434,7 +432,7 @@ public class RestconfImpl implements RestconfService { final CheckedFuture response; final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint(); final SchemaContext schemaContext; - if (identifier.contains(MOUNT_POINT_MODULE_NAME) && mountPoint != null) { + if (mountPoint != null) { final Optional mountRpcServices = mountPoint.getService(DOMRpcService.class); if ( ! mountRpcServices.isPresent()) { LOG.debug("Error: Rpc service is missing."); diff --git a/opendaylight/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java b/opendaylight/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java index ca5fbfeb35..72b5b3d9f7 100644 --- a/opendaylight/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java +++ b/opendaylight/restconf/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfImplTest.java @@ -10,23 +10,39 @@ 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.netconf.sal.restconf.impl.BrokerFacade; import org.opendaylight.netconf.sal.restconf.impl.ControllerContext; +import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext; +import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext; import org.opendaylight.netconf.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.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.SchemaNode; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; /** * @See {@link InvokeRpcMethodTest} @@ -65,4 +81,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(SchemaNode.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)); + } }