Export supported features to ietf-yang-library 30/100130/6
authorOleksandrZharov <Oleksandr.Zharov@pantheon.tech>
Tue, 15 Mar 2022 09:46:38 +0000 (10:46 +0100)
committerRobert Varga <nite@hq.sk>
Mon, 21 Mar 2022 06:14:49 +0000 (06:14 +0000)
ModuleLike.getFeatures() now reflects the set of features used to build
the module. Examine them to construct 'features' leaf-list accordingly.

JIRA: NETCONF-857
Change-Id: I8a1447b6d53f2947beaa06f3963ae9bd43373367
Signed-off-by: OleksandrZharov <Oleksandr.Zharov@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
netconf/mdsal-netconf-yang-library/src/main/java/org/opendaylight/netconf/mdsal/yang/library/YangLibraryWriter.java
netconf/mdsal-netconf-yang-library/src/test/java/org/opendaylight/netconf/mdsal/yang/library/ModulesStateTest.java
netconf/mdsal-netconf-yang-library/src/test/java/org/opendaylight/netconf/mdsal/yang/library/YangLibraryTest.java

index 5369d290eb9b57f3aa5b65553a7e85b2e1b1c20a..bdda3c2f2380c71237862c35931a4ee057fdd951 100644 (file)
@@ -15,6 +15,7 @@ import com.google.common.util.concurrent.MoreExecutors;
 import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
 import javax.annotation.PreDestroy;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -44,7 +45,9 @@ import org.opendaylight.yangtools.yang.binding.util.BindingMap;
 import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextListener;
+import org.opendaylight.yangtools.yang.model.api.FeatureDefinition;
 import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.ModuleLike;
 import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.component.annotations.Deactivate;
@@ -177,6 +180,7 @@ public class YangLibraryWriter implements EffectiveModelContextListener, AutoClo
                     .setRevision(ImportOnlyModuleRevisionBuilder.fromYangCommon(module.getQNameModule().getRevision())
                         .getRevisionIdentifier())
                     .setNamespace(new Uri(module.getNamespace().toString()))
+                    .setFeature(extractFeatures(module))
                     // FIXME: inline this once it's disambiguated
                     .setSubmodule(submoduleMap)
                     .build();
@@ -224,7 +228,8 @@ public class YangLibraryWriter implements EffectiveModelContextListener, AutoClo
                     .setConformanceType(ConformanceType.Implement)
                     // FIXME: inline this once it's disambiguated
                     .setSubmodule(submoduleMap)
-                    // FIXME: Add also deviations and features lists to module entries
+                    .setFeature(extractFeatures(module))
+                    // FIXME: Add also deviations to module entries
                     .build();
             })
             .collect(BindingMap.toMap());
@@ -235,4 +240,15 @@ public class YangLibraryWriter implements EffectiveModelContextListener, AutoClo
             .setModuleSetId(String.valueOf(moduleSetId))
             .build();
     }
+
+    private static List<YangIdentifier> extractFeatures(final ModuleLike module) {
+        final var namespace = module.getQNameModule();
+
+        return module.getFeatures().stream()
+            .map(FeatureDefinition::getQName)
+            // belt-and-suspenders: make sure the feature namespace matches
+            .filter(featureName -> namespace.equals(featureName.getModule()))
+            .map(featureName -> new YangIdentifier(featureName.getLocalName()))
+            .collect(Collectors.toUnmodifiableList());
+    }
 }
index 708667a02a3b6cc5776a306ec98fb77327b8f00a..75e48b2d67c75a369ecf79586eb408467c3b9aa8 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.netconf.mdsal.yang.library;
 
+import java.util.List;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.junit.MockitoJUnitRunner;
@@ -38,11 +39,13 @@ public class ModulesStateTest extends AbstractYangLibraryWriterTest {
                     .setRevision(CommonLeafsRevisionBuilder.emptyRevision())
                     .build()))
                 .setConformanceType(Module.ConformanceType.Implement)
+                .setFeature(List.of())
                 .build(), new ModuleBuilder()
                 .setName(new YangIdentifier("ietf-yang-library"))
                 .setNamespace(new Uri("urn:ietf:params:xml:ns:yang:ietf-yang-library"))
                 .setRevision(new Revision(new RevisionIdentifier("2019-01-04")))
                 .setConformanceType(Module.ConformanceType.Implement)
+                .setFeature(List.of())
                 .build()))
             .build());
     }
index 797ac77a29bcad7fba85b858beeaa9f2f7e1d909..248d6a6e780c0d682b69eff8d84303616bbc23f7 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.netconf.mdsal.yang.library;
 
 import com.google.common.collect.ImmutableMap;
 import java.util.Collections;
+import java.util.List;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.junit.MockitoJUnitRunner;
@@ -50,11 +51,13 @@ public class YangLibraryTest extends AbstractYangLibraryWriterTest {
                 .setNamespace(new Uri("test:namespace"))
                 .setRevision(new RevisionIdentifier("2013-07-22"))
                 .setSubmodule(ImmutableMap.of(sub.key(), sub))
+                .setFeature(List.of())
                 .build();
 
         Module yangLibrary = new ModuleBuilder().setName(new YangIdentifier("ietf-yang-library_2019-01-04"))
                 .setNamespace(new Uri("urn:ietf:params:xml:ns:yang:ietf-yang-library"))
                 .setRevision(new RevisionIdentifier("2019-01-04"))
+                .setFeature(List.of())
                 .build();
 
         ModuleSet modulesSet = new ModuleSetBuilder()