X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-it%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fit%2FAbstractNetconfConfigTest.java;h=1e31782bb22c87fe1c151e49fa22be9bd0344b60;hb=1a43f55c49d91816751cec1825c40d0a90f8bd8b;hp=a724d1d9c5e4e8b6cec46cdb94f98a7158c48407;hpb=d70f418d19fa09b1efc8fa4ce4ed35f0cf59b73b;p=controller.git diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/AbstractNetconfConfigTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/AbstractNetconfConfigTest.java index a724d1d9c5..1e31782bb2 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/AbstractNetconfConfigTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/AbstractNetconfConfigTest.java @@ -13,9 +13,8 @@ import static org.mockito.Matchers.any; import static org.mockito.Matchers.anySetOf; 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.io.ByteStreams; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.EventLoopGroup; @@ -34,7 +33,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; -import org.apache.commons.io.IOUtils; +import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; import org.opendaylight.controller.config.manager.impl.AbstractConfigTest; @@ -46,28 +45,28 @@ import org.opendaylight.controller.config.yang.test.impl.MultipleDependenciesMod import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleFactory; import org.opendaylight.controller.config.yang.test.impl.TestImplModuleFactory; import org.opendaylight.controller.netconf.api.NetconfMessage; +import org.opendaylight.controller.netconf.api.monitoring.NetconfMonitoringService; import org.opendaylight.controller.netconf.client.NetconfClientDispatcherImpl; import org.opendaylight.controller.netconf.client.SimpleNetconfClientSessionListener; import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration; import org.opendaylight.controller.netconf.client.conf.NetconfClientConfigurationBuilder; +import org.opendaylight.controller.netconf.confignetconfconnector.osgi.EnumResolver; import org.opendaylight.controller.netconf.confignetconfconnector.osgi.NetconfOperationServiceFactoryImpl; -import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreException; import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreService; -import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreServiceImpl; -import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreSnapshot; import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer; -import org.opendaylight.controller.netconf.impl.NetconfServerDispatcher; +import org.opendaylight.controller.netconf.impl.NetconfServerDispatcherImpl; import org.opendaylight.controller.netconf.impl.NetconfServerSessionNegotiatorFactory; import org.opendaylight.controller.netconf.impl.SessionIdProvider; +import org.opendaylight.controller.netconf.impl.osgi.AggregatedNetconfOperationServiceFactory; import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl; -import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl; -import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshotImpl; -import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationProvider; -import org.opendaylight.controller.netconf.mapping.api.NetconfOperationService; import org.opendaylight.controller.netconf.mapping.api.NetconfOperationServiceFactory; +import org.opendaylight.controller.netconf.monitoring.osgi.NetconfMonitoringActivator; +import org.opendaylight.controller.netconf.monitoring.osgi.NetconfMonitoringOperationService; +import org.opendaylight.controller.netconf.notifications.BaseNetconfNotificationListener; import org.opendaylight.controller.netconf.util.test.XmlFileLoader; import org.opendaylight.protocol.framework.NeverReconnectStrategy; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.NetconfCapabilityChange; +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.parser.impl.YangParserImpl; @@ -77,6 +76,7 @@ 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(), @@ -107,14 +107,16 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest { setUpTestInitial(); - final NetconfOperationServiceFactoryListenerImpl factoriesListener = new NetconfOperationServiceFactoryListenerImpl(); + final AggregatedNetconfOperationServiceFactory factoriesListener = new AggregatedNetconfOperationServiceFactory(); + final NetconfMonitoringService netconfMonitoringService = getNetconfMonitoringService(factoriesListener); factoriesListener.onAddNetconfOperationServiceFactory(new NetconfOperationServiceFactoryImpl(getYangStore())); + factoriesListener.onAddNetconfOperationServiceFactory(new NetconfMonitoringActivator.NetconfMonitoringOperationServiceFactory(new NetconfMonitoringOperationService(netconfMonitoringService))); - for (final NetconfOperationServiceFactory netconfOperationServiceFactory : getAdditionalServiceFactories()) { + for (final NetconfOperationServiceFactory netconfOperationServiceFactory : getAdditionalServiceFactories(factoriesListener)) { factoriesListener.onAddNetconfOperationServiceFactory(netconfOperationServiceFactory); } - serverTcpChannel = startNetconfTcpServer(factoriesListener); + serverTcpChannel = startNetconfTcpServer(factoriesListener, netconfMonitoringService); clientDispatcher = new NetconfClientDispatcherImpl(getNettyThreadgroup(), getNettyThreadgroup(), getHashedWheelTimer()); } @@ -136,8 +138,8 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest { return get; } - private Channel startNetconfTcpServer(final NetconfOperationServiceFactoryListenerImpl factoriesListener) throws Exception { - final NetconfServerDispatcher dispatch = createDispatcher(factoriesListener, getNetconfMonitoringService(), getNotificationProducer()); + private Channel startNetconfTcpServer(final AggregatedNetconfOperationServiceFactory listener, final NetconfMonitoringService monitoring) throws Exception { + final NetconfServerDispatcherImpl dispatch = createDispatcher(listener, monitoring, getNotificationProducer()); final ChannelFuture s; if(getTcpServerAddress() instanceof LocalAddress) { @@ -145,7 +147,7 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest { } else { s = dispatch.createServer(((InetSocketAddress) getTcpServerAddress())); } - s.await(); + s.await(RESOURCE_TIMEOUT_MINUTES, TimeUnit.MINUTES); return s.channel(); } @@ -156,16 +158,12 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest { return notificationProducer; } - protected Iterable getAdditionalServiceFactories() { + protected Iterable getAdditionalServiceFactories(final AggregatedNetconfOperationServiceFactory factoriesListener) throws Exception { return Collections.emptySet(); } - protected SessionMonitoringService getNetconfMonitoringService() throws Exception { - final NetconfOperationProvider netconfOperationProvider = mock(NetconfOperationProvider.class); - final NetconfOperationServiceSnapshotImpl snap = mock(NetconfOperationServiceSnapshotImpl.class); - doReturn(Collections.emptySet()).when(snap).getServices(); - doReturn(snap).when(netconfOperationProvider).openSnapshot(anyString()); - return new NetconfMonitoringServiceImpl(netconfOperationProvider); + protected NetconfMonitoringService getNetconfMonitoringService(final AggregatedNetconfOperationServiceFactory factoriesListener) throws Exception { + return new NetconfMonitoringServiceImpl(factoriesListener); } protected abstract SocketAddress getTcpServerAddress(); @@ -174,7 +172,7 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest { return clientDispatcher; } - private HardcodedYangStoreService getYangStore() throws YangStoreException, IOException { + private HardcodedYangStoreService getYangStore() throws IOException { final Collection yangDependencies = getBasicYangs(); return new HardcodedYangStoreService(yangDependencies); } @@ -187,6 +185,7 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest { "/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.yang"); final Collection yangDependencies = new ArrayList<>(); @@ -203,17 +202,17 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest { return yangDependencies; } - protected NetconfServerDispatcher createDispatcher( - final NetconfOperationServiceFactoryListenerImpl factoriesListener, final SessionMonitoringService sessionMonitoringService, + protected NetconfServerDispatcherImpl createDispatcher( + final AggregatedNetconfOperationServiceFactory factoriesListener, final NetconfMonitoringService sessionMonitoringService, final DefaultCommitNotificationProducer commitNotifier) { final SessionIdProvider idProvider = new SessionIdProvider(); final NetconfServerSessionNegotiatorFactory serverNegotiatorFactory = new NetconfServerSessionNegotiatorFactory( hashedWheelTimer, factoriesListener, idProvider, SERVER_CONNECTION_TIMEOUT_MILLIS, commitNotifier, sessionMonitoringService); - final NetconfServerDispatcher.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcher.ServerChannelInitializer( + final NetconfServerDispatcherImpl.ServerChannelInitializer serverChannelInitializer = new NetconfServerDispatcherImpl.ServerChannelInitializer( serverNegotiatorFactory); - return new NetconfServerDispatcher(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup); + return new NetconfServerDispatcherImpl(serverChannelInitializer, nettyThreadgroup, nettyThreadgroup); } protected HashedWheelTimer getHashedWheelTimer() { @@ -229,9 +228,9 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest { */ @After public void cleanUpNetconf() throws Exception { - serverTcpChannel.close().await(); + serverTcpChannel.close().await(RESOURCE_TIMEOUT_MINUTES, TimeUnit.MINUTES); hashedWheelTimer.stop(); - nettyThreadgroup.shutdownGracefully().await(); + nettyThreadgroup.shutdownGracefully().await(RESOURCE_TIMEOUT_MINUTES, TimeUnit.MINUTES); } public NetconfClientConfiguration getClientConfiguration(final InetSocketAddress tcpAddress, final int timeout) { @@ -243,22 +242,35 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest { return b.build(); } - public static final class HardcodedYangStoreService implements YangStoreService { - - private final List byteArrayInputStreams; + public static final class HardcodedYangStoreService extends YangStoreService { + public HardcodedYangStoreService(final Collection inputStreams) throws IOException { + super(new SchemaContextProvider() { + @Override + public SchemaContext getSchemaContext() { + return getSchema(inputStreams); + } + }, new BaseNetconfNotificationListener() { + @Override + public void onCapabilityChanged(final NetconfCapabilityChange capabilityChange) { + // NOOP + } + }); + } - public HardcodedYangStoreService(final Collection inputStreams) throws YangStoreException, IOException { - byteArrayInputStreams = new ArrayList<>(); + private static SchemaContext getSchema(final Collection inputStreams) { + final ArrayList byteArrayInputStreams = new ArrayList<>(); for (final InputStream inputStream : inputStreams) { assertNotNull(inputStream); - final byte[] content = IOUtils.toByteArray(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); } - } - @Override - public YangStoreSnapshot getYangStoreSnapshot() throws YangStoreException { for (final InputStream inputStream : byteArrayInputStreams) { try { inputStream.reset(); @@ -268,14 +280,22 @@ public abstract class AbstractNetconfConfigTest extends AbstractConfigTest { } final YangParserImpl yangParser = new YangParserImpl(); - final SchemaContext schemaContext = yangParser.resolveSchemaContext(new HashSet<>(yangParser.parseYangModelsFromStreamsMapped(byteArrayInputStreams).values())); - final YangStoreServiceImpl yangStoreService = new YangStoreServiceImpl(new SchemaContextProvider() { + return yangParser.resolveSchemaContext(new HashSet<>(yangParser.parseYangModelsFromStreamsMapped(byteArrayInputStreams).values())); + } + + @Override + public EnumResolver getEnumResolver() { + return new EnumResolver() { @Override - public SchemaContext getSchemaContext() { - return schemaContext ; + public String fromYang(final String enumType, final String enumYangValue) { + return BindingMapping.getClassName(enumYangValue); } - }); - return yangStoreService.getYangStoreSnapshot(); + + @Override + public String toYang(final String enumType, final String enumJavaValue) { + return enumJavaValue.toLowerCase(); + } + }; } } }