Uploaded image for project: 'yangtools'
  1. yangtools
  2. YANGTOOLS-1264

SchemaContextUtil.resolveModuleForPrefix does not look at submodules

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Medium
    • Resolution: Cannot Reproduce
    • None
    • None
    • None
    • None
    • I work with ODL Aluminium SR2. 

    Description

      We have a yang file ipi-bfd with rather complex structure. It includes some yang files

      include ipi-bfd-interface;

       

      The included yang file ipi-bfd-interface.yang in its turn imports some other yang files and uses them:

      import ipi-interface

      {         prefix ipi-interface;     }

      path  "/ipi-interface:interfaces/ipi-interface:interface/ipi-interface:name";

       

      These files are located on device and processed by Restconf. We get exception

      java.lang.IllegalArgumentException: Failed to resolve xpath: no module found for prefix ipi-interface in module ipi-bfd

                     at com.google.common.base.Preconditions.checkArgument(Preconditions.java:441) ~[?:?]

                      at org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.stringPathPartToQName(SchemaContextUtil.java:606)

       

      File ipi-bfd really does not have prefix ipi-interface. It is defined in included file and is used there.

      It looks like SchemaContextUtil.resolveModuleForPrefix method checks only imports from the top file itself ignoring included files.

      I fixed this bug in my environment by patching org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java, methodresolveModuleForPrefix.

       

      This is the patch

      -                return context.findModule(mi.getModuleName(), mi.getRevision()).orElse(null);

      +                Optional<? extends Module> moduleOpt = context.findModule(mi.getModuleName(), mi.getRevision());

      +                if (moduleOpt.isPresent())

      { +                    return moduleOpt.get(); +                }

      +            }

      +        }

      +

      +        for (Module submodule : module.getSubmodules()) {

      +            Module result = resolveModuleForPrefix(context, submodule, prefix);

      +            if (result != null) {

      +                return result;

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            yevgeny88 Yevgeny Shakhnovich
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: