From 41241fe63d25544b532508b351dc36f14ab14d87 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 24 Jul 2018 18:43:12 +0200 Subject: [PATCH] Remove netconf-it This does not build and we are not using it. Remove it. Change-Id: I2827d1b430036d2c41f44827cba0b66b0ad3ba7b Signed-off-by: Robert Varga --- netconf/netconf-it/pom.xml | 116 ------ .../netconf/it/AbstractNetconfConfigTest.java | 312 ---------------- .../it/NetconfConfigPersisterITTest.java | 187 ---------- .../netconf/it/NetconfITMonitoringTest.java | 166 --------- .../netconf/it/NetconfITSecureTest.java | 220 ----------- .../netconf/it/NetconfITSecureTestTool.java | 192 ---------- .../netconf/it/NetconfITTest.java | 350 ------------------ .../src/test/resources/logback-test.xml | 16 - .../netconfMessages/editConfig_identities.xml | 37 -- 9 files changed, 1596 deletions(-) delete mode 100644 netconf/netconf-it/pom.xml delete mode 100644 netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/AbstractNetconfConfigTest.java delete mode 100644 netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfConfigPersisterITTest.java delete mode 100644 netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfITMonitoringTest.java delete mode 100644 netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfITSecureTest.java delete mode 100644 netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfITSecureTestTool.java delete mode 100644 netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfITTest.java delete mode 100644 netconf/netconf-it/src/test/resources/logback-test.xml delete mode 100644 netconf/netconf-it/src/test/resources/netconfMessages/editConfig_identities.xml diff --git a/netconf/netconf-it/pom.xml b/netconf/netconf-it/pom.xml deleted file mode 100644 index beeede463c..0000000000 --- a/netconf/netconf-it/pom.xml +++ /dev/null @@ -1,116 +0,0 @@ - - - 4.0.0 - - - org.opendaylight.netconf - netconf-subsystem - 1.5.0-SNAPSHOT - - - netconf-it - ${project.artifactId} - jar - - - - ${project.groupId} - netconf-netty-util - - - org.opendaylight.yangtools - mockito-configuration - - - org.slf4j - slf4j-api - - - xmlunit - xmlunit - - - - ${project.groupId} - sal-netconf-connector - test - - - ${project.groupId} - netconf-api - test - - - ${project.groupId} - netconf-client - test - - - ${project.groupId} - netconf-client - ${project.version} - test-jar - test - - - ${project.groupId} - netconf-impl - test - - - ${project.groupId} - netconf-impl - test-jar - test - - - ${project.groupId} - netconf-mapping-api - test - - - ${project.groupId} - netconf-monitoring - test - - - ${project.groupId} - netconf-netty-util - test-jar - test - - - ${project.groupId} - netconf-ssh - test - - - ${project.groupId} - netconf-testtool - ${project.version} - test - - - ${project.groupId} - netconf-ssh - test-jar - test - - - ${project.groupId} - netconf-util - test-jar - test - - - org.opendaylight.controller - netty-config-api - test - - - org.opendaylight.controller - yang-test - test - - - diff --git a/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/AbstractNetconfConfigTest.java b/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/AbstractNetconfConfigTest.java deleted file mode 100644 index cd1b9ce81e..0000000000 --- a/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/AbstractNetconfConfigTest.java +++ /dev/null @@ -1,312 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the terms of the Eclipse - * Public License v1.0 which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.netconf.it; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import com.google.common.base.Throwables; -import com.google.common.io.ByteStreams; -import com.google.common.util.concurrent.CheckedFuture; -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.local.LocalAddress; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.util.HashedWheelTimer; -import io.netty.util.concurrent.GlobalEventExecutor; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.TimeUnit; -import org.junit.After; -import org.junit.Before; -import org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacadeFactory; -import org.opendaylight.controller.config.facade.xml.osgi.EnumResolver; -import org.opendaylight.controller.config.facade.xml.osgi.YangStoreService; -import org.opendaylight.controller.config.manager.impl.AbstractConfigTest; -import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver; -import org.opendaylight.controller.config.spi.ModuleFactory; -import org.opendaylight.controller.config.yang.test.impl.DepTestImplModuleFactory; -import org.opendaylight.controller.config.yang.test.impl.IdentityTestModuleFactory; -import org.opendaylight.controller.config.yang.test.impl.MultipleDependenciesModuleFactory; -import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleFactory; -import org.opendaylight.controller.config.yang.test.impl.TestImplModuleFactory; -import org.opendaylight.netconf.api.NetconfMessage; -import org.opendaylight.netconf.api.monitoring.NetconfMonitoringService; -import org.opendaylight.netconf.client.NetconfClientDispatcherImpl; -import org.opendaylight.netconf.client.SimpleNetconfClientSessionListener; -import org.opendaylight.netconf.client.conf.NetconfClientConfiguration; -import org.opendaylight.netconf.client.conf.NetconfClientConfigurationBuilder; -import org.opendaylight.netconf.confignetconfconnector.osgi.NetconfOperationServiceFactoryImpl; -import org.opendaylight.netconf.impl.NetconfServerDispatcherImpl; -import org.opendaylight.netconf.impl.NetconfServerSessionNegotiatorFactory; -import org.opendaylight.netconf.impl.SessionIdProvider; -import org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory; -import org.opendaylight.netconf.impl.osgi.NetconfMonitoringServiceImpl; -import org.opendaylight.netconf.mapping.api.NetconfOperationServiceFactory; -import org.opendaylight.netconf.monitoring.osgi.NetconfMonitoringActivator; -import org.opendaylight.netconf.monitoring.osgi.NetconfMonitoringOperationService; -import org.opendaylight.netconf.util.test.XmlFileLoader; -import org.opendaylight.protocol.framework.NeverReconnectStrategy; -import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext; -import org.opendaylight.yangtools.yang.binding.BindingMapping; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider; -import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException; -import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; -import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource; -import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider; -import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; - -public abstract class AbstractNetconfConfigTest extends AbstractConfigTest { - - public static final String LOOPBACK_ADDRESS = "127.0.0.1"; - public static final int SERVER_CONNECTION_TIMEOUT_MILLIS = 5000; - private static final int RESOURCE_TIMEOUT_MINUTES = 2; - - static ModuleFactory[] FACTORIES = - {new TestImplModuleFactory(), new DepTestImplModuleFactory(), new NetconfTestImplModuleFactory(), - new IdentityTestModuleFactory(), new MultipleDependenciesModuleFactory()}; - - protected ConfigSubsystemFacadeFactory configSubsystemFacadeFactory; - private EventLoopGroup nettyThreadgroup; - private HashedWheelTimer hashedWheelTimer; - - private NetconfClientDispatcherImpl clientDispatcher; - private Channel serverTcpChannel; - - private NetconfMessage getConfig; - private NetconfMessage get; - - /** - * @Before in subclasses is called after this method. - */ - @Before - public void setUpAbstractNetconfConfigTest() throws Exception { - super.initConfigTransactionManagerImpl(new HardcodedModuleFactoriesResolver(mockedContext, FACTORIES)); - - nettyThreadgroup = new NioEventLoopGroup(); - hashedWheelTimer = new HashedWheelTimer(); - - loadMessages(); - - setUpTestInitial(); - - final AggregatedNetconfOperationServiceFactory factoriesListener = - new AggregatedNetconfOperationServiceFactory(); - final NetconfMonitoringService netconfMonitoringService = getNetconfMonitoringService(factoriesListener); - configSubsystemFacadeFactory = - new ConfigSubsystemFacadeFactory(configRegistryClient, configRegistryClient, getYangStore()); - factoriesListener.onAddNetconfOperationServiceFactory( - new NetconfOperationServiceFactoryImpl(configSubsystemFacadeFactory)); - factoriesListener.onAddNetconfOperationServiceFactory( - new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory( - new NetconfMonitoringOperationService(netconfMonitoringService))); - - for (final NetconfOperationServiceFactory netconfOperationServiceFactory : getAdditionalServiceFactories( - factoriesListener)) { - factoriesListener.onAddNetconfOperationServiceFactory(netconfOperationServiceFactory); - } - - serverTcpChannel = startNetconfTcpServer(factoriesListener, netconfMonitoringService); - clientDispatcher = - new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer()); - } - - /** - * Called before setUp method is executed, so test classes can set up resources before - * setUpAbstractNetconfConfigTest method is called. - */ - protected void setUpTestInitial() throws Exception {} - - private void loadMessages() throws Exception { - this.getConfig = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/getConfig.xml"); - this.get = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/get.xml"); - } - - public NetconfMessage getGetConfig() { - return getConfig; - } - - public NetconfMessage getGet() { - return get; - } - - private Channel startNetconfTcpServer(final AggregatedNetconfOperationServiceFactory listener, - final NetconfMonitoringService monitoring) throws Exception { - final NetconfServerDispatcherImpl dispatch = createDispatcher(listener, monitoring); - - final ChannelFuture s; - if (getTcpServerAddress() instanceof LocalAddress) { - s = dispatch.createLocalServer(((LocalAddress) getTcpServerAddress())); - } else { - s = dispatch.createServer(((InetSocketAddress) getTcpServerAddress())); - } - s.await(RESOURCE_TIMEOUT_MINUTES, TimeUnit.MINUTES); - return s.channel(); - } - - protected Iterable getAdditionalServiceFactories( - final AggregatedNetconfOperationServiceFactory factoriesListener) throws Exception { - return Collections.emptySet(); - } - - protected NetconfMonitoringService getNetconfMonitoringService( - final AggregatedNetconfOperationServiceFactory factoriesListener) throws Exception { - return new NetconfMonitoringServiceImpl(factoriesListener); - } - - protected abstract SocketAddress getTcpServerAddress(); - - public NetconfClientDispatcherImpl getClientDispatcher() { - return clientDispatcher; - } - - private HardcodedYangStoreService getYangStore() throws IOException { - final Collection yangDependencies = getBasicYangs(); - return new HardcodedYangStoreService(yangDependencies, getBindingRuntimeContext()); - } - - static Collection getBasicYangs() throws IOException { - - final List paths = Arrays.asList("/META-INF/yang/config@2013-04-05.yang", - "/META-INF/yang/rpc-context@2013-06-17.yang", - "/META-INF/yang/config-test.yang", "/META-INF/yang/config-test-impl.yang", - "/META-INF/yang/test-types.yang", "/META-INF/yang/test-groups.yang", - "/META-INF/yang/ietf-inet-types@2013-07-15.yang"); - - final Collection yangDependencies = new ArrayList<>(); - final List failedToFind = new ArrayList<>(); - for (final String path : paths) { - final InputStream resourceAsStream = NetconfITTest.class.getResourceAsStream(path); - if (resourceAsStream == null) { - failedToFind.add(path); - } else { - yangDependencies.add(resourceAsStream); - } - } - assertEquals("Some yang files were not found", Collections.emptyList(), failedToFind); - return yangDependencies; - } - - protected NetconfServerDispatcherImpl createDispatcher( - final AggregatedNetconfOperationServiceFactory factoriesListener, - final NetconfMonitoringService sessionMonitoringService) { - final SessionIdProvider idProvider = new SessionIdProvider(); - - final NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = - new NetconfServerSessionNegotiatorFactory(hashedWheelTimer, factoriesListener, idProvider, - SERVER_CONNECTION_TIMEOUT_MILLIS, sessionMonitoringService); - - final NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer = - new NetconfServerDispatcherImpl.ServerChannelInitializer(serverNegotiatorFactory); - return new NetconfServerDispatcherImpl(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup); - } - - protected HashedWheelTimer getHashedWheelTimer() { - return hashedWheelTimer; - } - - protected EventLoopGroup getNettyThreadgroup() { - return nettyThreadgroup; - } - - /** - * @After in subclasses is be called before this. - */ - @After - public void cleanUpNetconf() throws Exception { - serverTcpChannel.close().await(RESOURCE_TIMEOUT_MINUTES, TimeUnit.MINUTES); - hashedWheelTimer.stop(); - nettyThreadgroup.shutdownGracefully().await(RESOURCE_TIMEOUT_MINUTES, TimeUnit.MINUTES); - } - - public NetconfClientConfiguration getClientConfiguration(final InetSocketAddress tcpAddress, final int timeout) { - final NetconfClientConfigurationBuilder b = NetconfClientConfigurationBuilder.create(); - b.withAddress(tcpAddress); - b.withSessionListener(new SimpleNetconfClientSessionListener()); - b.withReconnectStrategy(new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, timeout)); - b.withConnectionTimeoutMillis(timeout); - return b.build(); - } - - public static final class HardcodedYangStoreService extends YangStoreService { - public HardcodedYangStoreService(final Collection inputStreams, - final BindingRuntimeContext bindingRuntimeContext) throws IOException { - super(new SchemaContextProvider() { - @Override - public SchemaContext getSchemaContext() { - return getSchema(inputStreams); - } - }, new SchemaSourceProvider() { - @Override - public CheckedFuture getSource( - SourceIdentifier sourceIdentifier) { - - return null; - } - }); - - refresh(bindingRuntimeContext); - } - - private static SchemaContext getSchema(final Collection inputStreams) { - final ArrayList byteArrayInputStreams = new ArrayList<>(); - for (final InputStream inputStream : inputStreams) { - assertNotNull(inputStream); - final byte[] content; - try { - content = ByteStreams.toByteArray(inputStream); - } catch (IOException e) { - throw new IllegalStateException("Cannot read " + inputStream, e); - } - final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(content); - byteArrayInputStreams.add(byteArrayInputStream); - } - - for (final InputStream inputStream : byteArrayInputStreams) { - try { - inputStream.reset(); - } catch (final IOException e) { - throw new RuntimeException(e); - } - } - - try { - return YangInferencePipeline.RFC6020_REACTOR.newBuild().buildEffective(byteArrayInputStreams); - } catch (SourceException | ReactorException e) { - throw Throwables.propagate(e); - } - } - - @Override - public EnumResolver getEnumResolver() { - return new EnumResolver() { - @Override - public String fromYang(final String enumType, final String enumYangValue) { - return BindingMapping.getClassName(enumYangValue); - } - - @Override - public String toYang(final String enumType, final String enumJavaValue) { - return enumJavaValue.toLowerCase(); - } - }; - } - } -} diff --git a/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfConfigPersisterITTest.java b/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfConfigPersisterITTest.java deleted file mode 100644 index 91fc867055..0000000000 --- a/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfConfigPersisterITTest.java +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.netconf.it; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.opendaylight.controller.config.util.xml.XmlUtil.readXmlToDocument; -import static org.opendaylight.netconf.util.test.XmlUnitUtil.assertContainsElementWithName; -import static org.opendaylight.netconf.util.test.XmlUnitUtil.assertElementsCount; - -import com.google.common.collect.HashBiMap; -import com.google.common.collect.Lists; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.util.List; -import javax.management.InstanceNotFoundException; -import javax.management.Notification; -import javax.management.NotificationListener; -import org.junit.Test; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; -import org.opendaylight.controller.config.api.jmx.notifications.CommitJMXNotification; -import org.opendaylight.controller.config.api.jmx.notifications.ConfigJMXNotification; -import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; -import org.opendaylight.controller.config.persist.api.Persister; -import org.opendaylight.controller.config.persist.impl.ConfigPersisterNotificationHandler; -import org.opendaylight.netconf.api.NetconfMessage; -import org.opendaylight.netconf.client.TestingNetconfClient; -import org.opendaylight.netconf.util.test.XmlFileLoader; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.test.types.rev131127.TestIdentity1; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.test.types.rev131127.TestIdentity2; -import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext; -import org.w3c.dom.Document; -import org.xml.sax.SAXException; - -public class NetconfConfigPersisterITTest extends AbstractNetconfConfigTest { - - public static final int PORT = 12026; - private static final InetSocketAddress TCP_ADDRESS = new InetSocketAddress(LOOPBACK_ADDRESS, PORT); - - @Override - protected SocketAddress getTcpServerAddress() { - return TCP_ADDRESS; - } - - @Test - public void testNetconfCommitNotifications() throws Exception { - final VerifyingNotificationListener notificationVerifier = createCommitNotificationListener(); - final VerifyingPersister mockedAggregator = mockAggregator(); - - try (TestingNetconfClient persisterClient = new TestingNetconfClient("persister", getClientDispatcher(), getClientConfiguration(TCP_ADDRESS, 4000))) { - try (ConfigPersisterNotificationHandler configPersisterNotificationHandler = new ConfigPersisterNotificationHandler( - platformMBeanServer, mockedAggregator, configSubsystemFacadeFactory)) { - - try (TestingNetconfClient netconfClient = new TestingNetconfClient("client", getClientDispatcher(), getClientConfiguration(TCP_ADDRESS, 4000))) { - NetconfMessage response = netconfClient.sendMessage(loadEditConfigMessage()); - assertContainsElementWithName(response.getDocument(), "ok"); - response = netconfClient.sendMessage(loadCommitMessage()); - assertContainsElementWithName(response.getDocument(), "ok"); - - response = netconfClient.sendMessage(loadGetConfigMessage()); - assertContainsElementWithName(response.getDocument(), "modules"); - assertContainsElementWithName(response.getDocument(), "services"); - } - } - } - - notificationVerifier.assertNotificationCount(1); - - mockedAggregator.assertSnapshotCount(1); - // Capabilities are stripped for persister - mockedAggregator.assertSnapshotContent(0, 4, 3, 3); - } - - @Override - protected BindingRuntimeContext getBindingRuntimeContext() { - final BindingRuntimeContext ret = super.getBindingRuntimeContext(); - doReturn(TestIdentity1.class).when(ret).getIdentityClass(TestIdentity1.QNAME); - doReturn(TestIdentity2.class).when(ret).getIdentityClass(TestIdentity2.QNAME); - final HashBiMap toBeReturned = HashBiMap.create(); - toBeReturned.put("two", "Two"); - toBeReturned.put("one", "One"); - toBeReturned.put("version1", "Version1"); - doReturn(toBeReturned).when(ret).getEnumMapping(anyString()); - return ret; - } - - private VerifyingPersister mockAggregator() throws IOException { - return new VerifyingPersister(); - } - - private VerifyingNotificationListener createCommitNotificationListener() throws InstanceNotFoundException { - final VerifyingNotificationListener listener = new VerifyingNotificationListener(); - platformMBeanServer.addNotificationListener(ConfigJMXNotification.OBJECT_NAME, listener, null, null); - return listener; - } - - private NetconfMessage loadGetConfigMessage() throws Exception { - return XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/getConfig.xml"); - } - - private NetconfMessage loadEditConfigMessage() throws Exception { - return XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/editConfig.xml"); - } - - private NetconfMessage loadCommitMessage() throws Exception { - return XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/commit.xml"); - } - - private static class VerifyingNotificationListener implements NotificationListener { - public List notifications = Lists.newArrayList(); - - @Override - public void handleNotification(final Notification notification, final Object handback) { - this.notifications.add(notification); - } - - void assertNotificationCount(final Object size) { - assertEquals(size, notifications.size()); - } - - void assertNotificationContent(final int notificationIndex) { - final Notification notification = notifications.get(notificationIndex); - assertEquals(CommitJMXNotification.class, notification.getClass()); - } - } - - private static class VerifyingPersister implements Persister { - - public List snapshots = Lists.newArrayList(); - private Persister mockedPersister; - - public VerifyingPersister() throws IOException { - final Persister mockedAggregator = mock(Persister.class); - - doAnswer(new Answer() { - @Override - public Object answer(final InvocationOnMock invocation) throws Throwable { - final ConfigSnapshotHolder configSnapshot = (ConfigSnapshotHolder) invocation.getArguments()[0]; - snapshots.add(configSnapshot); - return null; - } - }).when(mockedAggregator).persistConfig(any(ConfigSnapshotHolder.class)); - - this.mockedPersister = mockedAggregator; - } - - void assertSnapshotCount(final Object size) { - assertEquals(size, snapshots.size()); - } - - void assertSnapshotContent(final int notificationIndex, final int expectedModulesSize, final int expectedServicesSize, final int expectedCapsSize) - throws SAXException, IOException { - final ConfigSnapshotHolder snapshot = snapshots.get(notificationIndex); - final int capsSize = snapshot.getCapabilities().size(); - assertEquals("Expected capabilities count should be " + expectedCapsSize + " but was " + snapshot.getCapabilities(), expectedCapsSize, capsSize); - final Document configSnapshot = readXmlToDocument(snapshot.getConfigSnapshot()); - assertElementsCount(configSnapshot, "module", expectedModulesSize); - assertElementsCount(configSnapshot, "instance", expectedServicesSize); - } - - @Override - public void persistConfig(final ConfigSnapshotHolder configSnapshotHolder) throws IOException { - mockedPersister.persistConfig(configSnapshotHolder); - } - - @Override - public List loadLastConfigs() throws IOException { - return mockedPersister.loadLastConfigs(); - } - - @Override - public void close() { - mockedPersister.close(); - } - } -} diff --git a/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfITMonitoringTest.java b/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfITMonitoringTest.java deleted file mode 100644 index 8e1b1a0f5f..0000000000 --- a/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfITMonitoringTest.java +++ /dev/null @@ -1,166 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.netconf.it; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.opendaylight.netconf.util.test.XmlUnitUtil.assertContainsElementWithText; - -import com.google.common.base.Optional; -import com.google.common.collect.Sets; -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.nio.charset.StandardCharsets; -import java.util.Collections; -import java.util.List; -import java.util.Set; -import org.junit.Test; -import org.opendaylight.controller.config.util.capability.Capability; -import org.opendaylight.controller.config.util.xml.XmlUtil; -import org.opendaylight.netconf.api.NetconfMessage; -import org.opendaylight.netconf.api.monitoring.CapabilityListener; -import org.opendaylight.netconf.client.TestingNetconfClient; -import org.opendaylight.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory; -import org.opendaylight.netconf.mapping.api.NetconfOperationService; -import org.opendaylight.netconf.util.test.XmlFileLoader; -import org.w3c.dom.Document; - -public class NetconfITMonitoringTest extends AbstractNetconfConfigTest { - - public static final int PORT = 12025; - public static final InetSocketAddress TCP_ADDRESS = new InetSocketAddress(LOOPBACK_ADDRESS, PORT); - public static final TestingCapability TESTING_CAPABILITY = new TestingCapability(); - - @Override - protected InetSocketAddress getTcpServerAddress() { - return TCP_ADDRESS; - } - - @Test - public void testGetResponseFromMonitoring() throws Exception { - try (TestingNetconfClient netconfClient = new TestingNetconfClient("client-monitoring", getClientDispatcher(), getClientConfiguration(TCP_ADDRESS, 10000))) { - try (TestingNetconfClient netconfClient2 = new TestingNetconfClient("client-monitoring2", getClientDispatcher(), getClientConfiguration(TCP_ADDRESS, 10000))) { - Thread.sleep(500); - final NetconfMessage response = netconfClient2.sendMessage(getGet()); - assertSessionElementsInResponse(response.getDocument(), 2); - } - Thread.sleep(500); - final NetconfMessage response = netconfClient.sendMessage(getGet()); - assertSessionElementsInResponse(response.getDocument(), 1); - } - } - - @Test(timeout = 13 * 10000) - public void testClientHelloWithAuth() throws Exception { - String fileName = "netconfMessages/client_hello_with_auth.xml"; - final String hello = XmlFileLoader.fileToString(fileName); - - fileName = "netconfMessages/get.xml"; - final String get = XmlFileLoader.fileToString(fileName); - - final Socket sock = new Socket(TCP_ADDRESS.getHostName(), TCP_ADDRESS.getPort()); - sock.getOutputStream().write(hello.getBytes(StandardCharsets.UTF_8)); - final String separator = "]]>]]>"; - - sock.getOutputStream().write(separator.getBytes(StandardCharsets.UTF_8)); - sock.getOutputStream().write(get.getBytes(StandardCharsets.UTF_8)); - sock.getOutputStream().write(separator.getBytes(StandardCharsets.UTF_8)); - - final StringBuilder responseBuilder = new StringBuilder(); - - try (InputStream inputStream = sock.getInputStream(); - InputStreamReader reader = new InputStreamReader(inputStream); - BufferedReader buff = new BufferedReader(reader)) { - String line; - while ((line = buff.readLine()) != null) { - - responseBuilder.append(line); - responseBuilder.append(System.lineSeparator()); - - if(line.contains("")) - break; - } - } - - sock.close(); - - final String helloMsg = responseBuilder.substring(0, responseBuilder.indexOf(separator)); - Document doc = XmlUtil.readXmlToDocument(helloMsg); - assertContainsElementWithText(doc, "urn:ietf:params:netconf:capability:candidate:1.0"); - - final String replyMsg = responseBuilder.substring(responseBuilder.indexOf(separator) + separator.length()); - doc = XmlUtil.readXmlToDocument(replyMsg); - assertContainsElementWithText(doc, "tomas"); - } - - private void assertSessionElementsInResponse(final Document document, final int i) { - final int elementSize = document.getElementsByTagName("session-id").getLength(); - assertEquals("Incorrect number of session-id tags in " + XmlUtil.toString(document), i, elementSize); - } - - public static AggregatedNetconfOperationServiceFactory getNetconfOperationProvider() throws Exception { - final AggregatedNetconfOperationServiceFactory factoriesListener = mock(AggregatedNetconfOperationServiceFactory.class); - final NetconfOperationService snap = mock(NetconfOperationService.class); - try { - doNothing().when(snap).close(); - } catch (final Exception e) { - // not happening - throw new IllegalStateException(e); - } - final Set caps = Sets.newHashSet(); - caps.add(TESTING_CAPABILITY); - - doReturn(caps).when(factoriesListener).getCapabilities(); - doReturn(snap).when(factoriesListener).createService(anyString()); - - AutoCloseable mock = mock(AutoCloseable.class); - doNothing().when(mock).close(); - doReturn(mock).when(factoriesListener).registerCapabilityListener(any(CapabilityListener.class)); - - return factoriesListener; - } - - private static class TestingCapability implements Capability { - @Override - public String getCapabilityUri() { - return "namespaceModuleRevision"; - } - - @Override - public Optional getModuleNamespace() { - return Optional.of("namespace"); - } - - @Override - public Optional getModuleName() { - return Optional.of("name"); - } - - @Override - public Optional getRevision() { - return Optional.of("revision"); - } - - @Override - public Optional getCapabilitySchema() { - return Optional.of("content"); - } - - @Override - public List getLocation() { - return Collections.emptyList(); - } - } -} diff --git a/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfITSecureTest.java b/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfITSecureTest.java deleted file mode 100644 index d39f2e5de4..0000000000 --- a/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfITSecureTest.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.netconf.it; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; - -import com.google.common.collect.Lists; -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.local.LocalAddress; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.util.concurrent.GlobalEventExecutor; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.nio.file.Files; -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicInteger; -import org.apache.sshd.server.keyprovider.PEMGeneratorHostKeyProvider; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.controller.config.util.xml.XmlUtil; -import org.opendaylight.netconf.api.NetconfMessage; -import org.opendaylight.netconf.auth.AuthProvider; -import org.opendaylight.netconf.client.NetconfClientDispatcher; -import org.opendaylight.netconf.client.NetconfClientDispatcherImpl; -import org.opendaylight.netconf.client.NetconfClientSessionListener; -import org.opendaylight.netconf.client.SimpleNetconfClientSessionListener; -import org.opendaylight.netconf.client.TestingNetconfClient; -import org.opendaylight.netconf.client.conf.NetconfClientConfiguration; -import org.opendaylight.netconf.client.conf.NetconfClientConfigurationBuilder; -import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; -import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPassword; -import org.opendaylight.netconf.sal.connect.api.RemoteDevice; -import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator; -import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences; -import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; -import org.opendaylight.netconf.ssh.SshProxyServer; -import org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder; -import org.opendaylight.netconf.util.messages.NetconfMessageUtil; -import org.opendaylight.netconf.util.osgi.NetconfConfigUtil; -import org.opendaylight.protocol.framework.NeverReconnectStrategy; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.RpcResult; -import org.xml.sax.SAXException; - -public class NetconfITSecureTest extends AbstractNetconfConfigTest { - - public static final int PORT = 12024; - private static final InetSocketAddress TLS_ADDRESS = new InetSocketAddress("127.0.0.1", PORT); - - public static final String USERNAME = "user"; - public static final String PASSWORD = "pwd"; - - private SshProxyServer sshProxyServer; - - private ExecutorService nioExec; - private EventLoopGroup clientGroup; - private ScheduledExecutorService minaTimerEx; - - @Before - public void setUp() throws Exception { - nioExec = Executors.newFixedThreadPool(1); - clientGroup = new NioEventLoopGroup(); - minaTimerEx = Executors.newScheduledThreadPool(1); - sshProxyServer = new SshProxyServer(minaTimerEx, clientGroup, nioExec); - sshProxyServer.bind( - new SshProxyServerConfigurationBuilder() - .setBindingAddress(TLS_ADDRESS) - .setLocalAddress(NetconfConfigUtil.getNetconfLocalAddress()) - .setAuthenticator(new AuthProvider() { - @Override - public boolean authenticated(String username, String password) { - return true; - } - } - ) - .setKeyPairProvider(new PEMGeneratorHostKeyProvider(Files.createTempFile("prefix", "suffix").toAbsolutePath().toString())) - .setIdleTimeout(Integer.MAX_VALUE) - .createSshProxyServerConfiguration()); - } - - @After - public void tearDown() throws Exception { - sshProxyServer.close(); - clientGroup.shutdownGracefully(); - minaTimerEx.shutdownNow(); - nioExec.shutdownNow(); - } - - @Test(timeout = 2*60*1000) - public void testSecure() throws Exception { - final NetconfClientDispatcher dispatch = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer()); - try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, getClientConfiguration(new SimpleNetconfClientSessionListener(), TLS_ADDRESS))) { - NetconfMessage response = netconfClient.sendMessage(getGetConfig()); - assertFalse("Unexpected error message " + XmlUtil.toString(response.getDocument()), - NetconfMessageUtil.isErrorMessage(response)); - - final NetconfMessage gs = new NetconfMessage(XmlUtil.readXmlToDocument("\n" + - " \n" + - " config\n" + - " \n" + - "\n")); - - response = netconfClient.sendMessage(gs); - assertFalse("Unexpected error message " + XmlUtil.toString(response.getDocument()), - NetconfMessageUtil.isErrorMessage(response)); - } - } - - /** - * Test all requests are handled properly and no mismatch occurs in listener - */ - @Test(timeout = 6*60*1000) - public void testSecureStress() throws Exception { - final int requests = 4000; - - final NetconfClientDispatcher dispatch = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer()); - final NetconfDeviceCommunicator sessionListener = getSessionListener(); - try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, getClientConfiguration(sessionListener, TLS_ADDRESS))) { - - final AtomicInteger responseCounter = new AtomicInteger(0); - final List>> futures = Lists.newArrayList(); - - for (int i = 0; i < requests; i++) { - NetconfMessage getConfig = getGetConfig(); - getConfig = changeMessageId(getConfig, i); - final ListenableFuture> netconfMessageFuture = sessionListener.sendRequest(getConfig, QName.create("namespace", "2012-12-12", "get")); - futures.add(netconfMessageFuture); - Futures.addCallback(netconfMessageFuture, new FutureCallback>() { - @Override - public void onSuccess(final RpcResult result) { - responseCounter.incrementAndGet(); - } - - @Override - public void onFailure(final Throwable t) { - throw new RuntimeException(t); - } - }); - } - - // Wait for every future - for (final ListenableFuture> future : futures) { - try { - future.get(3, TimeUnit.MINUTES); - } catch (final TimeoutException e) { - fail("Request " + futures.indexOf(future) + " is not responding"); - } - } - - // Give future listeners some time to finish counter incrementation - Thread.sleep(5000); - - assertEquals(requests, responseCounter.get()); - } - } - - public static NetconfMessage changeMessageId(final NetconfMessage getConfig, final int i) throws IOException, SAXException { - String s = XmlUtil.toString(getConfig.getDocument(), false); - s = s.replace("101", Integer.toString(i)); - return new NetconfMessage(XmlUtil.readXmlToDocument(s)); - } - - static NetconfClientConfiguration getClientConfiguration(final NetconfClientSessionListener sessionListener,final InetSocketAddress tlsAddress) throws IOException { - final NetconfClientConfigurationBuilder b = NetconfClientConfigurationBuilder.create(); - b.withAddress(tlsAddress); - // Using session listener from sal-netconf-connector since stress test cannot be performed with simple listener - b.withSessionListener(sessionListener); - b.withReconnectStrategy(new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000)); - b.withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH); - b.withConnectionTimeoutMillis(5000); - b.withAuthHandler(getAuthHandler()); - return b.build(); - } - - static NetconfDeviceCommunicator getSessionListener() { - RemoteDevice mockedRemoteDevice = mock(RemoteDevice.class); - doNothing().when(mockedRemoteDevice).onRemoteSessionUp(any(NetconfSessionPreferences.class), any(NetconfDeviceCommunicator.class)); - doNothing().when(mockedRemoteDevice).onRemoteSessionDown(); - return new NetconfDeviceCommunicator(new RemoteDeviceId("secure-test", InetSocketAddress.createUnresolved("localhost", 22)), mockedRemoteDevice); - } - - public AuthProvider getAuthProvider() throws Exception { - final AuthProvider mockAuth = mock(AuthProvider.class); - doReturn("mockedAuth").when(mockAuth).toString(); - doReturn(true).when(mockAuth).authenticated(anyString(), anyString()); - return mockAuth; - } - - public static AuthenticationHandler getAuthHandler() throws IOException { - return new LoginPassword(USERNAME, PASSWORD); - } - - @Override - protected LocalAddress getTcpServerAddress() { - return NetconfConfigUtil.getNetconfLocalAddress(); - } -} diff --git a/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfITSecureTestTool.java b/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfITSecureTestTool.java deleted file mode 100644 index 6e7ef741ba..0000000000 --- a/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfITSecureTestTool.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.netconf.it; - -import static java.lang.Thread.sleep; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.opendaylight.netconf.it.NetconfITSecureTest.getSessionListener; - -import com.google.common.base.Throwables; -import com.google.common.collect.Lists; -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.util.HashedWheelTimer; -import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicInteger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.netconf.api.NetconfMessage; -import org.opendaylight.netconf.client.NetconfClientDispatcher; -import org.opendaylight.netconf.client.NetconfClientDispatcherImpl; -import org.opendaylight.netconf.client.TestingNetconfClient; -import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator; -import org.opendaylight.netconf.test.tool.Main.Params; -import org.opendaylight.netconf.test.tool.NetconfDeviceSimulator; -import org.opendaylight.netconf.util.test.XmlFileLoader; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.RpcResult; - -public class NetconfITSecureTestTool -{ - - //set up port both for testool device and test - public static final int PORT = 17833; - private static final InetSocketAddress TLS_ADDRESS = new InetSocketAddress("127.0.0.1", PORT); - - private String xmlFile = "netconfMessages/editConfig.xml"; - - private ExecutorService msgExec = Executors.newFixedThreadPool(8); - - Collection> tasks = new LinkedList>(); - - final NetconfDeviceSimulator netconfDeviceSimulator = new NetconfDeviceSimulator(); - - @Before - public void setUp() throws Exception { - - //Set up parameters for testtool device - Params params = new Params(); - params.debug = true; - params.deviceCount = 1; - params.startingPort = PORT; - params.ssh = true; - params.exi = true; - - final List openDevices = netconfDeviceSimulator.start(params); - } - - @After - public void tearDown() throws Exception { - - } - - /** - * Test all requests are handled properly and no mismatch occurs in listener - */ - @Test(timeout = 6*60*1000) - public void testSecureStress() throws Exception { - - final int requests = 4000; - - List> tasks = new ArrayList<>(); - - final NetconfClientDispatcher dispatch = new NetconfClientDispatcherImpl(new NioEventLoopGroup(), new NioEventLoopGroup(), new HashedWheelTimer()); - - final NetconfDeviceCommunicator sessionListener = getSessionListener(); - - try (TestingNetconfClient netconfClient = new TestingNetconfClient("testing-ssh-client", dispatch, NetconfITSecureTest.getClientConfiguration(sessionListener, TLS_ADDRESS));) - { - - final AtomicInteger responseCounter = new AtomicInteger(0); - final List>> futures = Lists.newArrayList(); - - for (int i = 0; i < requests; i++) { - - NetconfMessage getConfig = XmlFileLoader.xmlFileToNetconfMessage(xmlFile); - - getConfig = NetconfITSecureTest.changeMessageId(getConfig,i); - - Runnable worker = new NetconfITSecureTestToolRunnable(getConfig,i, sessionListener, futures, responseCounter); - - tasks.add(msgExec.submit(worker)); - - } - - msgExec.shutdown(); - - // Wait for every future - for (final Future task : tasks){ - try - { - - task.get(3, TimeUnit.MINUTES); - } catch (final TimeoutException e) { - fail(String.format("Request %d is not responding", tasks.indexOf(task))); - } - } - - for (final ListenableFuture> future : futures) { - try { - - future.get(3, TimeUnit.MINUTES); - } catch (final TimeoutException e) { - fail(String.format("Reply %d is not responding", futures.indexOf(future))); - } - } - - sleep(5000); - - assertEquals(requests, responseCounter.get()); - - } - } - - class NetconfITSecureTestToolRunnable implements Runnable { - - private NetconfMessage getConfig; - private int it; - private NetconfDeviceCommunicator sessionListener; - private List>> futures; - private AtomicInteger responseCounter; - - public NetconfITSecureTestToolRunnable(NetconfMessage getConfig, int it, NetconfDeviceCommunicator sessionListener, List>> futures, AtomicInteger responseCounter){ - this.getConfig = getConfig; - this.it = it; - this.sessionListener = sessionListener; - this.futures = futures; - this.responseCounter = responseCounter; - } - - @Override - public void run(){ - - ListenableFuture> netconfMessageFuture; - - netconfMessageFuture = sessionListener.sendRequest(getConfig, QName.create("namespace", "2012-12-12", "get")); - - futures.add(netconfMessageFuture); - Futures.addCallback(netconfMessageFuture, new FutureCallback>() { - - @Override - public void onSuccess(final RpcResult result) { - - if(result.isSuccessful()&result.getErrors().isEmpty()) { - responseCounter.incrementAndGet(); - } else { - - fail(String.format("Message result not ok %s", result.getErrors().toString())); - - } - } - - @Override - public void onFailure(final Throwable t) { - - fail(String.format("Message failed %s", Throwables.getStackTraceAsString(t))); - - } - } - ); - } - } - -} diff --git a/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfITTest.java b/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfITTest.java deleted file mode 100644 index fc97e693db..0000000000 --- a/netconf/netconf-it/src/test/java/org/opendaylight/netconf/it/NetconfITTest.java +++ /dev/null @@ -1,350 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.netconf.it; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.doReturn; - -import com.google.common.base.Throwables; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeoutException; -import javax.management.ObjectName; -import javax.xml.parsers.ParserConfigurationException; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.controller.config.api.jmx.ObjectNameUtil; -import org.opendaylight.controller.config.util.ConfigTransactionJMXClient; -import org.opendaylight.controller.config.util.xml.DocumentedException; -import org.opendaylight.controller.config.util.xml.XmlElement; -import org.opendaylight.controller.config.util.xml.XmlUtil; -import org.opendaylight.controller.config.yang.test.impl.DepTestImplModuleFactory; -import org.opendaylight.controller.config.yang.test.impl.MultipleDependenciesModuleFactory; -import org.opendaylight.controller.config.yang.test.impl.MultipleDependenciesModuleMXBean; -import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleFactory; -import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleMXBean; -import org.opendaylight.netconf.api.NetconfMessage; -import org.opendaylight.netconf.client.NetconfClientDispatcher; -import org.opendaylight.netconf.client.TestingNetconfClient; -import org.opendaylight.netconf.util.test.XmlFileLoader; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.test.types.rev131127.TestIdentity1; -import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.test.types.rev131127.TestIdentity2; -import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.xml.sax.SAXException; - -public class NetconfITTest extends AbstractNetconfConfigTest { - - public static final int PORT = 12023; - public static final InetSocketAddress TCP_ADDRESS = new InetSocketAddress(LOOPBACK_ADDRESS, PORT); - - private NetconfMessage getConfigCandidate, editConfig, closeSession; - private NetconfClientDispatcher clientDispatcher; - - @Before - public void setUp() throws Exception { - loadMessages(); - clientDispatcher = getClientDispatcher(); - } - - @Override - protected InetSocketAddress getTcpServerAddress() { - return TCP_ADDRESS; - } - - private void loadMessages() throws IOException, SAXException, ParserConfigurationException { - this.editConfig = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/edit_config.xml"); - this.getConfigCandidate = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/getConfig_candidate.xml"); - this.closeSession = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/closeSession.xml"); - } - - @Test - public void testNetconfClientDemonstration() throws Exception { - try (TestingNetconfClient netconfClient = new TestingNetconfClient("client", clientDispatcher, getClientConfiguration(TCP_ADDRESS, 4000))) { - - final Set capabilitiesFromNetconfServer = netconfClient.getCapabilities(); - final long sessionId = netconfClient.getSessionId(); - - // NetconfMessage can be created : - // new NetconfMessage(XmlUtil.readXmlToDocument("")); - - final NetconfMessage response = netconfClient.sendMessage(getGetConfig()); - response.getDocument(); - } - } - - @Test - public void testTwoSessions() throws Exception { - try (TestingNetconfClient netconfClient = new TestingNetconfClient("1", clientDispatcher, getClientConfiguration(TCP_ADDRESS, 10000))) { - try (TestingNetconfClient netconfClient2 = new TestingNetconfClient("2", clientDispatcher, getClientConfiguration(TCP_ADDRESS, 10000))) { - assertNotNull(netconfClient2.getCapabilities()); - } - } - } - - @Test - public void rpcReplyContainsAllAttributesTest() throws Exception { - try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) { - final String rpc = "" + ""; - final Document doc = XmlUtil.readXmlToDocument(rpc); - final NetconfMessage message = netconfClient.sendMessage(new NetconfMessage(doc)); - assertNotNull(message); - final NamedNodeMap expectedAttributes = doc.getDocumentElement().getAttributes(); - final NamedNodeMap returnedAttributes = message.getDocument().getDocumentElement().getAttributes(); - - assertSameAttributes(expectedAttributes, returnedAttributes); - } - } - - private void assertSameAttributes(final NamedNodeMap expectedAttributes, final NamedNodeMap returnedAttributes) { - assertNotNull("Expecting 4 attributes", returnedAttributes); - assertEquals(expectedAttributes.getLength(), returnedAttributes.getLength()); - - for (int i = 0; i < expectedAttributes.getLength(); i++) { - final Node expAttr = expectedAttributes.item(i); - final Node attr = returnedAttributes.item(i); - assertEquals(expAttr.getNodeName(), attr.getNodeName()); - assertEquals(expAttr.getNamespaceURI(), attr.getNamespaceURI()); - assertEquals(expAttr.getTextContent(), attr.getTextContent()); - } - } - - @Test - public void rpcReplyErrorContainsAllAttributesTest() throws Exception { - try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) { - final String rpc = "" + ""; - final Document doc = XmlUtil.readXmlToDocument(rpc); - final NetconfMessage message = netconfClient.sendMessage(new NetconfMessage(doc)); - final NamedNodeMap expectedAttributes = doc.getDocumentElement().getAttributes(); - final NamedNodeMap returnedAttributes = message.getDocument().getDocumentElement().getAttributes(); - - assertSameAttributes(expectedAttributes, returnedAttributes); - } - } - - @Test - public void rpcOutputContainsCorrectNamespace() throws Exception { - final ConfigTransactionJMXClient transaction = this.configRegistryClient.createTransaction(); - final ObjectName dep = transaction.createModule(DepTestImplModuleFactory.NAME, "instanceD"); - final ObjectName impl = transaction.createModule(NetconfTestImplModuleFactory.NAME, "instance"); - final NetconfTestImplModuleMXBean proxy = configRegistryClient - .newMXBeanProxy(impl, NetconfTestImplModuleMXBean.class); - proxy.setTestingDep(dep); - proxy.setSimpleShort((short) 0); - - transaction.commit(); - - try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) { - final String expectedNamespace = "urn:opendaylight:params:xml:ns:yang:controller:test:impl"; - - final String rpc = "" - + " " - + "/modules/module[type='impl-netconf'][name='instance']" - + "argument1" + "" + ""; - final Document doc = XmlUtil.readXmlToDocument(rpc); - final NetconfMessage message = netconfClient.sendMessage(new NetconfMessage(doc)); - - final Element rpcReply = message.getDocument().getDocumentElement(); - final XmlElement resultElement = XmlElement.fromDomElement(rpcReply).getOnlyChildElement(); - assertEquals("result", resultElement.getName()); - - final String namespace = resultElement.getNamespaceAttribute(); - assertEquals(expectedNamespace, namespace); - } - } - - @Test - public void testCloseSession() throws Exception { - try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) { - - // edit config - Document rpcReply = netconfClient.sendMessage(this.editConfig) - .getDocument(); - assertIsOK(rpcReply); - - rpcReply = netconfClient.sendMessage(this.closeSession) - .getDocument(); - - assertIsOK(rpcReply); - } - } - - @Test - public void testEditConfig() throws Exception { - try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) { - // send edit_config.xml - final Document rpcReply = netconfClient.sendMessage(this.editConfig).getDocument(); - assertIsOK(rpcReply); - } - } - - @Test - public void testValidate() throws Exception { - try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) { - // begin transaction - Document rpcReply = netconfClient.sendMessage(getConfigCandidate).getDocument(); - assertEquals("data", XmlElement.fromDomDocument(rpcReply).getOnlyChildElement().getName()); - - // operations empty - rpcReply = netconfClient.sendMessage(XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/validate.xml")) - .getDocument(); - assertIsOK(rpcReply); - } - } - - private void assertIsOK(final Document rpcReply) throws DocumentedException { - assertEquals("rpc-reply", rpcReply.getDocumentElement().getLocalName()); - assertEquals("ok", XmlElement.fromDomDocument(rpcReply).getOnlyChildElement().getName()); - } - - private Document assertGetConfigWorks(final TestingNetconfClient netconfClient) throws InterruptedException, ExecutionException, TimeoutException, DocumentedException { - return assertGetConfigWorks(netconfClient, getGetConfig()); - } - - private Document assertGetConfigWorks(final TestingNetconfClient netconfClient, final NetconfMessage getConfigMessage) - throws InterruptedException, ExecutionException, TimeoutException, DocumentedException { - final NetconfMessage rpcReply = netconfClient.sendMessage(getConfigMessage); - assertNotNull(rpcReply); - assertEquals("data", XmlElement.fromDomDocument(rpcReply.getDocument()).getOnlyChildElement().getName()); - return rpcReply.getDocument(); - } - - @Test - public void testGetConfig() throws Exception { - try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) { - assertGetConfigWorks(netconfClient); - } - } - - @Test - public void createYangTestBasedOnYuma() throws Exception { - try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) { - Document rpcReply = netconfClient.sendMessage( - XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/editConfig_merge_yang-test.xml")) - .getDocument(); - assertEquals("rpc-reply", rpcReply.getDocumentElement().getTagName()); - assertIsOK(rpcReply); - assertGetConfigWorks(netconfClient, this.getConfigCandidate); - rpcReply = netconfClient.sendMessage(XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/commit.xml")) - .getDocument(); - assertIsOK(rpcReply); - - final ObjectName on = new ObjectName( - "org.opendaylight.controller:instanceName=impl-dep-instance,type=Module,moduleFactoryName=impl-dep"); - final Set cfgBeans = configRegistryClient.lookupConfigBeans(); - assertEquals(cfgBeans, Sets.newHashSet(on)); - } - } - - private TestingNetconfClient createSession(final InetSocketAddress address, final String expected) throws Exception { - final TestingNetconfClient netconfClient = new TestingNetconfClient("test " + address.toString(), clientDispatcher, getClientConfiguration(address, 5000)); - assertEquals(expected, Long.toString(netconfClient.getSessionId())); - return netconfClient; - } - - @Test - public void testIdRef() throws Exception { - final NetconfMessage editId = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/editConfig_identities.xml"); - final NetconfMessage commit = XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/commit.xml"); - - try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) { - assertIsOK(netconfClient.sendMessage(editId).getDocument()); - assertIsOK(netconfClient.sendMessage(commit).getDocument()); - - final NetconfMessage response = netconfClient.sendMessage(getGetConfig()); - - assertThat(XmlUtil.toString(response.getDocument()), containsString("prefix:test-identity1")); - assertThat(XmlUtil.toString(response.getDocument()), containsString("prefix:test-identity2")); - assertThat(XmlUtil.toString(response.getDocument()), containsString("prefix:test-identity2")); - assertThat(XmlUtil.toString(response.getDocument()), containsString("prefix:test-identity1")); - - } catch (final Exception e) { - fail(Throwables.getStackTraceAsString(e)); - } - } - - @Override - protected BindingRuntimeContext getBindingRuntimeContext() { - final BindingRuntimeContext ret = super.getBindingRuntimeContext(); - doReturn(TestIdentity1.class).when(ret).getIdentityClass(TestIdentity1.QNAME); - doReturn(TestIdentity2.class).when(ret).getIdentityClass(TestIdentity2.QNAME); - return ret; - } - - @Test - public void testMultipleDependencies() throws Exception { - // push first xml, should add parent and d1,d2 dependencies - try (TestingNetconfClient netconfClient = createSession(TCP_ADDRESS, "1")) { - final Document rpcReply = netconfClient.sendMessage( - XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/editConfig_merge_multiple-deps1.xml")) - .getDocument(); - assertIsOK(rpcReply); - commit(netconfClient); - } - // verify that parent.getTestingDeps == d1,d2 - final MultipleDependenciesModuleMXBean parentProxy = configRegistryClient.newMXBeanProxy( - configRegistryClient.lookupConfigBean(MultipleDependenciesModuleFactory.NAME, "parent"), - MultipleDependenciesModuleMXBean.class); - { - final List testingDeps = parentProxy.getTestingDeps(); - assertEquals(2, testingDeps.size()); - final Set actualRefs = getServiceReferences(testingDeps); - assertEquals(Sets.newHashSet("ref_d1", "ref_d2"), actualRefs); - } - - // push second xml, should add d3 to parent's dependencies - mergeD3(parentProxy); - // push second xml again, to test that d3 is not added again - mergeD3(parentProxy); - } - - public void mergeD3(final MultipleDependenciesModuleMXBean parentProxy) throws Exception { - try (TestingNetconfClient netconfClient = new TestingNetconfClient( - "test " + TCP_ADDRESS.toString(), clientDispatcher, getClientConfiguration(TCP_ADDRESS, 5000))) { - - final Document rpcReply = netconfClient.sendMessage( - XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/editConfig_merge_multiple-deps2.xml")) - .getDocument(); - assertIsOK(rpcReply); - commit(netconfClient); - } - { - final List testingDeps = parentProxy.getTestingDeps(); - assertEquals(3, testingDeps.size()); - final Set actualRefs = getServiceReferences(testingDeps); - assertEquals(Sets.newHashSet("ref_d1", "ref_d2", "ref_d3"), actualRefs); - } - } - - public Set getServiceReferences(final List testingDeps) { - return new HashSet<>(Lists.transform(testingDeps, ObjectNameUtil::getReferenceName)); - } - - public void commit(final TestingNetconfClient netconfClient) throws Exception { - final Document rpcReply; - rpcReply = netconfClient.sendMessage(XmlFileLoader.xmlFileToNetconfMessage("netconfMessages/commit.xml")) - .getDocument(); - assertIsOK(rpcReply); - } -} diff --git a/netconf/netconf-it/src/test/resources/logback-test.xml b/netconf/netconf-it/src/test/resources/logback-test.xml deleted file mode 100644 index e9ee13d8b6..0000000000 --- a/netconf/netconf-it/src/test/resources/logback-test.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - %date{"yyyy-MM-dd HH:mm:ss.SSS z"} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - - - - diff --git a/netconf/netconf-it/src/test/resources/netconfMessages/editConfig_identities.xml b/netconf/netconf-it/src/test/resources/netconfMessages/editConfig_identities.xml deleted file mode 100644 index cf9f3e5ccd..0000000000 --- a/netconf/netconf-it/src/test/resources/netconfMessages/editConfig_identities.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - set - - merge - - - - - test-impl:impl-identity-test - - id-test - - prefix:test-identity1 - prefix:test-identity2 - - - prefix:test-identity2 - prefix:test-identity1 - - - prefix:test-identity2 - - prefix:test-identity1 - - - - - - - - - -- 2.36.6