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);
}
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"));
}
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);
}
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());
}
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;
}
Aggregations