Search in sources :

Example 81 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class NetconfDeviceCommunicatorTest method createMultiErrorResponseMessage.

private static NetconfMessage createMultiErrorResponseMessage(final String messageID) throws Exception {
    // multiple rpc-errors which simulate actual response like in NETCONF-666
    String xmlStr = "<nc:rpc-reply xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\" xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" xmlns:junos=\"http://xml.juniper.net/junos/18.4R1/junos\"" + "           message-id=\"" + messageID + "\">" + "<nc:rpc-error>\n" + "<nc:error-type>protocol</nc:error-type>\n" + "<nc:error-tag>operation-failed</nc:error-tag>\n" + "<nc:error-severity>error</nc:error-severity>\n" + "<source-daemon>\n" + "dcd\n" + "</source-daemon>\n" + "<nc:error-message>\n" + "Number of member links configured, i.e [1], " + "for interface [ae0]is lesser than the required minimum [2].\n" + "</nc:error-message>\n" + "</nc:rpc-error>\n" + "<nc:rpc-error>\n" + "<nc:error-type>protocol</nc:error-type>\n" + "<nc:error-tag>operation-failed</nc:error-tag>\n" + "<nc:error-severity>error</nc:error-severity>\n" + "<nc:error-message>\n" + "configuration check-out failed\n" + "</nc:error-message>\n" + "</nc:rpc-error>\n" + "</nc:rpc-reply>";
    ByteArrayInputStream bis = new ByteArrayInputStream(xmlStr.getBytes());
    Document doc = UntrustedXML.newDocumentBuilder().parse(bis);
    return new NetconfMessage(doc);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) Document(org.w3c.dom.Document)

Example 82 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class NetconfDeviceCommunicatorTest method testSendRequestWithWithSendFailure.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testSendRequestWithWithSendFailure() throws Exception {
    setupSession();
    NetconfMessage message = new NetconfMessage(UntrustedXML.newDocumentBuilder().newDocument());
    QName rpc = QName.create("", "mockRpc");
    ArgumentCaptor<GenericFutureListener> futureListener = ArgumentCaptor.forClass(GenericFutureListener.class);
    ChannelFuture mockChannelFuture = mock(ChannelFuture.class);
    doReturn(mockChannelFuture).when(mockChannelFuture).addListener(futureListener.capture());
    doReturn(mockChannelFuture).when(mockSession).sendMessage(same(message));
    ListenableFuture<RpcResult<NetconfMessage>> resultFuture = communicator.sendRequest(message, rpc);
    assertNotNull("ListenableFuture is null", resultFuture);
    verify(mockChannelFuture).addListener(futureListener.capture());
    Future<Void> operationFuture = mock(Future.class);
    doReturn(false).when(operationFuture).isSuccess();
    doReturn(new Exception("mock error")).when(operationFuture).cause();
    futureListener.getValue().operationComplete(operationFuture);
    // Should have an immediate result
    RpcResult<NetconfMessage> rpcResult = resultFuture.get(3, TimeUnit.MILLISECONDS);
    RpcError rpcError = verifyErrorRpcResult(rpcResult, RpcError.ErrorType.TRANSPORT, "operation-failed");
    assertEquals("RpcError message contains \"mock error\"", true, rpcError.getMessage().contains("mock error"));
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) QName(org.opendaylight.yangtools.yang.common.QName) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) RpcError(org.opendaylight.yangtools.yang.common.RpcError) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) TimeoutException(java.util.concurrent.TimeoutException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Test(org.junit.Test)

Example 83 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class NetconfDeviceRpcTest method setUp.

@Before
public void setUp() throws Exception {
    NetconfMessageTransformer transformer = new NetconfMessageTransformer(new EmptyMountPointContext(SCHEMA_CONTEXT), true, BASE_SCHEMAS.getBaseSchema());
    final NetconfMessage reply = new NetconfMessage(XmlUtil.readXmlToDocument("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"101\">\n" + "<data>\n" + "</data>\n" + "</rpc-reply>"));
    RpcResult<NetconfMessage> result = RpcResultBuilder.success(reply).build();
    doReturn(Futures.immediateFuture(result)).when(communicator).sendRequest(any(NetconfMessage.class), any(QName.class));
    rpc = new NetconfDeviceRpc(SCHEMA_CONTEXT, communicator, transformer);
    type = QName.create("urn:ietf:params:xml:ns:netconf:base:1.0", "2011-06-01", "get-config");
    expectedReply = transformer.toRpcResult(reply, type);
}
Also used : EmptyMountPointContext(org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) QName(org.opendaylight.yangtools.yang.common.QName) NetconfMessageTransformer(org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer) Before(org.junit.Before)

Example 84 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class NetconfDeviceRpcTest method testDeadlock.

@Test
public void testDeadlock() throws Exception {
    // when rpc is successful, but transformer fails for some reason
    final MessageTransformer<NetconfMessage> failingTransformer = mock(MessageTransformer.class);
    final RemoteDeviceCommunicator<NetconfMessage> communicatorMock = mock(RemoteDeviceCommunicator.class);
    final NetconfMessage msg = null;
    final RpcResult<NetconfMessage> result = RpcResultBuilder.success(msg).build();
    when(communicatorMock.sendRequest(any(), any())).thenReturn(Futures.immediateFuture(result));
    when(failingTransformer.toRpcResult(any(), any())).thenThrow(new RuntimeException("FAIL"));
    final NetconfDeviceRpc failingRpc = new NetconfDeviceRpc(SCHEMA_CONTEXT, communicatorMock, failingTransformer);
    assertThrows(ExecutionException.class, () -> failingRpc.invokeRpc(type, mock(ContainerNode.class)).get());
    assertThrows(ExecutionException.class, () -> failingRpc.invokeRpc(type, null).get());
}
Also used : NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) AbstractBaseSchemasTest(org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest) Test(org.junit.Test)

Example 85 with NetconfMessage

use of org.opendaylight.netconf.api.NetconfMessage in project netconf by opendaylight.

the class NetconfDeviceCommunicatorTest method sendRequest.

@SuppressWarnings("unchecked")
private ListenableFuture<RpcResult<NetconfMessage>> sendRequest(final String messageID, final boolean doLastTest) throws Exception {
    Document doc = UntrustedXML.newDocumentBuilder().newDocument();
    Element element = doc.createElement("request");
    element.setAttribute("message-id", messageID);
    doc.appendChild(element);
    NetconfMessage message = new NetconfMessage(doc);
    ChannelFuture mockChannelFuture = mock(ChannelFuture.class);
    doReturn(mockChannelFuture).when(mockChannelFuture).addListener(any(GenericFutureListener.class));
    doReturn(mockChannelFuture).when(mockSession).sendMessage(same(message));
    ListenableFuture<RpcResult<NetconfMessage>> resultFuture = communicator.sendRequest(message, QName.create("", "mockRpc"));
    if (doLastTest) {
        assertNotNull("ListenableFuture is null", resultFuture);
    }
    return resultFuture;
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) Element(org.w3c.dom.Element) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) Document(org.w3c.dom.Document) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener)

Aggregations

NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)125 Test (org.junit.Test)72 AbstractBaseSchemasTest (org.opendaylight.netconf.sal.connect.netconf.AbstractBaseSchemasTest)40 Document (org.w3c.dom.Document)28 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)23 QName (org.opendaylight.yangtools.yang.common.QName)17 DOMSourceAnyxmlNode (org.opendaylight.yangtools.yang.data.api.schema.DOMSourceAnyxmlNode)15 Test (org.junit.jupiter.api.Test)13 SimpleNetconfClientSessionListener (org.opendaylight.netconf.client.SimpleNetconfClientSessionListener)13 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)13 Node (org.w3c.dom.Node)13 NetconfClientSession (org.opendaylight.netconf.client.NetconfClientSession)12 ArrayList (java.util.ArrayList)11 Element (org.w3c.dom.Element)11 DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)10 UnkeyedListNode (org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode)10 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)9 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)9 ChannelFuture (io.netty.channel.ChannelFuture)8 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)8