2 * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.sal.connect.netconf.sal;
10 import static org.junit.Assert.assertEquals;
12 import java.net.InetSocketAddress;
13 import java.util.Optional;
14 import java.util.concurrent.TimeUnit;
15 import org.awaitility.Awaitility;
16 import org.junit.AfterClass;
17 import org.junit.Before;
18 import org.junit.BeforeClass;
19 import org.junit.Test;
20 import org.opendaylight.mdsal.binding.api.DataBroker;
21 import org.opendaylight.mdsal.binding.dom.adapter.test.ConcurrentDataBrokerTestCustomizer;
22 import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeContext;
23 import org.opendaylight.mdsal.binding.runtime.spi.BindingRuntimeHelpers;
24 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
25 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
26 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
27 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCapabilities;
28 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus;
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.augment.test.rev160808.Node1;
32 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
33 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
34 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyBuilder;
35 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
36 import org.opendaylight.yangtools.yang.common.QName;
37 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
38 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
39 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
41 // FIXME: base on AbstractDataBrokerTest test?
42 public class NetconfDeficeTopologyAdapterIntegrationTest {
43 private static final RemoteDeviceId ID = new RemoteDeviceId("test", new InetSocketAddress("localhost", 22));
45 private static BindingRuntimeContext RUNTIME_CONTEXT;
47 private DataBroker dataBroker;
48 private DOMDataBroker domDataBroker;
50 private NetconfDeviceTopologyAdapter adapter;
53 public static void beforeClass() {
54 RUNTIME_CONTEXT = BindingRuntimeHelpers.createRuntimeContext(NetconfNode.class, Node1.class);
58 public static void afterClass() {
59 RUNTIME_CONTEXT = null;
63 public void setUp() throws Exception {
64 final var customizer = new ConcurrentDataBrokerTestCustomizer(true);
65 domDataBroker = customizer.getDOMDataBroker();
66 dataBroker = customizer.createDataBroker();
67 customizer.updateSchema(RUNTIME_CONTEXT);
69 final var tx = dataBroker.newWriteOnlyTransaction();
70 tx.put(LogicalDatastoreType.OPERATIONAL, RemoteDeviceId.DEFAULT_TOPOLOGY_IID, new TopologyBuilder()
71 .withKey(RemoteDeviceId.DEFAULT_TOPOLOGY_IID.getKey())
73 tx.commit().get(2, TimeUnit.SECONDS);
75 adapter = new NetconfDeviceTopologyAdapter(dataBroker, ID);
79 public void testFailedDeviceIntegration() {
80 adapter.setDeviceAsFailed(null);
82 Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> dataBroker.newReadWriteTransaction()
83 .read(LogicalDatastoreType.OPERATIONAL, ID.getTopologyBindingPath().augmentation(NetconfNode.class))
84 .get(5, TimeUnit.SECONDS)
85 .map(NetconfNodeConnectionStatus::getConnectionStatus)
86 .filter(status -> status == NetconfNodeConnectionStatus.ConnectionStatus.UnableToConnect)
91 public void testDeviceAugmentedNodePresence() throws Exception {
92 QName netconfTestLeafQname = QName.create(
93 "urn:TBD:params:xml:ns:yang:network-topology-augment-test", "2016-08-08", "test-id").intern();
95 YangInstanceIdentifier pathToAugmentedLeaf = YangInstanceIdentifier.builder().node(NetworkTopology.QNAME)
97 .nodeWithKey(Topology.QNAME, QName.create(Topology.QNAME, "topology-id"), "topology-netconf")
99 .nodeWithKey(Node.QNAME, QName.create(Node.QNAME, "node-id"), "test")
100 .node(netconfTestLeafQname).build();
102 final Integer dataTestId = 474747;
103 final var augmentNode = ImmutableNodes.leafNode(netconfTestLeafQname, dataTestId);
105 DOMDataTreeWriteTransaction wtx = domDataBroker.newWriteOnlyTransaction();
106 wtx.put(LogicalDatastoreType.OPERATIONAL, pathToAugmentedLeaf, augmentNode);
107 wtx.commit().get(5, TimeUnit.SECONDS);
109 adapter.updateDeviceData(true, new NetconfDeviceCapabilities());
111 assertEquals(Optional.of(dataTestId), domDataBroker.newReadOnlyTransaction()
112 .read(LogicalDatastoreType.OPERATIONAL, pathToAugmentedLeaf)
113 .get(2, TimeUnit.SECONDS)
114 .map(NormalizedNode::body));
116 adapter.setDeviceAsFailed(null);
118 assertEquals(Optional.of(dataTestId), domDataBroker.newReadOnlyTransaction()
119 .read(LogicalDatastoreType.OPERATIONAL, pathToAugmentedLeaf)
120 .get(2, TimeUnit.SECONDS)
121 .map(NormalizedNode::body));