From f5cb57931b95ea20af945fe81a770e3f3b01c222 Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Thu, 29 Jun 2017 07:48:52 -0400 Subject: [PATCH] Bug 8725: Remove netconf device mounting via the config system Change-Id: Ida7a236f0bd75978e07a64b38497ccf8aa75fea8 Signed-off-by: Tom Pantelis --- netconf/netconf-client/pom.xml | 6 +- .../src/main/yang/odl-netconf-cfg.yang | 35 --- netconf/netconf-topology-singleton/pom.xml | 4 + netconf/sal-netconf-connector/pom.xml | 60 +---- .../netconf/NetconfConnectorModule.java | 215 ---------------- .../NetconfConnectorModuleFactory.java | 34 --- .../yang/odl-sal-netconf-connector-cfg.yang | 239 ------------------ .../netconf/NetconfConnectorModuleTest.java | 122 --------- 8 files changed, 17 insertions(+), 698 deletions(-) delete mode 100644 netconf/netconf-client/src/main/yang/odl-netconf-cfg.yang delete mode 100644 netconf/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java delete mode 100644 netconf/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModuleFactory.java delete mode 100644 netconf/sal-netconf-connector/src/main/yang/odl-sal-netconf-connector-cfg.yang delete mode 100644 netconf/sal-netconf-connector/src/test/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModuleTest.java diff --git a/netconf/netconf-client/pom.xml b/netconf/netconf-client/pom.xml index 072eeac5b6..7de7fbf6de 100644 --- a/netconf/netconf-client/pom.xml +++ b/netconf/netconf-client/pom.xml @@ -10,9 +10,9 @@ 4.0.0 - org.opendaylight.controller - config-parent - 0.7.0-SNAPSHOT + org.opendaylight.odlparent + bundle-parent + 2.0.0 diff --git a/netconf/netconf-client/src/main/yang/odl-netconf-cfg.yang b/netconf/netconf-client/src/main/yang/odl-netconf-cfg.yang deleted file mode 100644 index 21e62422bc..0000000000 --- a/netconf/netconf-client/src/main/yang/odl-netconf-cfg.yang +++ /dev/null @@ -1,35 +0,0 @@ -// vi: set smarttab et sw=4 tabstop=4: -module odl-netconf-cfg { - - yang-version 1; - namespace "urn:opendaylight:params:xml:ns:yang:controller:config:netconf"; - prefix "cfg-net"; - - import config { prefix config; revision-date 2013-04-05; } - - description - "This module contains the base YANG definitions for - netconf related services. - - Copyright (c)2013 Cisco Systems, Inc. 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"; - - revision "2014-04-08" { - description - "Initial revision."; - } - - // We keep this as sal-netconf-connector and netconf-topology need it. - // Once they will be moved to blueprint, it will be safe to delete all - // together the netconf-config-dispatcher bundle. - identity netconf-client-dispatcher { - base "config:service-type"; - config:java-class "org.opendaylight.netconf.client.NetconfClientDispatcher"; - config:disable-osgi-service-registration; - status deprecated; - } -} \ No newline at end of file diff --git a/netconf/netconf-topology-singleton/pom.xml b/netconf/netconf-topology-singleton/pom.xml index d0397d8463..4014443859 100644 --- a/netconf/netconf-topology-singleton/pom.xml +++ b/netconf/netconf-topology-singleton/pom.xml @@ -65,6 +65,10 @@ org.opendaylight.controller sal-clustering-commons + + org.opendaylight.controller + threadpool-config-api + org.opendaylight.mdsal mdsal-singleton-common-api diff --git a/netconf/sal-netconf-connector/pom.xml b/netconf/sal-netconf-connector/pom.xml index fb52fbb0c2..87e88e669f 100644 --- a/netconf/sal-netconf-connector/pom.xml +++ b/netconf/sal-netconf-connector/pom.xml @@ -9,9 +9,9 @@ 4.0.0 - org.opendaylight.controller - config-parent - 0.7.0-SNAPSHOT + org.opendaylight.mdsal + binding-parent + 0.11.0-SNAPSHOT @@ -24,6 +24,13 @@ + + org.opendaylight.controller + mdsal-artifacts + 1.6.0-SNAPSHOT + pom + import + org.opendaylight.netconf netconf-artifacts @@ -63,14 +70,6 @@ ${project.groupId} netconf-notifications-api - - org.opendaylight.controller - netty-config-api - - - org.opendaylight.controller - netty-threadgroup-config - org.opendaylight.controller sal-binding-api @@ -83,10 +82,6 @@ org.opendaylight.controller sal-binding-config - - org.opendaylight.controller - threadpool-config-api - org.opendaylight.controller.model model-inventory @@ -135,36 +130,11 @@ xmlunit xmlunit - - org.opendaylight.controller - config-api - provided - - - org.opendaylight.controller - config-manager - test - - - org.opendaylight.controller - config-manager - test-jar - test - ${project.groupId} config-netconf-connector test - - org.opendaylight.controller - config-persister-impl - test - - - org.opendaylight.controller - config-util - ${project.groupId} netconf-impl @@ -181,16 +151,6 @@ test-jar test - - org.opendaylight.controller - yang-test - test - - - org.opendaylight.controller - logback-config - test - org.opendaylight.controller sal-binding-broker-impl diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java deleted file mode 100644 index 34f2cbed1f..0000000000 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModule.java +++ /dev/null @@ -1,215 +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.controller.config.yang.md.sal.connector.netconf; - -import static org.opendaylight.controller.config.api.JmxAttributeValidationException.checkCondition; -import static org.opendaylight.controller.config.api.JmxAttributeValidationException.checkNotNull; - -import com.google.common.util.concurrent.CheckedFuture; -import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; -import javax.annotation.Nullable; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.NonModuleCapabilities; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.NonModuleCapabilitiesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.YangModuleCapabilities; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.parameters.YangModuleCapabilitiesBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.Credentials; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.schema.storage.YangLibrary; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.schema.storage.YangLibraryBuilder; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Instead of using loopback (controller-config mount point) to create your netconf-connector, - * you should use the network-topology capability. - * - *

- * Follow instructions provided in this - * wiki. - * - *

- * Deprecation notice in Carbon, removal planned for Nitrogen. - */ -@Deprecated -public final class NetconfConnectorModule - extends org.opendaylight.controller.config.yang.md.sal.connector.netconf.AbstractNetconfConnectorModule - implements BindingAwareConsumer { - private static final Logger LOG = LoggerFactory.getLogger(NetconfConnectorModule.class); - - private static final InstanceIdentifier TOPOLOGY_PATH = InstanceIdentifier.create(NetworkTopology.class) - .child(Topology.class, new TopologyKey(new TopologyId("topology-netconf"))); - private final String instanceName; - private InstanceIdentifier nodePath; - private DataBroker dataBroker; - - public NetconfConnectorModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, - final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { - super(identifier, dependencyResolver); - instanceName = identifier.getInstanceName(); - } - - public NetconfConnectorModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, - final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, - final NetconfConnectorModule oldModule, final java.lang.AutoCloseable oldInstance) { - super(identifier, dependencyResolver, oldModule, oldInstance); - instanceName = identifier.getInstanceName(); - } - - @Override - protected void customValidation() { - checkNotNull(getAddress(), addressJmxAttribute); - checkCondition(isHostAddressPresent(getAddress()), "Host address not present in " + getAddress(), - addressJmxAttribute); - checkNotNull(getPort(), portJmxAttribute); - - checkNotNull(getConnectionTimeoutMillis(), connectionTimeoutMillisJmxAttribute); - checkCondition(getConnectionTimeoutMillis() > 0, "must be > 0", connectionTimeoutMillisJmxAttribute); - - checkNotNull(getDefaultRequestTimeoutMillis(), defaultRequestTimeoutMillisJmxAttribute); - checkCondition(getDefaultRequestTimeoutMillis() > 0, "must be > 0", defaultRequestTimeoutMillisJmxAttribute); - - checkNotNull(getBetweenAttemptsTimeoutMillis(), betweenAttemptsTimeoutMillisJmxAttribute); - checkCondition(getBetweenAttemptsTimeoutMillis() > 0, "must be > 0", betweenAttemptsTimeoutMillisJmxAttribute); - - // Check username + password in case of ssh - if (!getTcpOnly()) { - checkNotNull(getUsername(), usernameJmxAttribute); - checkNotNull(getPassword(), passwordJmxAttribute); - } - } - - private static boolean isHostAddressPresent(final Host address) { - return address.getDomainName() != null || address.getIpAddress() != null - && (address.getIpAddress().getIpv4Address() != null || address.getIpAddress().getIpv6Address() != null); - } - - @Override - public java.lang.AutoCloseable createInstance() { - getBindingRegistryDependency().registerConsumer(this); - return this::deleteNode; - } - - @Override - public void onSessionInitialized(final BindingAwareBroker.ConsumerContext session) { - dataBroker = session.getSALService(DataBroker.class); - final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); - final NodeId nodeId = new NodeId(instanceName); - final NodeKey nodeKey = new NodeKey(nodeId); - final Node node = createNetconfNode(nodeId, nodeKey); - nodePath = TOPOLOGY_PATH.child(Node.class, nodeKey); - transaction.put(LogicalDatastoreType.CONFIGURATION, nodePath, node); - final CheckedFuture submitFuture = transaction.submit(); - Futures.addCallback(submitFuture, new FutureCallback() { - @Override - public void onSuccess(@Nullable final Void result) { - LOG.debug("Node {} was successfully added to the topology", instanceName); - } - - @Override - public void onFailure(final Throwable throwable) { - LOG.error("Node {} creation failed: {}", instanceName, throwable); - } - }); - } - - private void deleteNode() { - if (dataBroker != null) { - final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); - transaction.delete(LogicalDatastoreType.CONFIGURATION, nodePath); - final CheckedFuture submitFuture = transaction.submit(); - Futures.addCallback(submitFuture, new FutureCallback() { - @Override - public void onSuccess(@Nullable final Void result) { - LOG.debug("Node {} was successfully deleted from the topology", instanceName); - } - - @Override - public void onFailure(final Throwable throwable) { - LOG.error("Node {} deletion failed: {}", instanceName, throwable); - } - }); - - } - } - - private Node createNetconfNode(final NodeId nodeId, final NodeKey nodeKey) { - final Credentials credentials = new LoginPasswordBuilder() - .setUsername(getUsername()) - .setPassword(getPassword()) - .build(); - - YangModuleCapabilities moduleCapabilities = null; - if (getYangModuleCapabilities() != null) { - moduleCapabilities = new YangModuleCapabilitiesBuilder() - .setOverride(getYangModuleCapabilities().getOverride()) - .setCapability(getYangModuleCapabilities().getCapability()) - .build(); - } - - NonModuleCapabilities nonModuleCapabilities = null; - if (getNonModuleCapabilities() != null) { - nonModuleCapabilities = new NonModuleCapabilitiesBuilder() - .setOverride(getNonModuleCapabilities().getOverride()) - .setCapability(getNonModuleCapabilities().getCapability()) - .build(); - } - - final YangLibrary yangLibrary; - if (getYangLibrary() != null) { - yangLibrary = new YangLibraryBuilder() - .setYangLibraryUrl(getYangLibrary().getYangLibraryUrl()) - .setUsername(getYangLibrary().getUsername()) - .setPassword(getYangLibrary().getPassword()) - .build(); - } else { - yangLibrary = null; - } - final NetconfNode netconfNode = new NetconfNodeBuilder() - .setHost(getAddress()) - .setPort(getPort()) - .setCredentials(credentials) - .setConnectionTimeoutMillis(getConnectionTimeoutMillis()) - .setDefaultRequestTimeoutMillis(getDefaultRequestTimeoutMillis()) - .setBetweenAttemptsTimeoutMillis(getBetweenAttemptsTimeoutMillis()) - .setConcurrentRpcLimit(getConcurrentRpcLimit()) - .setKeepaliveDelay(getKeepaliveDelay()) - .setMaxConnectionAttempts(getMaxConnectionAttempts()) - .setReconnectOnChangedSchema(getReconnectOnChangedSchema()) - .setSchemaCacheDirectory(getSchemaCacheDirectory()) - .setSleepFactor(getSleepFactor()) - .setTcpOnly(getTcpOnly()) - .setYangModuleCapabilities(moduleCapabilities) - .setNonModuleCapabilities(nonModuleCapabilities) - .setYangLibrary(yangLibrary) - .build(); - return new NodeBuilder() - .setNodeId(nodeId) - .setKey(nodeKey) - .addAugmentation(NetconfNode.class, netconfNode) - .build(); - } -} diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModuleFactory.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModuleFactory.java deleted file mode 100644 index 0e5bb46b6b..0000000000 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModuleFactory.java +++ /dev/null @@ -1,34 +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.controller.config.yang.md.sal.connector.netconf; - -import org.opendaylight.controller.config.api.DependencyResolver; -import org.opendaylight.controller.config.api.DynamicMBeanWithInstance; -import org.opendaylight.controller.config.spi.Module; -import org.osgi.framework.BundleContext; - -@Deprecated -public class NetconfConnectorModuleFactory extends - org.opendaylight.controller.config.yang.md.sal.connector.netconf.AbstractNetconfConnectorModuleFactory { - - @Override - public Module createModule(final String instanceName, final DependencyResolver dependencyResolver, - final DynamicMBeanWithInstance old, final BundleContext bundleContext) throws Exception { - final NetconfConnectorModule module = - (NetconfConnectorModule) super.createModule(instanceName, dependencyResolver, old, bundleContext); - return module; - } - - @Override - public Module createModule(final String instanceName, final DependencyResolver dependencyResolver, - final BundleContext bundleContext) { - final NetconfConnectorModule module = - (NetconfConnectorModule) super.createModule(instanceName, dependencyResolver, bundleContext); - return module; - } -} diff --git a/netconf/sal-netconf-connector/src/main/yang/odl-sal-netconf-connector-cfg.yang b/netconf/sal-netconf-connector/src/main/yang/odl-sal-netconf-connector-cfg.yang deleted file mode 100644 index ec5f31c101..0000000000 --- a/netconf/sal-netconf-connector/src/main/yang/odl-sal-netconf-connector-cfg.yang +++ /dev/null @@ -1,239 +0,0 @@ -module odl-sal-netconf-connector-cfg { - yang-version 1; - namespace "urn:opendaylight:params:xml:ns:yang:controller:md:sal:connector:netconf"; - prefix "sal-netconf"; - - import config { prefix config; revision-date 2013-04-05; } - import threadpool {prefix th;} - import netty {prefix netty;} - import opendaylight-md-sal-dom {prefix dom;} - import opendaylight-md-sal-binding {prefix md-sal-binding; revision-date 2013-10-28;} - import odl-netconf-cfg { prefix cfg-net; revision-date 2014-04-08; } - import ietf-inet-types {prefix inet; revision-date "2013-07-15";} - - description - "Config definition for Netconf Connector modules"; - - revision "2015-08-03" { - description - "Non-mandatory keepalive executor"; - } - - revision "2013-10-28" { - description - "Initial revision"; - } - - identity sal-netconf-connector { - base config:module-type; - config:java-name-prefix NetconfConnector; - status deprecated; - } - - grouping server { - leaf address { - type string; - } - - leaf port { - type uint32; - } - } - - augment "/config:modules/config:module/config:configuration" { - status deprecated; - case sal-netconf-connector { - when "/config:modules/config:module/config:type = 'sal-netconf-connector'"; - - leaf address { - type inet:host; - } - - leaf port { - type inet:port-number; - } - - leaf tcp-only { - type boolean; - } - - leaf username { - type string; - } - - leaf password { - type string; - } - - leaf concurrent-rpc-limit { - type uint16; - default 0; - description "Limit of concurrent messages that can be send before reply messages are received. - If value less than 1 is provided, no limit will be enforced"; - } - - leaf schema-cache-directory { - type string; - default "schema"; - description "The destination schema repository for yang files relative to the cache directory. This may be specified per netconf mount - so that the loaded yang files are stored to a distinct directory to avoid potential conflict."; - } - - container yang-module-capabilities { - leaf override { - type boolean; - default false; - description "Whether to override or merge this list of capabilities with capabilities from device"; - } - - leaf-list capability { - type string; - description "Set a list of capabilities to override capabilities provided in device's hello message. - Can be used for devices that do not report any yang modules in their hello message"; - } - } - - container non-module-capabilities { - leaf override { - type boolean; - default false; - description "Whether to override or merge this list of non-module based capabilities with non-module - based capabilities from device"; - } - - leaf-list capability { - type string; - description "Set a list of non-module based capabilities to override or merge non-module capabilities - provided in device's hello message. Can be used for devices that do not report or - incorrectly report non-module based capabilities in their hello message"; - } - } - - leaf reconnect-on-changed-schema { - type boolean; - default false; - description "If true, the connector would auto disconnect/reconnect when schemas are changed in the remote device. - The connector subscribes (right after connect) to base netconf notifications and listens for netconf-capability-change notification"; - } - - container dom-registry { - uses config:service-ref { - refine type { - mandatory false; - config:required-identity dom:dom-broker-osgi-registry; - } - } - } - - container binding-registry { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity md-sal-binding:binding-broker-osgi-registry; - } - } - } - - container event-executor { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity netty:netty-event-executor; - } - } - } - - container processing-executor { - uses config:service-ref { - refine type { - mandatory true; - config:required-identity th:threadpool; - } - } - - description "Makes up for flaws in netty threading design"; - } - - container client-dispatcher { - uses config:service-ref { - refine type { - mandatory false; - config:required-identity cfg-net:netconf-client-dispatcher; - } - } - } - - leaf connection-timeout-millis { - description "Specifies timeout in milliseconds after which connection must be established."; - type uint32; - default 20000; - } - - leaf default-request-timeout-millis { - description "Timeout for blocking operations within transactions."; - type uint32; - default 60000; - } - - leaf max-connection-attempts { - description "Maximum number of connection retries. Non positive value or null is interpreted as infinity."; - type uint32; - default 0; // retry forever - } - - leaf between-attempts-timeout-millis { - description "Initial timeout in milliseconds to wait between connection attempts. Will be multiplied by sleep-factor with every additional attempt"; - type uint16; - default 2000; - } - - leaf sleep-factor { - type decimal64 { - fraction-digits 1; - } - default 1.5; - } - - // Keepalive configuration - leaf keepalive-delay { - type uint32; - default 120; - description "Netconf connector sends keepalive RPCs while the session is idle, this delay specifies the delay between keepalive RPC in seconds - If a value less than 1 is provided, no keepalives will be sent"; - } - - container keepalive-executor { - uses config:service-ref { - refine type { - mandatory false; - config:required-identity th:scheduled-threadpool; - } - refine name { - mandatory false; - } - } - - description "Dedicated solely to keepalive execution"; - } - - container yang-library { - leaf yang-library-url { - config true; - type inet:uri; - description "Yang library to be plugged as additional source provider into the shared schema repository"; - } - - // credentials for basic http authentication for get request for yanglib data - leaf username { - config true; - type string; - } - - leaf password { - config true; - type string; - } - } - } - } -} diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModuleTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModuleTest.java deleted file mode 100644 index 9e918b6d57..0000000000 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/controller/config/yang/md/sal/connector/netconf/NetconfConnectorModuleTest.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright (c) 2016 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.controller.config.yang.md.sal.connector.netconf; - -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import com.google.common.util.concurrent.Futures; -import java.lang.reflect.Field; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.config.api.DependencyResolver; -import org.opendaylight.controller.config.api.ModuleIdentifier; -import org.opendaylight.controller.md.sal.binding.api.DataBroker; -import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; -import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.DomainName; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPassword; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.credentials.credentials.LoginPasswordBuilder; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; -import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier; - -public class NetconfConnectorModuleTest { - - private static final String MODULE_NAME = "module-name"; - private static final Host HOST = new Host(new DomainName("localhost")); - private static final PortNumber PORT = new PortNumber(17830); - private static final Boolean TCP_ONLY = Boolean.FALSE; - private static final LoginPassword LOGIN_PASSWORD = new LoginPasswordBuilder() - .setUsername("admin") - .setPassword("admin") - .build(); - @Mock - private DependencyResolver resolver; - @Mock - private BindingAwareBroker bindingRegistry; - @Mock - private BindingAwareBroker.ConsumerContext session; - @Mock - private DataBroker dataBroker; - @Mock - private WriteTransaction transaction; - private NetconfConnectorModule module; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - module = new NetconfConnectorModule(new ModuleIdentifier("factory", MODULE_NAME), resolver); - setViaReflection(module, "bindingRegistryDependency", bindingRegistry); - setViaReflection(module, "address", HOST); - setViaReflection(module, "port", PORT); - setViaReflection(module, "tcpOnly", TCP_ONLY); - setViaReflection(module, "username", LOGIN_PASSWORD.getUsername()); - setViaReflection(module, "password", LOGIN_PASSWORD.getPassword()); - doReturn(dataBroker).when(session).getSALService(DataBroker.class); - doReturn(transaction).when(dataBroker).newWriteOnlyTransaction(); - doReturn(Futures.immediateCheckedFuture(null)).when(transaction).submit(); - module.customValidation(); - } - - @Test - public void onSessionInitialized() throws Exception { - final AutoCloseable instance = module.createInstance(); - verify(bindingRegistry).registerConsumer(module); - final NodeId nodeId = new NodeId(MODULE_NAME); - final KeyedInstanceIdentifier id = InstanceIdentifier.create(NetworkTopology.class) - .child(Topology.class, new TopologyKey(new TopologyId("topology-netconf"))) - .child(Node.class, new NodeKey(nodeId)); - //when session is initialized, topology node should be created - module.onSessionInitialized(session); - final ArgumentCaptor createdNodeCaptor = ArgumentCaptor.forClass(Node.class); - verify(transaction).put(eq(LogicalDatastoreType.CONFIGURATION), eq(id), createdNodeCaptor.capture()); - verifyNode(nodeId, createdNodeCaptor.getValue()); - //node should be deleted on close - instance.close(); - verify(transaction).delete(LogicalDatastoreType.CONFIGURATION, id); - verify(transaction, times(2)).submit(); - } - - private static void verifyNode(final NodeId nodeId, final Node node) { - Assert.assertEquals(nodeId, node.getNodeId()); - final NetconfNode netconfNode = node.getAugmentation(NetconfNode.class); - Assert.assertEquals(HOST, netconfNode.getHost()); - Assert.assertEquals(PORT, netconfNode.getPort()); - Assert.assertEquals(LOGIN_PASSWORD, netconfNode.getCredentials()); - Assert.assertEquals(TCP_ONLY, netconfNode.isTcpOnly()); - } - - private static void setViaReflection(final Object object, final String fieldName, final Object value) { - try { - final Field field = AbstractNetconfConnectorModule.class.getDeclaredField(fieldName); - field.setAccessible(true); - field.set(object, value); - } catch (NoSuchFieldException | IllegalAccessException e) { - Assert.fail("Failed to set field via reflection: " + fieldName); - } - } - -} \ No newline at end of file -- 2.36.6