From 98504df45f32dc385bbabadd08082f1c7e848f2b Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 1 Jan 2023 17:05:41 +0100 Subject: [PATCH] Move NetconfDeviceTopologyAdapter NetconfDeviceTopologyAdapter is updating the datastore view of the device, and as such is tied to the fact that this is network topology. Move the class out, opting to specialize NetconfDeviceSalFacade instead. JIRA: NETCONF-918 Change-Id: I24115bee0f97852d4c4cfa09152fdeeab2395965 Signed-off-by: Robert Varga --- .../singleton/impl/MasterSalFacade.java | 14 +++-- netconf/netconf-topology/pom.xml | 13 +++++ .../topology/spi/AbstractNetconfTopology.java | 5 +- .../spi}/NetconfDeviceTopologyAdapter.java | 4 +- .../spi/NetconfTopologyDeviceSalFacade.java | 56 +++++++++++++++++++ ...fDeficeTopologyAdapterIntegrationTest.java | 2 +- .../NetconfDeviceTopologyAdapterTest.java | 2 +- netconf/sal-netconf-connector/pom.xml | 12 ---- .../netconf/sal/NetconfDeviceSalFacade.java | 17 +++--- .../netconf/sal/NetconfDeviceSalProvider.java | 27 +-------- .../sal/NetconfDeviceSalFacadeTest.java | 38 ------------- .../sal/NetconfDeviceSalProviderTest.java | 31 +--------- 12 files changed, 95 insertions(+), 126 deletions(-) rename netconf/{sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal => netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi}/NetconfDeviceTopologyAdapter.java (98%) create mode 100644 netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/NetconfTopologyDeviceSalFacade.java rename netconf/{sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal => netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi}/NetconfDeficeTopologyAdapterIntegrationTest.java (98%) rename netconf/{sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal => netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi}/NetconfDeviceTopologyAdapterTest.java (98%) diff --git a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/MasterSalFacade.java b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/MasterSalFacade.java index e747f2a8f1..c3e801a785 100644 --- a/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/MasterSalFacade.java +++ b/netconf/netconf-topology-singleton/src/main/java/org/opendaylight/netconf/topology/singleton/impl/MasterSalFacade.java @@ -31,6 +31,7 @@ import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceDataBroker; import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalProvider; import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; import org.opendaylight.netconf.topology.singleton.messages.CreateInitialMasterActorData; +import org.opendaylight.netconf.topology.spi.NetconfDeviceTopologyAdapter; import org.opendaylight.yangtools.rfc8528.data.api.MountPointContext; import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier; import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; @@ -46,6 +47,7 @@ class MasterSalFacade implements RemoteDeviceHandler, AutoCloseable { private final NetconfDeviceSalProvider salProvider; private final ActorRef masterActorRef; private final ActorSystem actorSystem; + private final NetconfDeviceTopologyAdapter datastoreAdapter; private final boolean lockDatastore; private NetconfDeviceSchema currentSchema = null; @@ -62,11 +64,13 @@ class MasterSalFacade implements RemoteDeviceHandler, AutoCloseable { final DataBroker dataBroker, final boolean lockDatastore) { this.id = id; - salProvider = new NetconfDeviceSalProvider(id, mountService, dataBroker); + salProvider = new NetconfDeviceSalProvider(id, mountService); this.actorSystem = actorSystem; this.masterActorRef = masterActorRef; this.actorResponseWaitTime = actorResponseWaitTime; this.lockDatastore = lockDatastore; + + datastoreAdapter = new NetconfDeviceTopologyAdapter(dataBroker, id); } @Override @@ -100,13 +104,13 @@ class MasterSalFacade implements RemoteDeviceHandler, AutoCloseable { @Override public void onDeviceDisconnected() { LOG.info("Device {} disconnected - unregistering master mount point", id); - salProvider.getTopologyDatastoreAdapter().updateDeviceData(false, NetconfDeviceCapabilities.empty()); + datastoreAdapter.updateDeviceData(false, NetconfDeviceCapabilities.empty()); unregisterMasterMountPoint(); } @Override public void onDeviceFailed(final Throwable throwable) { - salProvider.getTopologyDatastoreAdapter().setDeviceAsFailed(throwable); + datastoreAdapter.setDeviceAsFailed(throwable); unregisterMasterMountPoint(); } @@ -117,6 +121,7 @@ class MasterSalFacade implements RemoteDeviceHandler, AutoCloseable { @Override public void close() { + datastoreAdapter.close(); unregisterMasterMountPoint(); closeGracefully(salProvider); } @@ -168,8 +173,7 @@ class MasterSalFacade implements RemoteDeviceHandler, AutoCloseable { private void updateDeviceData() { final String masterAddress = Cluster.get(actorSystem).selfAddress().toString(); LOG.debug("{}: updateDeviceData with master address {}", id, masterAddress); - salProvider.getTopologyDatastoreAdapter().updateClusteredDeviceData(true, masterAddress, - currentSchema.capabilities()); + datastoreAdapter.updateClusteredDeviceData(true, masterAddress, currentSchema.capabilities()); } private void unregisterMasterMountPoint() { diff --git a/netconf/netconf-topology/pom.xml b/netconf/netconf-topology/pom.xml index c227c32466..f731127404 100644 --- a/netconf/netconf-topology/pom.xml +++ b/netconf/netconf-topology/pom.xml @@ -27,5 +27,18 @@ org.opendaylight.netconf sal-netconf-connector + + + org.awaitility + awaitility + + + org.opendaylight.mdsal + mdsal-binding-test-utils + + + org.opendaylight.netconf + netconf-test-models + diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/AbstractNetconfTopology.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/AbstractNetconfTopology.java index 039f222693..7d929ed7ad 100644 --- a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/AbstractNetconfTopology.java +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/AbstractNetconfTopology.java @@ -49,7 +49,6 @@ import org.opendaylight.netconf.sal.connect.netconf.SchemalessNetconfDevice; import org.opendaylight.netconf.sal.connect.netconf.auth.DatastoreBackedPublicKeyAuth; import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator; import org.opendaylight.netconf.sal.connect.netconf.sal.KeepaliveSalFacade; -import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalFacade; import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfKeystoreAdapter; import org.opendaylight.netconf.sal.connect.netconf.schema.YangLibrarySchemaYangSourceProvider; import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseNetconfSchemas; @@ -216,8 +215,8 @@ public abstract class AbstractNetconfTopology implements NetconfTopology { final var deviceId = NetconfNodeUtils.toRemoteDeviceId(nodeId, node); final long keepaliveDelay = node.requireKeepaliveDelay().toJava(); - final var deviceSalFacade = new NetconfDeviceSalFacade(deviceId, mountPointService, dataBroker, - node.requireLockDatastore()); + final var deviceSalFacade = new NetconfTopologyDeviceSalFacade(deviceId, mountPointService, + node.requireLockDatastore(), dataBroker); // The facade we are going it present to NetconfDevice RemoteDeviceHandler salFacade; final KeepaliveSalFacade keepAliveFacade; diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceTopologyAdapter.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/NetconfDeviceTopologyAdapter.java similarity index 98% rename from netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceTopologyAdapter.java rename to netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/NetconfDeviceTopologyAdapter.java index 9d7e3f3861..bfc124fab2 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceTopologyAdapter.java +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/NetconfDeviceTopologyAdapter.java @@ -5,7 +5,7 @@ * 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.sal.connect.netconf.sal; +package org.opendaylight.netconf.topology.spi; import static java.util.Objects.requireNonNull; @@ -50,7 +50,7 @@ public final class NetconfDeviceTopologyAdapter implements TransactionChainListe private TransactionChain txChain; - NetconfDeviceTopologyAdapter(final DataBroker dataBroker, final RemoteDeviceId id) { + public NetconfDeviceTopologyAdapter(final DataBroker dataBroker, final RemoteDeviceId id) { this.dataBroker = requireNonNull(dataBroker); this.id = requireNonNull(id); txChain = dataBroker.createMergingTransactionChain(this); diff --git a/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/NetconfTopologyDeviceSalFacade.java b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/NetconfTopologyDeviceSalFacade.java new file mode 100644 index 0000000000..fbaa8ac14a --- /dev/null +++ b/netconf/netconf-topology/src/main/java/org/opendaylight/netconf/topology/spi/NetconfTopologyDeviceSalFacade.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023 PANTHEON.tech, s.r.o. 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.topology.spi; + +import org.opendaylight.mdsal.binding.api.DataBroker; +import org.opendaylight.mdsal.dom.api.DOMMountPointService; +import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices; +import org.opendaylight.netconf.sal.connect.netconf.NetconfDeviceSchema; +import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities; +import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences; +import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalFacade; +import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; + +/** + * {@link NetconfDeviceSalFacade} specialization for netconf topology. + */ +public class NetconfTopologyDeviceSalFacade extends NetconfDeviceSalFacade { + private final NetconfDeviceTopologyAdapter datastoreAdapter; + + public NetconfTopologyDeviceSalFacade(final RemoteDeviceId id, final DOMMountPointService mountPointService, + final boolean lockDatastore, final DataBroker dataBroker) { + super(id, mountPointService, lockDatastore); + datastoreAdapter = new NetconfDeviceTopologyAdapter(dataBroker, id); + } + + @Override + public synchronized void onDeviceConnected(final NetconfDeviceSchema deviceSchema, + final NetconfSessionPreferences sessionPreferences, final RemoteDeviceServices services) { + super.onDeviceConnected(deviceSchema, sessionPreferences, services); + datastoreAdapter.updateDeviceData(true, deviceSchema.capabilities()); + + } + + @Override + public synchronized void onDeviceDisconnected() { + datastoreAdapter.updateDeviceData(false, NetconfDeviceCapabilities.empty()); + super.onDeviceDisconnected(); + } + + @Override + public synchronized void onDeviceFailed(final Throwable throwable) { + datastoreAdapter.setDeviceAsFailed(throwable); + super.onDeviceFailed(throwable); + } + + @Override + public void close() { + datastoreAdapter.close(); + super.close(); + } +} diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeficeTopologyAdapterIntegrationTest.java b/netconf/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfDeficeTopologyAdapterIntegrationTest.java similarity index 98% rename from netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeficeTopologyAdapterIntegrationTest.java rename to netconf/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfDeficeTopologyAdapterIntegrationTest.java index 709beabfd9..db98f76f57 100644 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeficeTopologyAdapterIntegrationTest.java +++ b/netconf/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfDeficeTopologyAdapterIntegrationTest.java @@ -5,7 +5,7 @@ * 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.sal.connect.netconf.sal; +package org.opendaylight.netconf.topology.spi; import static org.junit.Assert.assertEquals; diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceTopologyAdapterTest.java b/netconf/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfDeviceTopologyAdapterTest.java similarity index 98% rename from netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceTopologyAdapterTest.java rename to netconf/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfDeviceTopologyAdapterTest.java index e3281fb490..804b4df563 100644 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceTopologyAdapterTest.java +++ b/netconf/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfDeviceTopologyAdapterTest.java @@ -5,7 +5,7 @@ * 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.sal.connect.netconf.sal; +package org.opendaylight.netconf.topology.spi; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; diff --git a/netconf/sal-netconf-connector/pom.xml b/netconf/sal-netconf-connector/pom.xml index d1caf19e66..6955e0be3c 100644 --- a/netconf/sal-netconf-connector/pom.xml +++ b/netconf/sal-netconf-connector/pom.xml @@ -129,26 +129,14 @@ test-jar test - - org.opendaylight.mdsal - mdsal-binding-test-utils - com.google.code.gson gson - - org.awaitility - awaitility - org.opendaylight.yangtools yang-test-util - - org.opendaylight.netconf - netconf-test-models - diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacade.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacade.java index a5dd2231a2..d2fa6e573d 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacade.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacade.java @@ -7,20 +7,20 @@ */ package org.opendaylight.netconf.sal.connect.netconf.sal; +import static java.util.Objects.requireNonNull; + import com.google.common.annotations.VisibleForTesting; -import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.mdsal.dom.api.DOMMountPointService; import org.opendaylight.mdsal.dom.api.DOMNotification; import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler; import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices; import org.opendaylight.netconf.sal.connect.netconf.NetconfDeviceSchema; -import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities; import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences; import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public final class NetconfDeviceSalFacade implements RemoteDeviceHandler, AutoCloseable { +public class NetconfDeviceSalFacade implements RemoteDeviceHandler, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceSalFacade.class); private final RemoteDeviceId id; @@ -28,15 +28,15 @@ public final class NetconfDeviceSalFacade implements RemoteDeviceHandler, AutoCl private final boolean lockDatastore; public NetconfDeviceSalFacade(final RemoteDeviceId id, final DOMMountPointService mountPointService, - final DataBroker dataBroker, final boolean lockDatastore) { - this(id, new NetconfDeviceSalProvider(id, mountPointService, dataBroker), lockDatastore); + final boolean lockDatastore) { + this(id, new NetconfDeviceSalProvider(id, mountPointService), lockDatastore); } @VisibleForTesting NetconfDeviceSalFacade(final RemoteDeviceId id, final NetconfDeviceSalProvider salProvider, final boolean lockDatastore) { - this.id = id; - this.salProvider = salProvider; + this.id = requireNonNull(id); + this.salProvider = requireNonNull(salProvider); this.lockDatastore = lockDatastore; } @@ -60,18 +60,15 @@ public final class NetconfDeviceSalFacade implements RemoteDeviceHandler, AutoCl salProvider.getMountInstance().onTopologyDeviceConnected(modelContext, services, netconfDataBroker, netconfDataTree); - salProvider.getTopologyDatastoreAdapter().updateDeviceData(true, deviceSchema.capabilities()); } @Override public synchronized void onDeviceDisconnected() { - salProvider.getTopologyDatastoreAdapter().updateDeviceData(false, NetconfDeviceCapabilities.empty()); salProvider.getMountInstance().onTopologyDeviceDisconnected(); } @Override public synchronized void onDeviceFailed(final Throwable throwable) { - salProvider.getTopologyDatastoreAdapter().setDeviceAsFailed(throwable); salProvider.getMountInstance().onTopologyDeviceDisconnected(); } diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java index 12aac10510..ff4af4649e 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProvider.java @@ -11,7 +11,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static java.util.Objects.requireNonNull; -import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.mdsal.dom.api.DOMActionService; import org.opendaylight.mdsal.dom.api.DOMDataBroker; import org.opendaylight.mdsal.dom.api.DOMMountPoint; @@ -33,26 +32,17 @@ import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +// FIXME: remove this class and promote MountInstance to a top-level construct +// Non-final for mocking public class NetconfDeviceSalProvider implements AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceSalProvider.class); private final RemoteDeviceId id; private final MountInstance mountInstance; - private volatile NetconfDeviceTopologyAdapter topologyDatastoreAdapter; - public NetconfDeviceSalProvider(final RemoteDeviceId deviceId, final DOMMountPointService mountService) { - this(deviceId, mountService, null); - } - - // FIXME: NETCONF-918: remove this method - public NetconfDeviceSalProvider(final RemoteDeviceId deviceId, final DOMMountPointService mountService, - final DataBroker dataBroker) { - id = deviceId; + id = requireNonNull(deviceId); mountInstance = new MountInstance(mountService, id); - if (dataBroker != null) { - topologyDatastoreAdapter = new NetconfDeviceTopologyAdapter(dataBroker, id); - } } public MountInstance getMountInstance() { @@ -61,20 +51,9 @@ public class NetconfDeviceSalProvider implements AutoCloseable { return mountInstance; } - public NetconfDeviceTopologyAdapter getTopologyDatastoreAdapter() { - final NetconfDeviceTopologyAdapter local = topologyDatastoreAdapter; - checkState(local != null, - "%s: Sal provider %s was not initialized by sal. Cannot get topology datastore adapter", id, this); - return local; - } - @Override public void close() { mountInstance.close(); - if (topologyDatastoreAdapter != null) { - topologyDatastoreAdapter.close(); - topologyDatastoreAdapter = null; - } } public static class MountInstance implements AutoCloseable { diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacadeTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacadeTest.java index 91cb8a7f61..dee82a8e69 100644 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacadeTest.java +++ b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalFacadeTest.java @@ -5,10 +5,8 @@ * 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.sal.connect.netconf.sal; -import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doNothing; @@ -22,15 +20,8 @@ import java.util.List; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.opendaylight.mdsal.binding.api.DataBroker; -import org.opendaylight.mdsal.binding.api.TransactionChain; -import org.opendaylight.mdsal.binding.api.WriteTransaction; -import org.opendaylight.mdsal.common.api.CommitInfo; -import org.opendaylight.mdsal.common.api.LogicalDatastoreType; import org.opendaylight.mdsal.dom.api.DOMDataBroker; import org.opendaylight.mdsal.dom.api.DOMNotification; import org.opendaylight.netconf.dom.api.NetconfDataTreeService; @@ -41,8 +32,6 @@ import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabi import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences; import org.opendaylight.netconf.sal.connect.netconf.util.NetconfMessageTransformUtil; import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev221225.ConnectionOper.ConnectionStatus; -import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNode; import org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext; import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; @@ -54,31 +43,13 @@ public class NetconfDeviceSalFacadeTest { private NetconfDeviceSalProvider.MountInstance mountInstance; @Mock private NetconfDeviceSalProvider salProvider; - @Mock - private DataBroker dataBroker; - @Mock - private TransactionChain txChain; - @Mock - private WriteTransaction tx; - @Captor - private ArgumentCaptor nodeCaptor; private NetconfDeviceSalFacade deviceFacade; @Before public void setUp() throws Exception { - doReturn(txChain).when(dataBroker).createMergingTransactionChain(any()); - doReturn(tx).when(txChain).newWriteOnlyTransaction(); - doNothing().when(tx).mergeParentStructurePut(eq(LogicalDatastoreType.OPERATIONAL), - eq(remoteDeviceId.getTopologyBindingPath().augmentation(NetconfNode.class)), nodeCaptor.capture()); - doReturn(CommitInfo.emptyFluentFuture()).when(tx).commit(); - - final NetconfDeviceTopologyAdapter adapter = new NetconfDeviceTopologyAdapter(dataBroker, remoteDeviceId); - deviceFacade = new NetconfDeviceSalFacade(remoteDeviceId, salProvider, true); - doReturn(adapter).when(salProvider).getTopologyDatastoreAdapter(); - doReturn(mountInstance).when(salProvider).getMountInstance(); doNothing().when(mountInstance).onTopologyDeviceDisconnected(); } @@ -87,7 +58,6 @@ public class NetconfDeviceSalFacadeTest { public void testOnDeviceDisconnected() { deviceFacade.onDeviceDisconnected(); - verifyConnectionStatusUpdate(ConnectionStatus.Connecting); verify(mountInstance, times(1)).onTopologyDeviceDisconnected(); } @@ -96,7 +66,6 @@ public class NetconfDeviceSalFacadeTest { final Throwable throwable = new Throwable(); deviceFacade.onDeviceFailed(throwable); - verifyConnectionStatusUpdate(ConnectionStatus.UnableToConnect); verify(mountInstance, times(1)).onTopologyDeviceDisconnected(); } @@ -118,7 +87,6 @@ public class NetconfDeviceSalFacadeTest { new NetconfDeviceSchema(NetconfDeviceCapabilities.empty(), new EmptyMountPointContext(schemaContext)), netconfSessionPreferences, deviceServices); - verifyConnectionStatusUpdate(ConnectionStatus.Connected); verify(mountInstance, times(1)).onTopologyDeviceConnected(eq(schemaContext), eq(deviceServices), any(DOMDataBroker.class), any(NetconfDataTreeService.class)); } @@ -129,10 +97,4 @@ public class NetconfDeviceSalFacadeTest { deviceFacade.onNotification(domNotification); verify(mountInstance).publish(domNotification); } - - private void verifyConnectionStatusUpdate(final ConnectionStatus expectedStatus) { - verify(tx).mergeParentStructurePut(eq(LogicalDatastoreType.OPERATIONAL), - eq(remoteDeviceId.getTopologyBindingPath().augmentation(NetconfNode.class)), any()); - assertEquals(expectedStatus, nodeCaptor.getValue().getConnectionStatus()); - } } diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProviderTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProviderTest.java index 8b1e7cc104..d7095c8055 100644 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProviderTest.java +++ b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/sal/NetconfDeviceSalProviderTest.java @@ -7,60 +7,31 @@ */ package org.opendaylight.netconf.sal.connect.netconf.sal; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.verify; - import java.net.InetSocketAddress; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.opendaylight.mdsal.binding.api.DataBroker; -import org.opendaylight.mdsal.binding.api.TransactionChain; -import org.opendaylight.mdsal.binding.api.TransactionChainListener; -import org.opendaylight.mdsal.binding.api.WriteTransaction; -import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.mdsal.dom.api.DOMMountPointService; import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId; @RunWith(MockitoJUnitRunner.StrictStubs.class) public class NetconfDeviceSalProviderTest { - @Mock - private WriteTransaction tx; - @Mock - private DataBroker dataBroker; - @Mock - private TransactionChain chain; @Mock private DOMMountPointService mountPointService; - @Mock - private WriteTransaction writeTx; - @Captor - private ArgumentCaptor listeners; private NetconfDeviceSalProvider provider; @Before public void setUp() { - doReturn(chain).when(dataBroker).createMergingTransactionChain(listeners.capture()); - doReturn(writeTx).when(chain).newWriteOnlyTransaction(); - doReturn("Some object").when(writeTx).getIdentifier(); - doReturn(CommitInfo.emptyFluentFuture()).when(writeTx).commit(); provider = new NetconfDeviceSalProvider(new RemoteDeviceId("device1", - InetSocketAddress.createUnresolved("localhost", 17830)), mountPointService, dataBroker); - doReturn(tx).when(chain).newWriteOnlyTransaction(); - doReturn(CommitInfo.emptyFluentFuture()).when(tx).commit(); - doReturn(tx).when(tx).getIdentifier(); + InetSocketAddress.createUnresolved("localhost", 17830)), mountPointService); } @Test public void close() { - listeners.getValue().onTransactionChainSuccessful(chain); provider.close(); - verify(chain).close(); } @Test -- 2.36.6