[YANGTOOLS-790] BGP models not compatible with leafref context Created: 19/Jun/17  Updated: 10/Apr/22  Resolved: 28/Sep/17

Status: Resolved
Project: yangtools
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Jan Srnicek Assignee: Peter Kajsa
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


External issue ID: 8713

 Description   

While trying to create LeafRefContext(yangtools) it appears that bgp models contains some leafref configuration that is invalid. Following error is showed

org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefPathParseException: No module import for prefix: bgp-pol in module: openconfig-routing-policy
at org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefPathParserListenerImpl.getQNameModuleForImportPrefix(LeafRefPathParserListenerImpl.java:178)
at org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefPathParserListenerImpl.enterPrefix(LeafRefPathParserListenerImpl.java:121)
at org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefPathParser$PrefixContext.enterRule(LeafRefPathParser.java:997)
at org.antlr.v4.runtime.tree.ParseTreeWalker.enterRule(ParseTreeWalker.java:66)
at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:49)
at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:52)
at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:52)
at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:52)
at org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefPathParserImpl.parseLeafRefPathSourceToSchemaPath(LeafRefPathParserImpl.java:37)
at org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextTreeBuilder.buildLeafRefContextReferencingTree(LeafRefContextTreeBuilder.java:134)
at org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextTreeBuilder.buildLeafRefContextReferencingTree(LeafRefContextTreeBuilder.java:92)
at org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextTreeBuilder.buildLeafRefContextReferencingTree(LeafRefContextTreeBuilder.java:92)
at org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextTreeBuilder.buildLeafRefContextReferencingTree(LeafRefContextTreeBuilder.java:92)
at org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextTreeBuilder.buildLeafRefContextReferencingTree(LeafRefContextTreeBuilder.java:92)
at org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextTreeBuilder.buildLeafRefContextReferencingTree(LeafRefContextTreeBuilder.java:92)
at org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextTreeBuilder.buildLeafRefContextReferencingTree(LeafRefContextTreeBuilder.java:92)
at org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextTreeBuilder.buildLeafRefContextReferencingTree(LeafRefContextTreeBuilder.java:92)
at org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextTreeBuilder.buildLeafRefContextReferencingTree(LeafRefContextTreeBuilder.java:92)
at org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextTreeBuilder.buildLeafRefContextTree(LeafRefContextTreeBuilder.java:48)
at org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext.create(LeafRefContext.java:53)
at io.fd.hc2vpp.model.test.LeafRefContextTest.testLeafRefContextCreation(LeafRefContextTest.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

Can be reproduced with following test:

public class LeafRefContextTest {

private static final String YANG_BA_PROVIDER_PATH = "META-INF/services/" + YangModelBindingProvider.class.getName();

@Test
public void testLeafRefContextCreation()

{ assertNotNull(LeafRefContext.create(context())); }

private SchemaContext context()

{ ModuleInfoBackedContext ctx = ModuleInfoBackedContext.create(); final Set<YangModuleInfo> modules = modules(); checkState(!modules.isEmpty(), "No modules found"); ctx.addModuleInfos(modules); return ctx.getSchemaContext(); }

private Set<YangModuleInfo> modules() {
try

{ return Collections.list(getClass().getClassLoader().getResources(YANG_BA_PROVIDER_PATH)) .stream() .map(LeafRefContextTest::urlToString) .flatMap(content -> Arrays.stream(content.split("\n"))) .filter(line -> !Strings.isNullOrEmpty(line.trim())) .map(LeafRefContextTest::loadClass) .map(LeafRefContextTest::getInstance) .map(YangModelBindingProvider.class::cast) .map(YangModelBindingProvider::getModuleInfo) .collect(Collectors.toSet()); }

catch (IOException e)

{ throw new IllegalStateException("Unable to load binding providers from path: " + YANG_BA_PROVIDER_PATH, e); }

}

private static Object getInstance(@Nonnull final Class<?> aClass) {
try

{ return aClass.newInstance(); }

catch (InstantiationException | IllegalAccessException e)

{ throw new IllegalStateException("Unable to create instance of " + aClass); }

}

private static Class<?> loadClass(@Nonnull final String className) {
try

{ return Class.forName(className); }

catch (ClassNotFoundException e)

{ throw new IllegalArgumentException("Unable to load class: " + className, e); }

}

private static String urlToString(@Nonnull final URL url) {
try

{ return Resources.toString(url, Charsets.UTF_8); }

catch (IOException e)

{ throw new IllegalArgumentException("Unable to read resource from: " + url, e); }

}
}

And set of dependencies:

<dependencies>
<dependency>
<groupId>org.opendaylight.bgpcep</groupId>
<artifactId>bgp-rib-api</artifactId>
<version>${bgpcep.version}</version>
</dependency>
<dependency>
<groupId>org.opendaylight.bgpcep</groupId>
<artifactId>bgp-bmp-api</artifactId>
<version>${bgpcep.version}</version>
</dependency>
<dependency>
<groupId>org.opendaylight.bgpcep</groupId>
<artifactId>bgp-openconfig-api</artifactId>
<version>${bgpcep.version}</version>
</dependency>
<dependency>
<groupId>org.opendaylight.bgpcep</groupId>
<artifactId>rsvp-api</artifactId>
<version>${bgpcep.version}</version>
</dependency>
<dependency>
<groupId>org.opendaylight.bgpcep</groupId>
<artifactId>bgp-parser-api</artifactId>
<version>${bgpcep.version}</version>
</dependency>
</dependencies>



 Comments   
Comment by Robert Varga [ 05/Aug/17 ]

I do not see anything wrong with the BGP models, but it would seem the leafref parser is getting confused.

Comment by Peter Kajsa [ 09/Aug/17 ]

I tried to replicate this bug, but I am getting different error:

testLeafRefContextCreation(LeafRefContextTest): No child (http://openconfig.net/yang/network-instance?revision=2015-10-18)network-instances found in node container ModuleEffectiveStatementImpl[name=bgp-openconfig-extensions, namespace=urn:opendaylight:params:xml:ns:yang:bgp:openconfig-extensions, revision=2016-06-14, prefix=odl-oc-ext, yangVersion=1] in module bgp-openconfig-extensions

Please which version of bgpcep are you using (${bgpcep.version}) ?

Comment by Jan Srnicek [ 09/Aug/17 ]

This was present in BORON-SR4 , but fix for Carbon would be enough as we've bumped recently

Comment by Peter Kajsa [ 09/Aug/17 ]

Ok, thanks and please are you sure you are using the following fix ? https://git.opendaylight.org/gerrit/#/c/57224/

Comment by Jan Srnicek [ 16/Aug/17 ]

If that bugfix is part of Carbon SR1 then yes

Comment by Jan Srnicek [ 16/Aug/17 ]

Verified, getting the same error as Peter Kajsa

Comment by Peter Kajsa [ 07/Sep/17 ]

https://git.opendaylight.org/gerrit/#/c/62832/

Generated at Wed Feb 07 20:54:19 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.