[YANGTOOLS-1555] nested instance identifer values Created: 12/Dec/23  Updated: 12/Dec/23  Resolved: 12/Dec/23

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

Type: Bug Priority: Medium
Reporter: Maurizio Brigandi' Assignee: Unassigned
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

karaf 18.3



 Description   

The following instance-identifer value for node osiIf  

crosses a list element

whose key my-is-is:name is an intance-identifer ...

This following encoding seems reasonable as output of a GET,

in which the single quote characters are escaped

in the nested instance-idenfier value.

 

<osiIf  xmlns:my-interfaces="xxx"  
        xmlns:my-is-is="yyy" 
        xmlns:my-routing="zzz">/my-routing:routing/my-routing:control-plane-protocol[my-routing:name='MANAGEMENT-PLANE']/my-is-is:isis/my-is-is:interface[my-is-is:name='/my-interfaces:interfaces/my-interfaces:if[my-interfaces:typeIf=&apos;lan&apos;][my-interfaces:idx=&apos;1&apos;]']</osiIf>

 

But it is not accepted by opendaylight sw, which raises the following error:

{
  "errors": {
    "error": [
      {
         "error-tag": "operation-failed",
         "error-info": "java.lang.IllegalArgumentException: Could not parse Instance Identifier '/my-routing:routing/my-routing:control-plane-protocol[my-routing:name='MANAGEMENT-PLANE']/my-is-is:isis/my-is-is:interface[my-is-is:name='/my-interfaces:interfaces/my-interfaces:if[my-interfaces:typeIf='lan'][my-interfaces:idx='1']']'. Offset: 203 : Reason: Precondition must ends with ']'",
         "error-message": "Transaction failed",
         "error-type": "application"
       }
    ]
  }
}


 Comments   
Comment by Robert Varga [ 12/Dec/23 ]

This is not a bug.
The problem here is you are using XML entities to hide nested apostrophes – and those get replaced by the XML parser, as it it's job. That means your document's instance-identifier value is completely equivalent to the string we report in the error message – which is exactly what the XMLStreamReader gives us.

In order to make this case work, you need to use YANG string escaping, and since the embedded instance-identifier value uses single-quoted strings, the outer value needs to use double-quoted strings and escape the value using the rules associated with that.

See https://github.com/opendaylight/yangtools/blob/bab5285c29c41b6e25098fd1859803534d24324f/data/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/AbstractStringInstanceIdentifierCodec.java#L106-L127

I.e. the value should be:

/my-routing:routing/my-routing:control-plane-protocol[my-routing:name='MANAGEMENT-PLANE']/my-is-is:isis/my-is-is:interface[my-is-is:name="/my-interfaces:interfaces/my-interfaces:if[my-interfaces:typeIf='lan'][my-interfaces:idx='1']"]
Generated at Wed Feb 07 20:56:29 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.