From ea5ba02bdfd1ed6e16683b01f1f499cb2473e37e Mon Sep 17 00:00:00 2001 From: Ravi Pendurty Date: Fri, 20 Oct 2023 14:30:41 +0530 Subject: Support multiple YANG revisions Provide o-ran-supervision messages to VES collector Issue-ID: CCSDK-3948 Change-Id: I16cb880414dde00a48fa59d8b90251beedae2c0e Signed-off-by: Ravi Pendurty --- .../dom/TestORanDOMFaultNotificationListener.java | 36 +++++---- .../oran/impl/dom/TestORanDOMNetworkElement.java | 38 +++++++-- .../oran/impl/dom/TestORanDOMNotification.java | 3 +- .../impl/dom/TestORanDOMToInternalDataModel.java | 91 +++++++++++++++++----- .../impl/dom/TestORanNetworkElementFactory.java | 61 +++++++++++---- .../TestORanRegistrationToVESpnfRegistration.java | 5 +- 6 files changed, 174 insertions(+), 60 deletions(-) (limited to 'sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java') diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMFaultNotificationListener.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMFaultNotificationListener.java index 89ff6dc90..de19bf1a2 100644 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMFaultNotificationListener.java +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMFaultNotificationListener.java @@ -22,6 +22,7 @@ package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.google.common.io.Files; @@ -29,6 +30,7 @@ import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.time.Instant; +import java.util.Optional; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -37,17 +39,22 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.notification.ORanDOMFaultNotificationListener; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.yangspecs.ORANFM; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; import org.onap.ccsdk.features.sdnr.wt.devicemanager.vescollectorconnector.impl.VESCollectorServiceImpl; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities; import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor; import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService; import org.opendaylight.mdsal.dom.api.DOMEvent; import org.opendaylight.mdsal.dom.api.DOMNotification; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; -import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.common.Revision; +import org.opendaylight.yangtools.yang.common.XMLNamespace; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; @@ -89,6 +96,8 @@ public class TestORanDOMFaultNotificationListener { @Mock DataProvider databaseService; VESCollectorService vesCollectorService; + static Optional oranfm; + private Capabilities capabilities; @After @Before @@ -98,6 +107,11 @@ public class TestORanDOMFaultNotificationListener { LOG.info("Remove {}", f.getAbsolutePath()); f.delete(); } + capabilities = mock(Capabilities.class); + when(domAccessor.getCapabilites()).thenReturn(capabilities); + when(capabilities.isSupportingNamespaceAndRevision( + QNameModule.create(XMLNamespace.of(ORANFM.NAMESPACE), Revision.of("2022-08-15")))).thenReturn(true); + oranfm = ORANFM.getModule(domAccessor); } @Test @@ -105,7 +119,7 @@ public class TestORanDOMFaultNotificationListener { Files.asCharSink(new File(TESTFILENAME), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); vesCollectorService = new VESCollectorServiceImpl(new ConfigurationFileRepresentation(TESTFILENAME)); when(domAccessor.getNodeId()).thenReturn(new NodeId("nSky")); - ORanDOMFaultNotificationListener faultListener = new ORanDOMFaultNotificationListener(domAccessor, + ORanDOMFaultNotificationListener faultListener = new ORanDOMFaultNotificationListener(domAccessor, oranfm, vesCollectorService, faultService, websocketManagerService, databaseService); NetconfDeviceNotification ndn = new NetconfDeviceNotification(createORANDOMFault(), Instant.now()); faultListener.onNotification(ndn); @@ -114,20 +128,14 @@ public class TestORanDOMFaultNotificationListener { } public static ContainerNode createORANDOMFault() { - final QName fault_id = QName.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF, "fault-id"); - final QName fault_source = QName.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF, "fault-source"); - final QName fault_severity = QName.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF, "fault-severity"); - final QName is_cleared = QName.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF, "is-cleared"); - final QName fault_text = QName.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF, "fault-text"); - return Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF)) - .withChild(ImmutableNodes.leafNode(fault_id, "47")) - .withChild(ImmutableNodes.leafNode(fault_source, "Slot-2-Port-B")) - .withChild(ImmutableNodes.leafNode(fault_severity, "MAJOR")) - .withChild(ImmutableNodes.leafNode(is_cleared, "true")) - .withChild(ImmutableNodes.leafNode(fault_text, "CPRI Port Down")).build(); + return Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(oranfm.get().getAlarmNotifQName())) + .withChild(ImmutableNodes.leafNode(oranfm.get().getFaultIdQName(), "47")) + .withChild(ImmutableNodes.leafNode(oranfm.get().getFaultSourceQName(), "Slot-2-Port-B")) + .withChild(ImmutableNodes.leafNode(oranfm.get().getFaultSeverityQName(), "MAJOR")) + .withChild(ImmutableNodes.leafNode(oranfm.get().getFaultIsClearedQName(), "true")) + .withChild(ImmutableNodes.leafNode(oranfm.get().getFaultTextQName(), "CPRI Port Down")).build(); } - public static class NetconfDeviceNotification implements DOMNotification, DOMEvent { private final ContainerNode content; private final Absolute schemaPath; diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMNetworkElement.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMNetworkElement.java index 283d122b0..7fd947211 100644 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMNetworkElement.java +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMNetworkElement.java @@ -21,17 +21,25 @@ */ package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import com.google.common.io.Files; +import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Optional; import org.eclipse.jdt.annotation.NonNull; import org.junit.BeforeClass; import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; import org.onap.ccsdk.features.sdnr.wt.devicemanager.ne.service.NetworkElement; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.config.ORanDMConfig; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDeviceManagerQNames; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.yangspecs.ORANFM; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.yangspecs.OnapSystem; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.NotificationProxyParser; @@ -43,12 +51,15 @@ import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccesso import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.common.Revision; +import org.opendaylight.yangtools.yang.common.XMLNamespace; public class TestORanDOMNetworkElement { private static final QName OneCell = QName.create("urn:onf:otcc:wireless:yang:radio-access:commscope-onecell", "2020-06-22", "onecell").intern(); - private static final @NonNull QName OnapSystem = + private static final @NonNull QName OnapSystem1 = QName.create("urn:onap:system", "2020-10-26", "onap-system").intern(); private static String NODEIDSTRING = "nSky"; private static NodeId nodeId = new NodeId(NODEIDSTRING); @@ -61,6 +72,16 @@ public class TestORanDOMNetworkElement { private static NotificationProxyParser notificationProxyParser; private static VESCollectorCfgService vesCfgService; private static WebsocketManagerService websocketManagerService; + private static ORanDMConfig oranDmConfig; + private static ConfigurationFileRepresentation oranCfg; + + private static String fileName = "test1.properties"; + // @formatter:off + private static final String TESTCONFIG_CONTENT = "[ORAN-SUPERVISION]\n" + + "supervision-notification-interval=60\n" + + "guard-timer-overhead=10\n" + + ""; + // @formatter:on @BeforeClass public static void init() throws InterruptedException, IOException { @@ -72,6 +93,7 @@ public class TestORanDOMNetworkElement { notificationProxyParser = mock(NotificationProxyParser.class); vesCfgService = mock(VESCollectorCfgService.class); websocketManagerService = mock(WebsocketManagerService.class); + oranDmConfig = mock(ORanDMConfig.class); when(accessor.getCapabilites()).thenReturn(capabilities); when(accessor.getNodeId()).thenReturn(nodeId); @@ -79,6 +101,10 @@ public class TestORanDOMNetworkElement { when(domAccessor.getNodeId()).thenReturn(nodeId); when(domAccessor.getCapabilites()).thenReturn(capabilities); when(vesCollectorService.getNotificationProxyParser()).thenReturn(notificationProxyParser); + when(capabilities.isSupportingNamespaceAndRevision( + QNameModule.create(XMLNamespace.of(ORANFM.NAMESPACE), Revision.of("2022-08-15")))).thenReturn(true); + when(capabilities.isSupportingNamespaceAndRevision( + QNameModule.create(XMLNamespace.of(OnapSystem.NAMESPACE), Revision.of("2022-11-04")))).thenReturn(true); DataProvider dataProvider = mock(DataProvider.class); FaultService faultService = mock(FaultService.class); @@ -89,6 +115,8 @@ public class TestORanDOMNetworkElement { when(vesCollectorService.getConfig()).thenReturn(vesCfgService); when(vesCfgService.isVESCollectorEnabled()).thenReturn(true); + Files.asCharSink(new File(fileName), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); + oranCfg = new ConfigurationFileRepresentation(fileName); } @Test @@ -96,9 +124,9 @@ public class TestORanDOMNetworkElement { Optional oRanNe; when(capabilities.isSupportingNamespace(ORanDeviceManagerQNames.ORAN_HW_COMPONENT)).thenReturn(true); when(capabilities.isSupportingNamespace(OneCell)).thenReturn(false); - when(capabilities.isSupportingNamespace(OnapSystem)).thenReturn(false); + when(capabilities.isSupportingNamespace(OnapSystem1)).thenReturn(false); - ORanNetworkElementFactory factory = new ORanNetworkElementFactory(); + ORanNetworkElementFactory factory = new ORanNetworkElementFactory(oranCfg, oranDmConfig); oRanNe = factory.create(accessor, serviceProvider); assertTrue(factory.create(accessor, serviceProvider).isPresent()); oRanNe.get().register(); diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMNotification.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMNotification.java index 1665ac1ad..96983b1ba 100644 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMNotification.java +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMNotification.java @@ -29,6 +29,8 @@ import java.time.Instant; import org.junit.BeforeClass; import org.junit.Test; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.notification.ORanDOMChangeNotificationListener; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDeviceManagerQNames; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor; @@ -141,7 +143,6 @@ public class TestORanDOMNotification { @Test public void test() { ContainerNode cn = createDOMNotificationBody(); - System.out.println(cn.toString()); NetconfDeviceNotification ndn = new NetconfDeviceNotification(cn, Instant.now()); ORanDOMChangeNotificationListener changeListener = new ORanDOMChangeNotificationListener(domAccessor, vesCollectorService, databaseService); changeListener.onNotification(ndn); diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMToInternalDataModel.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMToInternalDataModel.java index 5ce758210..01502e49c 100644 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMToInternalDataModel.java +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanDOMToInternalDataModel.java @@ -22,6 +22,8 @@ package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import com.google.common.collect.Sets; import java.io.IOException; import java.io.InputStream; @@ -33,9 +35,13 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.dataprovider.ORanDOMToInternalDataModel; import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom.util.TestYangParserUtil; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.yangspecs.ORANFM; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.yangspecs.OnapSystem; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities; +import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor; import org.opendaylight.mdsal.dom.api.DOMEvent; import org.opendaylight.mdsal.dom.api.DOMNotification; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultlogEntity; @@ -48,10 +54,12 @@ import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.Revision; import org.opendaylight.yangtools.yang.common.XMLNamespace; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode; import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; +import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListEntryNode; +import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode; import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter; import org.opendaylight.yangtools.yang.data.codec.xml.XmlParserStream; import org.opendaylight.yangtools.yang.data.impl.schema.Builders; @@ -73,9 +81,18 @@ public class TestORanDOMToInternalDataModel { QNameModule.create(XMLNamespace.of("urn:ietf:params:xml:ns:yang:ietf-system"), Revision.of("2014-08-06")); private static final QName IETF_CONTAINER = QName.create(IETF_SYSTEM_MODULE, "system"); + private static final QNameModule ORAN_MODULE = + QNameModule.create(XMLNamespace.of("urn:o-ran:fm:1.0"), Revision.of("2022-08-15")); + private static final QName ORAN_ACTIVE_ALARM_CONTAINER = QName.create(ORAN_MODULE, "active-alarm-list"); + private static EffectiveModelContext schemaContext; private static Inference hwContainerSchema; private static Inference systemSchema; + private static Inference activeAlarmSchema; + private static Capabilities capabilities; + private static Optional onapSystem; + private static Optional oranfm; + private static NetconfDomAccessor domAccessor; private static final NodeId nodeId = new NodeId("nSky"); @@ -84,6 +101,18 @@ public class TestORanDOMToInternalDataModel { schemaContext = TestYangParserUtil.parseYangResourceDirectory("/"); hwContainerSchema = Inference.ofDataTreePath(schemaContext, HW_CONTAINER); systemSchema = Inference.ofDataTreePath(schemaContext, IETF_CONTAINER); + activeAlarmSchema = Inference.ofDataTreePath(schemaContext, ORAN_ACTIVE_ALARM_CONTAINER); + + capabilities = mock(Capabilities.class); + domAccessor = mock(NetconfDomAccessor.class); + when(domAccessor.getCapabilites()).thenReturn(capabilities); + when(capabilities.isSupportingNamespaceAndRevision( + QNameModule.create(XMLNamespace.of(OnapSystem.NAMESPACE), Revision.of("2022-11-04")))).thenReturn(true); + onapSystem = OnapSystem.getModule(domAccessor); + when(capabilities.isSupportingNamespaceAndRevision( + QNameModule.create(XMLNamespace.of(ORANFM.NAMESPACE), Revision.of("2022-08-15")))).thenReturn(true); + oranfm = ORANFM.getModule(domAccessor); + } @AfterClass @@ -91,12 +120,14 @@ public class TestORanDOMToInternalDataModel { schemaContext = null; hwContainerSchema = null; systemSchema = null; + activeAlarmSchema = null; } @Test public void testIetfHardwareFromXML() throws XMLStreamException, URISyntaxException, IOException, SAXException { - final InputStream resourceAsStream = TestORanDOMToInternalDataModel.class.getResourceAsStream("/ietf-hardware.xml"); + final InputStream resourceAsStream = + TestORanDOMToInternalDataModel.class.getResourceAsStream("/ietf-hardware.xml"); /* * final XMLInputFactory factory = XMLInputFactory.newInstance(); @@ -121,11 +152,11 @@ public class TestORanDOMToInternalDataModel { inventoryList.stream().filter(inventory -> inventory.getTreeLevel() == null).count()); } - @Ignore //TODO @Test public void testIetfSystemFromXML() throws XMLStreamException, URISyntaxException, IOException, SAXException { - final InputStream resourceAsStream = TestORanDOMToInternalDataModel.class.getResourceAsStream("/onap-system.xml"); + final InputStream resourceAsStream = + TestORanDOMToInternalDataModel.class.getResourceAsStream("/onap-system.xml"); final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream); @@ -140,9 +171,10 @@ public class TestORanDOMToInternalDataModel { NormalizedNode transformedInput = result.getResult(); ContainerNode cn = (ContainerNode) transformedInput; - AugmentationIdentifier onapSystemIID = YangInstanceIdentifier.AugmentationIdentifier.create( - Sets.newHashSet(ORanDeviceManagerQNames.ONAP_SYSTEM_NAME, ORanDeviceManagerQNames.ONAP_SYSTEM_WEB_UI)); - Optional gc = ORanDOMToInternalDataModel.getGuicutthrough(cn.getChildByArg(onapSystemIID)); + AugmentationNode gcData = (AugmentationNode) cn.childByArg( + YangInstanceIdentifier.AugmentationIdentifier.create(Sets.newHashSet(onapSystem.get().getName(), + onapSystem.get().getWebUi(), onapSystem.get().getGeoLocation()))); + Optional gc = ORanDOMToInternalDataModel.getGuicutthrough(gcData, onapSystem.get()); assertEquals(gc.isPresent(), true); } @@ -151,23 +183,40 @@ public class TestORanDOMToInternalDataModel { public void testORANFault() { ContainerNode cn = createORANDOMFault(); NetconfDeviceNotification faultNotif = new NetconfDeviceNotification(cn, Instant.now()); - FaultlogEntity fle = ORanDOMToInternalDataModel.getFaultLog(faultNotif, nodeId, 1); + FaultlogEntity fle = ORanDOMToInternalDataModel.getFaultLog(faultNotif, oranfm.get(), nodeId, 1); assertEquals(fle.getId(), "47"); } + @Test + public void testORANActiveAlarms() throws XMLStreamException, URISyntaxException, IOException, SAXException { + final InputStream resourceAsStream = + TestORanDOMToInternalDataModel.class.getResourceAsStream("/oran-fm-active-alarm.xml"); + + final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream); + final NormalizedNodeResult result = new NormalizedNodeResult(); + final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); + + final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, activeAlarmSchema); + xmlParser.parse(reader); + + xmlParser.flush(); + xmlParser.close(); + NormalizedNode transformedInput = result.getResult(); + ContainerNode cn = (ContainerNode) transformedInput; + + UnkeyedListNode activeAlarmsList = + (UnkeyedListNode) cn.childByArg(new NodeIdentifier(oranfm.get().getFaultActiveAlarmsQName())); + for (UnkeyedListEntryNode activeAlarmEntry : activeAlarmsList.body()) + ORanDOMToInternalDataModel.getFaultLog(activeAlarmEntry, oranfm.get(), new NodeId("nSky"), Integer.valueOf(0)); + } + public static ContainerNode createORANDOMFault() { - final QName fault_id = QName.create(ORanDeviceManagerQNames.ORAN_FM_FAULT_ID, "fault-id"); - final QName fault_source = QName.create(ORanDeviceManagerQNames.ORAN_FM_FAULT_SOURCE, "fault-source"); - final QName fault_severity = QName.create(ORanDeviceManagerQNames.ORAN_FM_FAULT_SEVERITY, "fault-severity"); - final QName is_cleared = QName.create(ORanDeviceManagerQNames.ORAN_FM_FAULT_IS_CLEARED, "is-cleared"); - final QName fault_text = QName.create(ORanDeviceManagerQNames.ORAN_FM_FAULT_TEXT, "fault-text"); - return Builders.containerBuilder() - .withNodeIdentifier(NodeIdentifier.create(ORanDeviceManagerQNames.ORAN_FM_ALARM_NOTIF)) - .withChild(ImmutableNodes.leafNode(fault_id, "47")) - .withChild(ImmutableNodes.leafNode(fault_source, "Slot-2-Port-B")) - .withChild(ImmutableNodes.leafNode(fault_severity, "MAJOR")) - .withChild(ImmutableNodes.leafNode(is_cleared, "true")) - .withChild(ImmutableNodes.leafNode(fault_text, "CPRI Port Down")).build(); + return Builders.containerBuilder().withNodeIdentifier(NodeIdentifier.create(oranfm.get().getAlarmNotifQName())) + .withChild(ImmutableNodes.leafNode(oranfm.get().getFaultIdQName(), "47")) + .withChild(ImmutableNodes.leafNode(oranfm.get().getFaultSourceQName(), "Slot-2-Port-B")) + .withChild(ImmutableNodes.leafNode(oranfm.get().getFaultSeverityQName(), "MAJOR")) + .withChild(ImmutableNodes.leafNode(oranfm.get().getFaultIsClearedQName(), "true")) + .withChild(ImmutableNodes.leafNode(oranfm.get().getFaultTextQName(), "CPRI Port Down")).build(); } public static class NetconfDeviceNotification implements DOMNotification, DOMEvent { diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanNetworkElementFactory.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanNetworkElementFactory.java index 2ca2ee445..cad0994cc 100644 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanNetworkElementFactory.java +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanNetworkElementFactory.java @@ -17,83 +17,110 @@ */ package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import com.google.common.io.Files; +import java.io.File; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.Optional; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation; import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.config.ORanDMConfig; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.util.ORanDeviceManagerQNames; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.yangspecs.ORANFM; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.yangspecs.OnapSystem; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.DeviceManagerServiceProvider; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.FaultService; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.Capabilities; import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfAccessor; -import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor; import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfDomAccessor; -import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.TransactionUtils; import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; +import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.common.Revision; +import org.opendaylight.yangtools.yang.common.XMLNamespace; public class TestORanNetworkElementFactory { private static String NODEIDSTRING = "nSky"; private static NetconfAccessor accessor; + private static NetconfDomAccessor domAccessor; private static DeviceManagerServiceProvider serviceProvider; private static Capabilities capabilities; private static VESCollectorService vesCollectorService; private static FaultService faultService; private static WebsocketManagerService notificationService; private static DataProvider databaseService; + private static ORanDMConfig oranDmConfig; + private static ConfigurationFileRepresentation oranCfg; private static NodeId nodeId = new NodeId(NODEIDSTRING); - @BeforeClass - public static void init() throws InterruptedException, IOException { - NetconfBindingAccessor bindingAccessor = mock(NetconfBindingAccessor.class); - when(bindingAccessor.getTransactionUtils()).thenReturn(mock(TransactionUtils.class)); - when(bindingAccessor.getNodeId()).thenReturn(nodeId); + private static String fileName = "test1.properties"; + // @formatter:off + private static final String TESTCONFIG_CONTENT = "[ORAN-SUPERVISION]\n" + + "supervision-notification-interval=60\n" + + "guard-timer-overhead=10\n" + + ""; + // @formatter:on - NetconfDomAccessor domAccessor = mock(NetconfDomAccessor.class); - when(domAccessor.getNodeId()).thenReturn(nodeId); - capabilities = mock(Capabilities.class); - //accessor = mock(NetconfBindingAccessor.class); + @BeforeClass + public static void init() throws InterruptedException, IOException { accessor = mock(NetconfAccessor.class); + domAccessor = mock(NetconfDomAccessor.class); + capabilities = mock(Capabilities.class); serviceProvider = mock(DeviceManagerServiceProvider.class); vesCollectorService = mock(VESCollectorService.class); faultService = mock(FaultService.class); notificationService = mock(WebsocketManagerService.class); databaseService = mock(DataProvider.class); + oranDmConfig = mock(ORanDMConfig.class); + when(domAccessor.getCapabilites()).thenReturn(capabilities); + when(domAccessor.getNodeId()).thenReturn(nodeId); when(accessor.getCapabilites()).thenReturn(capabilities); - when(accessor.getNetconfBindingAccessor()).thenReturn(Optional.of(bindingAccessor)); when(accessor.getNetconfDomAccessor()).thenReturn(Optional.of(domAccessor)); when(serviceProvider.getFaultService()).thenReturn(faultService); when(serviceProvider.getWebsocketService()).thenReturn(notificationService); when(serviceProvider.getDataProvider()).thenReturn(databaseService); when(serviceProvider.getVESCollectorService()).thenReturn(vesCollectorService); + when(capabilities.isSupportingNamespaceAndRevision( + QNameModule.create(XMLNamespace.of(ORANFM.NAMESPACE), Revision.of("2022-08-15")))).thenReturn(true); + when(capabilities.isSupportingNamespaceAndRevision( + QNameModule.create(XMLNamespace.of(OnapSystem.NAMESPACE), Revision.of("2022-11-04")))).thenReturn(true); + Files.asCharSink(new File(fileName), StandardCharsets.UTF_8).write(TESTCONFIG_CONTENT); + oranCfg = new ConfigurationFileRepresentation(fileName); } @Test public void testCreateORANHWComponent() throws Exception { - when(accessor.getCapabilites().isSupportingNamespace(ORanDeviceManagerQNames.ORAN_HW_COMPONENT)).thenReturn(true); - ORanNetworkElementFactory factory = new ORanNetworkElementFactory(); + when(domAccessor.getCapabilites().isSupportingNamespace(ORanDeviceManagerQNames.ORAN_HW_COMPONENT)).thenReturn(true); + ORanNetworkElementFactory factory = new ORanNetworkElementFactory(oranCfg, oranDmConfig); assertTrue((factory.create(accessor, serviceProvider)).isPresent()); } @Test public void testCreateNone() throws Exception { - when(accessor.getCapabilites().isSupportingNamespace(ORanDeviceManagerQNames.ORAN_HW_COMPONENT)).thenReturn(false); - ORanNetworkElementFactory factory = new ORanNetworkElementFactory(); + when(domAccessor.getCapabilites().isSupportingNamespace(ORanDeviceManagerQNames.ORAN_HW_COMPONENT)).thenReturn(false); + ORanNetworkElementFactory factory = new ORanNetworkElementFactory(oranCfg, oranDmConfig); assertTrue(!(factory.create(accessor, serviceProvider).isPresent())); } @After public void cleanUp() throws Exception { + File file = new File(fileName); + if (file.exists()) { + System.out.println("File exists, Deleting it"); + file.delete(); + } } } diff --git a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanRegistrationToVESpnfRegistration.java b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanRegistrationToVESpnfRegistration.java index b46595293..ad1fcede3 100644 --- a/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanRegistrationToVESpnfRegistration.java +++ b/sdnr/wt/devicemanager-o-ran-sc/o-ran/ru-fh/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/oran/impl/dom/TestORanRegistrationToVESpnfRegistration.java @@ -22,12 +22,13 @@ package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; import org.mockito.junit.MockitoJUnitRunner; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.vesmapper.ORanRegistrationToVESpnfRegistrationMapper; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorCfgService; import org.onap.ccsdk.features.sdnr.wt.devicemanager.service.VESCollectorService; import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO; -- cgit 1.2.3-korg