Issue an info message when a config=true list does not have keys 98/86598/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 28 Dec 2019 10:09:37 +0000 (11:09 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 28 Dec 2019 10:12:34 +0000 (11:12 +0100)
RFC7950 section 7.8.2 places an explicit requirement that lists
representing configuration (i.e. config=true) must define at least
one key.

This restriction does make sense in contexts like NETCONF, but is
generally not needed in OpenDaylight. Since it hurts model
interoperability, add a message pointing this violation out.

JIRA: YANGTOOLS-957
Change-Id: If29078e51aa1ec55fa070f263755f15147ad835f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/list/ListEffectiveStatementImpl.java

index 275caa58568f6e17946be60ed3508b1c0090e711..867543d425900c5d7c850f9388d6ad1f758a924c 100644 (file)
@@ -38,11 +38,14 @@ import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveMust
 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStmtUtils;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 final class ListEffectiveStatementImpl
         extends AbstractEffectiveMustConstraintAwareSimpleDataNodeContainer<ListStatement>
         implements ListEffectiveStatement, ListSchemaNode, DerivableSchemaNode,
             ActionNodeContainerCompat<QName, ListStatement>, NotificationNodeContainerCompat<QName, ListStatement> {
+    private static final Logger LOG = LoggerFactory.getLogger(ListEffectiveStatementImpl.class);
     private static final String ORDER_BY_USER_KEYWORD = "user";
 
     private final boolean userOrdered;
@@ -88,6 +91,12 @@ final class ListEffectiveStatementImpl
             this.keyDefinition = ImmutableList.of();
         }
 
+        if (isConfiguration() && keyDefinition.isEmpty()) {
+            LOG.info("Configuration list {} does not define any keys in violation of RFC7950 section 7.8.2. While "
+                    + " this is fine with OpenDaylight, it can cause interoperability issues with other systems "
+                    + "[at {}]", ctx.getStatementArgument(), ctx.getStatementSourceReference());
+        }
+
         this.uniqueConstraints = ImmutableList.copyOf(allSubstatementsOfType(UniqueConstraint.class));
 
         final Builder<ActionDefinition> actionsBuilder = ImmutableSet.builder();