import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
import org.opendaylight.netconf.sal.connect.netconf.sal.AbstractNetconfDataTreeService;
import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceDataBroker;
-import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalProvider;
+import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceMount;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.netconf.topology.singleton.messages.CreateInitialMasterActorData;
import org.opendaylight.netconf.topology.spi.NetconfDeviceTopologyAdapter;
private final RemoteDeviceId id;
private final Timeout actorResponseWaitTime;
- private final NetconfDeviceSalProvider salProvider;
private final ActorRef masterActorRef;
private final ActorSystem actorSystem;
private final NetconfDeviceTopologyAdapter datastoreAdapter;
+ private final NetconfDeviceMount mount;
private final boolean lockDatastore;
private NetconfDeviceSchema currentSchema = null;
final DataBroker dataBroker,
final boolean lockDatastore) {
this.id = id;
- salProvider = new NetconfDeviceSalProvider(id, mountService);
+ mount = new NetconfDeviceMount(mountService, id);
this.actorSystem = actorSystem;
this.masterActorRef = masterActorRef;
this.actorResponseWaitTime = actorResponseWaitTime;
public void onDeviceDisconnected() {
LOG.info("Device {} disconnected - unregistering master mount point", id);
datastoreAdapter.updateDeviceData(false, NetconfDeviceCapabilities.empty());
- unregisterMasterMountPoint();
+ mount.onDeviceDisconnected();
}
@Override
public void onDeviceFailed(final Throwable throwable) {
datastoreAdapter.setDeviceAsFailed(throwable);
- unregisterMasterMountPoint();
+ mount.onDeviceDisconnected();
}
@Override
public void onNotification(final DOMNotification domNotification) {
- salProvider.getMountInstance().publish(domNotification);
+ mount.publish(domNotification);
}
@Override
public void close() {
datastoreAdapter.close();
- unregisterMasterMountPoint();
- closeGracefully(salProvider);
+ mount.close();
}
private void registerMasterMountPoint() {
actorResponseWaitTime);
final NetconfDataTreeService proxyNetconfService = new ProxyNetconfDataTreeService(id, masterActorRef,
actorSystem.dispatcher(), actorResponseWaitTime);
- salProvider.getMountInstance().onTopologyDeviceConnected(mountContext.getEffectiveModelContext(),
- deviceServices, proxyDataBroker, proxyNetconfService);
+ mount.onDeviceConnected(mountContext.getEffectiveModelContext(), deviceServices,
+ proxyDataBroker, proxyNetconfService);
}
protected DOMDataBroker newDeviceDataBroker(final MountPointContext mountContext,
LOG.debug("{}: updateDeviceData with master address {}", id, masterAddress);
datastoreAdapter.updateClusteredDeviceData(true, masterAddress, currentSchema.capabilities());
}
-
- private void unregisterMasterMountPoint() {
- salProvider.getMountInstance().onTopologyDeviceDisconnected();
- }
-
- @SuppressWarnings("checkstyle:IllegalCatch")
- private void closeGracefully(final AutoCloseable resource) {
- if (resource != null) {
- try {
- resource.close();
- } catch (final Exception e) {
- LOG.error("{}: Ignoring exception while closing {}", id, resource, e);
- }
- }
- }
}
import akka.util.Timeout;
import java.util.concurrent.atomic.AtomicBoolean;
import org.opendaylight.mdsal.dom.api.DOMMountPointService;
-import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
-import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceSalProvider;
+import org.opendaylight.netconf.sal.connect.netconf.sal.NetconfDeviceMount;
import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SlaveSalFacade {
-
private static final Logger LOG = LoggerFactory.getLogger(SlaveSalFacade.class);
+ private final AtomicBoolean registered = new AtomicBoolean(false);
private final RemoteDeviceId id;
- private final NetconfDeviceSalProvider salProvider;
+ private final NetconfDeviceMount mount;
private final ActorSystem actorSystem;
private final Timeout actorResponseWaitTime;
- private final AtomicBoolean registered = new AtomicBoolean(false);
public SlaveSalFacade(final RemoteDeviceId id,
final ActorSystem actorSystem,
final Timeout actorResponseWaitTime,
final DOMMountPointService mountPointService) {
this.id = id;
- salProvider = new NetconfDeviceSalProvider(id, mountPointService);
this.actorSystem = actorSystem;
this.actorResponseWaitTime = actorResponseWaitTime;
+ mount = new NetconfDeviceMount(mountPointService, id);
}
public void registerSlaveMountPoint(final EffectiveModelContext remoteSchemaContext, final ActorRef masterActorRef,
final RemoteDeviceServices services) {
if (!registered.compareAndSet(false, true)) {
+ LOG.info("Mount point {} already registered, skipping registation", id);
return;
}
- final ProxyDOMDataBroker netconfDeviceDataBroker = new ProxyDOMDataBroker(id, masterActorRef,
+ final var netconfDeviceDataBroker = new ProxyDOMDataBroker(id, masterActorRef,
actorSystem.dispatcher(), actorResponseWaitTime);
- final NetconfDataTreeService proxyNetconfService = new ProxyNetconfDataTreeService(id, masterActorRef,
+ final var proxyNetconfService = new ProxyNetconfDataTreeService(id, masterActorRef,
actorSystem.dispatcher(), actorResponseWaitTime);
- salProvider.getMountInstance().onTopologyDeviceConnected(remoteSchemaContext, services, netconfDeviceDataBroker,
- proxyNetconfService);
-
+ mount.onDeviceConnected(remoteSchemaContext, services, netconfDeviceDataBroker, proxyNetconfService);
LOG.info("{}: Slave mount point registered.", id);
}
public void close() {
- if (!registered.compareAndSet(true, false)) {
- return;
+ if (registered.compareAndSet(true, false)) {
+ mount.onDeviceDisconnected();
+ LOG.info("{}: Slave mount point unregistered.", id);
}
-
- salProvider.getMountInstance().onTopologyDeviceDisconnected();
-
- LOG.info("{}: Slave mount point unregistered.", id);
}
}
--- /dev/null
+/*
+ * 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.sal.connect.netconf.sal;
+
+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.dom.api.DOMActionService;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
+import org.opendaylight.mdsal.dom.api.DOMNotificationService;
+import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
+import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
+import org.opendaylight.netconf.sal.connect.api.NetconfRpcService;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices.Actions;
+import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices.Rpcs;
+import org.opendaylight.netconf.sal.connect.api.SchemalessRpcService;
+import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+// Non-final for mocking
+public class NetconfDeviceMount implements AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceMount.class);
+
+ private final DOMMountPointService mountService;
+ private final RemoteDeviceId id;
+
+ private NetconfDeviceNotificationService notificationService;
+ private ObjectRegistration<DOMMountPoint> topologyRegistration;
+
+ public NetconfDeviceMount(final DOMMountPointService mountService, final RemoteDeviceId id) {
+ this.mountService = requireNonNull(mountService);
+ this.id = requireNonNull(id);
+ }
+
+ public void onDeviceConnected(final EffectiveModelContext initialCtx,
+ final RemoteDeviceServices services, final DOMDataBroker broker,
+ final NetconfDataTreeService dataTreeService) {
+ onDeviceConnected(initialCtx, services, new NetconfDeviceNotificationService(), broker,
+ dataTreeService);
+ }
+
+ public synchronized void onDeviceConnected(final EffectiveModelContext initialCtx,
+ final RemoteDeviceServices services, final NetconfDeviceNotificationService newNotificationService,
+ final DOMDataBroker broker, final NetconfDataTreeService dataTreeService) {
+ requireNonNull(mountService, "Closed");
+ checkState(topologyRegistration == null, "Already initialized");
+
+ final var mountBuilder = mountService.createMountPoint(id.getTopologyPath());
+ mountBuilder.addService(DOMSchemaService.class, FixedDOMSchemaService.of(() -> initialCtx));
+
+ final var rpcs = services.rpcs();
+ mountBuilder.addService(NetconfRpcService.class, rpcs);
+ if (rpcs instanceof Rpcs.Normalized normalized) {
+ mountBuilder.addService(DOMRpcService.class, normalized);
+ } else if (rpcs instanceof Rpcs.Schemaless schemaless) {
+ mountBuilder.addService(SchemalessRpcService.class, schemaless);
+ }
+ if (services.actions() instanceof Actions.Normalized normalized) {
+ mountBuilder.addService(DOMActionService.class, normalized);
+ }
+
+ if (broker != null) {
+ mountBuilder.addService(DOMDataBroker.class, broker);
+ }
+ if (dataTreeService != null) {
+ mountBuilder.addService(NetconfDataTreeService.class, dataTreeService);
+ }
+ mountBuilder.addService(DOMNotificationService.class, newNotificationService);
+ notificationService = newNotificationService;
+
+ topologyRegistration = mountBuilder.register();
+ LOG.debug("{}: Mountpoint exposed into MD-SAL {}", id, topologyRegistration);
+ }
+
+ public synchronized void onDeviceDisconnected() {
+ if (topologyRegistration == null) {
+ LOG.trace("{}: Not removing mountpoint from MD-SAL, mountpoint was not registered yet", id);
+ return;
+ }
+
+ try {
+ topologyRegistration.close();
+ } finally {
+ LOG.debug("{}: Mountpoint removed from MD-SAL {}", id, topologyRegistration);
+ topologyRegistration = null;
+ }
+ }
+
+ public synchronized void publish(final DOMNotification domNotification) {
+ checkNotNull(notificationService, "Device not set up yet, cannot handle notification %s", domNotification)
+ .publishNotification(domNotification);
+ }
+
+ @Override
+ public synchronized void close() {
+ onDeviceDisconnected();
+ }
+}
\ No newline at end of file
import org.opendaylight.netconf.sal.connect.netconf.NetconfDeviceSchema;
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 class NetconfDeviceSalFacade implements RemoteDeviceHandler, AutoCloseable {
- private static final Logger LOG = LoggerFactory.getLogger(NetconfDeviceSalFacade.class);
-
private final RemoteDeviceId id;
- private final NetconfDeviceSalProvider salProvider;
+ private final NetconfDeviceMount mount;
private final boolean lockDatastore;
public NetconfDeviceSalFacade(final RemoteDeviceId id, final DOMMountPointService mountPointService,
final boolean lockDatastore) {
- this(id, new NetconfDeviceSalProvider(id, mountPointService), lockDatastore);
+ this(id, new NetconfDeviceMount(mountPointService, id), lockDatastore);
}
@VisibleForTesting
- NetconfDeviceSalFacade(final RemoteDeviceId id, final NetconfDeviceSalProvider salProvider,
- final boolean lockDatastore) {
+ NetconfDeviceSalFacade(final RemoteDeviceId id, final NetconfDeviceMount mount, final boolean lockDatastore) {
this.id = requireNonNull(id);
- this.salProvider = requireNonNull(salProvider);
+ this.mount = requireNonNull(mount);
this.lockDatastore = lockDatastore;
}
@Override
public synchronized void onNotification(final DOMNotification domNotification) {
- salProvider.getMountInstance().publish(domNotification);
+ mount.publish(domNotification);
}
@Override
final var netconfDataBroker = new NetconfDeviceDataBroker(id, mountContext, deviceRpc, sessionPreferences,
lockDatastore);
- salProvider.getMountInstance().onTopologyDeviceConnected(modelContext, services, netconfDataBroker,
- netconfDataTree);
+ mount.onDeviceConnected(modelContext, services, netconfDataBroker, netconfDataTree);
}
@Override
public synchronized void onDeviceDisconnected() {
- salProvider.getMountInstance().onTopologyDeviceDisconnected();
+ mount.onDeviceDisconnected();
}
@Override
public synchronized void onDeviceFailed(final Throwable throwable) {
- salProvider.getMountInstance().onTopologyDeviceDisconnected();
+ mount.onDeviceDisconnected();
}
@Override
public synchronized void close() {
- closeGracefully(salProvider);
- }
-
- @SuppressWarnings("checkstyle:IllegalCatch")
- private void closeGracefully(final AutoCloseable resource) {
- if (resource != null) {
- try {
- resource.close();
- } catch (final Exception e) {
- LOG.warn("{}: Ignoring exception while closing {}", id, resource, e);
- }
- }
+ mount.close();
}
}
+++ /dev/null
-/*
- * 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.sal.connect.netconf.sal;
-
-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.dom.api.DOMActionService;
-import org.opendaylight.mdsal.dom.api.DOMDataBroker;
-import org.opendaylight.mdsal.dom.api.DOMMountPoint;
-import org.opendaylight.mdsal.dom.api.DOMMountPointService;
-import org.opendaylight.mdsal.dom.api.DOMNotification;
-import org.opendaylight.mdsal.dom.api.DOMNotificationService;
-import org.opendaylight.mdsal.dom.api.DOMRpcService;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
-import org.opendaylight.netconf.dom.api.NetconfDataTreeService;
-import org.opendaylight.netconf.sal.connect.api.NetconfRpcService;
-import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices;
-import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices.Actions;
-import org.opendaylight.netconf.sal.connect.api.RemoteDeviceServices.Rpcs;
-import org.opendaylight.netconf.sal.connect.api.SchemalessRpcService;
-import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
-import org.opendaylight.yangtools.concepts.ObjectRegistration;
-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;
-
- public NetconfDeviceSalProvider(final RemoteDeviceId deviceId, final DOMMountPointService mountService) {
- id = requireNonNull(deviceId);
- mountInstance = new MountInstance(mountService, id);
- }
-
- public MountInstance getMountInstance() {
- checkState(mountInstance != null, "%s: Mount instance was not initialized by sal. Cannot get mount instance",
- id);
- return mountInstance;
- }
-
- @Override
- public void close() {
- mountInstance.close();
- }
-
- public static class MountInstance implements AutoCloseable {
-
- private final DOMMountPointService mountService;
- private final RemoteDeviceId id;
-
- private NetconfDeviceNotificationService notificationService;
- private ObjectRegistration<DOMMountPoint> topologyRegistration;
-
- MountInstance(final DOMMountPointService mountService, final RemoteDeviceId id) {
- this.mountService = requireNonNull(mountService);
- this.id = requireNonNull(id);
- }
-
- public void onTopologyDeviceConnected(final EffectiveModelContext initialCtx,
- final RemoteDeviceServices services, final DOMDataBroker broker,
- final NetconfDataTreeService dataTreeService) {
- onTopologyDeviceConnected(initialCtx, services, new NetconfDeviceNotificationService(), broker,
- dataTreeService);
- }
-
- public synchronized void onTopologyDeviceConnected(final EffectiveModelContext initialCtx,
- final RemoteDeviceServices services, final NetconfDeviceNotificationService newNotificationService,
- final DOMDataBroker broker, final NetconfDataTreeService dataTreeService) {
- requireNonNull(mountService, "Closed");
- checkState(topologyRegistration == null, "Already initialized");
-
- final var mountBuilder = mountService.createMountPoint(id.getTopologyPath());
- mountBuilder.addService(DOMSchemaService.class, FixedDOMSchemaService.of(() -> initialCtx));
-
- final var rpcs = services.rpcs();
- mountBuilder.addService(NetconfRpcService.class, rpcs);
- if (rpcs instanceof Rpcs.Normalized normalized) {
- mountBuilder.addService(DOMRpcService.class, normalized);
- } else if (rpcs instanceof Rpcs.Schemaless schemaless) {
- mountBuilder.addService(SchemalessRpcService.class, schemaless);
- }
- if (services.actions() instanceof Actions.Normalized normalized) {
- mountBuilder.addService(DOMActionService.class, normalized);
- }
-
- if (broker != null) {
- mountBuilder.addService(DOMDataBroker.class, broker);
- }
- if (dataTreeService != null) {
- mountBuilder.addService(NetconfDataTreeService.class, dataTreeService);
- }
- mountBuilder.addService(DOMNotificationService.class, newNotificationService);
- notificationService = newNotificationService;
-
- topologyRegistration = mountBuilder.register();
- LOG.debug("{}: TOPOLOGY Mountpoint exposed into MD-SAL {}", id, topologyRegistration);
- }
-
- @SuppressWarnings("checkstyle:IllegalCatch")
- public synchronized void onTopologyDeviceDisconnected() {
- if (topologyRegistration == null) {
- LOG.trace("{}: Not removing TOPOLOGY mountpoint from MD-SAL, mountpoint was not registered yet", id);
- return;
- }
-
- try {
- topologyRegistration.close();
- } catch (final Exception e) {
- // Only log and ignore
- LOG.warn("Unable to unregister mount instance for {}. Ignoring exception", id.getTopologyPath(), e);
- } finally {
- LOG.debug("{}: TOPOLOGY Mountpoint removed from MD-SAL {}", id, topologyRegistration);
- topologyRegistration = null;
- }
- }
-
- @Override
- public synchronized void close() {
- onTopologyDeviceDisconnected();
- }
-
- public synchronized void publish(final DOMNotification domNotification) {
- checkNotNull(notificationService, "Device not set up yet, cannot handle notification %s", domNotification)
- .publishNotification(domNotification);
- }
- }
-
-}
@Mock
private DOMNotification notification;
- private NetconfDeviceSalProvider.MountInstance mountInstance;
+ private NetconfDeviceMount mountInstance;
@BeforeClass
public static void suiteSetUp() throws Exception {
when(service.createMountPoint(any(YangInstanceIdentifier.class))).thenReturn(mountPointBuilder);
when(mountPointBuilder.register()).thenReturn(registration);
- mountInstance = new NetconfDeviceSalProvider.MountInstance(
+ mountInstance = new NetconfDeviceMount(
service, new RemoteDeviceId("device-1", InetSocketAddress.createUnresolved("localhost", 17830)));
}
@Test
public void testOnTopologyDeviceConnected() {
- mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
+ mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
notificationService, broker, null);
verify(mountPointBuilder).addService(eq(DOMSchemaService.class), any());
verify(mountPointBuilder).addService(DOMDataBroker.class, broker);
@Test
public void testOnTopologyDeviceConnectedWithNetconfService() {
- mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
+ mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
notificationService, null, netconfService);
verify(mountPointBuilder).addService(eq(DOMSchemaService.class), any());
verify(mountPointBuilder).addService(NetconfDataTreeService.class, netconfService);
@Test
public void testOnTopologyDeviceDisconnected() {
- mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
+ mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
notificationService, broker, null);
- mountInstance.onTopologyDeviceDisconnected();
+ mountInstance.onDeviceDisconnected();
verify(registration).close();
- mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
+ mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
notificationService, broker, null);
}
@Test
public void testClose() {
- mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
+ mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
notificationService, broker, null);
mountInstance.close();
verify(registration).close();
@Test
public void testPublishNotification() {
- mountInstance.onTopologyDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
+ mountInstance.onDeviceConnected(SCHEMA_CONTEXT, new RemoteDeviceServices(rpcService, null),
notificationService, broker, null);
verify(mountPointBuilder).addService(eq(DOMSchemaService.class), any());
verify(mountPointBuilder).addService(DOMNotificationService.class, notificationService);
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
private final RemoteDeviceId remoteDeviceId = new RemoteDeviceId("test", new InetSocketAddress("127.0.0.1", 8000));
@Mock
- private NetconfDeviceSalProvider.MountInstance mountInstance;
- @Mock
- private NetconfDeviceSalProvider salProvider;
+ private NetconfDeviceMount mountInstance;
private NetconfDeviceSalFacade deviceFacade;
@Before
public void setUp() throws Exception {
- deviceFacade = new NetconfDeviceSalFacade(remoteDeviceId, salProvider, true);
+ doNothing().when(mountInstance).onDeviceDisconnected();
- doReturn(mountInstance).when(salProvider).getMountInstance();
- doNothing().when(mountInstance).onTopologyDeviceDisconnected();
+ deviceFacade = new NetconfDeviceSalFacade(remoteDeviceId, mountInstance, true);
}
@Test
public void testOnDeviceDisconnected() {
deviceFacade.onDeviceDisconnected();
- verify(mountInstance, times(1)).onTopologyDeviceDisconnected();
+ verify(mountInstance, times(1)).onDeviceDisconnected();
}
@Test
final Throwable throwable = new Throwable();
deviceFacade.onDeviceFailed(throwable);
- verify(mountInstance, times(1)).onTopologyDeviceDisconnected();
+ verify(mountInstance, times(1)).onDeviceDisconnected();
}
@Test
public void testOnDeviceClose() throws Exception {
deviceFacade.close();
- verify(salProvider).close();
+ verify(mountInstance).close();
}
@Test
new NetconfDeviceSchema(NetconfDeviceCapabilities.empty(), new EmptyMountPointContext(schemaContext)),
netconfSessionPreferences, deviceServices);
- verify(mountInstance, times(1)).onTopologyDeviceConnected(eq(schemaContext), eq(deviceServices),
+ verify(mountInstance, times(1)).onDeviceConnected(eq(schemaContext), eq(deviceServices),
any(DOMDataBroker.class), any(NetconfDataTreeService.class));
}
+++ /dev/null
-/*
- * 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.netconf.sal.connect.netconf.sal;
-
-import java.net.InetSocketAddress;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.mdsal.dom.api.DOMMountPointService;
-import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
-
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class NetconfDeviceSalProviderTest {
- @Mock
- private DOMMountPointService mountPointService;
-
- private NetconfDeviceSalProvider provider;
-
- @Before
- public void setUp() {
- provider = new NetconfDeviceSalProvider(new RemoteDeviceId("device1",
- InetSocketAddress.createUnresolved("localhost", 17830)), mountPointService);
- }
-
- @Test
- public void close() {
- provider.close();
- }
-
- @Test
- public void closeWithoutNPE() {
- close();
-
- // No further interations
- provider.close();
- }
-}