diff API output #2028
Replies: 3 comments 7 replies
-
Yes, please provide the input and output in the old version and in the new version, please. |
Beta Was this translation helpful? Give feedback.
-
Thanks for getting back. The yang model is below: module pkm {
yang-version "1.1";
namespace "pkm";
prefix "pkm";
grouping nc-top {
container named-conditions {
list named-condition {
key name;
leaf name {
type string {
length 1..64;
}
}
leaf description {
type string;
}
list rules {
key position;
leaf position {
type uint32 {
range 1..max;
}
}
leaf description {
type string;
}
}
}
}
}
// data definition statements
uses nc-top;
} data1: {
"pkm:named-conditions":{
"named-condition":[
{
"name":"nc0",
"description": "d2",
"rules":[
{
"description":"test gbp tcp allow rule",
"position":10
},
{
"description":"test gbp tcp allow rule",
"position":20
}
]
}
]
}
} data2: {
"pkm:named-conditions":{
"named-condition":[
{
"name":"nc0",
"description": "d2-new",
"rules":[
{
"description":"test gbp tcp allow rule",
"position":20
}
]
}
]
}
} SO, if we look diff between data 1 and data 2, the changes are the following: I am using the diff API (lyd_diff_tree) to get the diff between data 1 and data 2, and I see inconsistencies in the output Sometimes it is in format1 as shown below: {
"pkm:named-conditions": {
"@": {
"yang:operation": "none"
},
"named-condition": [
{
"@": {
"yang:operation": "none"
},
"name": "nc0",
"description": "d2-new",
"@description": {
"yang:operation": "replace",
"yang:orig-default": false,
"yang:orig-value": "d2"
},
"rules": [
{
"@": {
"yang:operation": "delete"
},
"position": 10,
"description": "test gbp tcp allow rule"
}
]
}
]
}
} But sometimes it is format2 below: {
"pkm:named-conditions": {
"@": {
"yang:operation": "none"
},
"named-condition": [
{
"@": {
"yang:operation": "none"
},
"name": "nc0",
"description": "d2-new",
"@description": {
"yang:operation": "replace",
"yang:orig-default": false,
"yang:orig-value": "d2"
}
},
{
"@": {
"yang:operation": "none"
},
"name": "nc0",
"rules": [
{
"@": {
"yang:operation": "delete"
},
"position": 10,
"description": "test gbp tcp allow rule"
}
]
}
]
}
} In format1, there is only one dict block for "nc0" whereas in format2, there are two blocks for nc0 (instead of merging them into one) for each of the two changes. What is the correct format (format1?) and why is it in-consistent ? |
Beta Was this translation helpful? Give feedback.
-
Sorry, please try the below inputs to reproduce. Originally, I thought the issue was with latest tag (2.1.55). But, later, realized that the problem is seen when we change the inputs data, a little bit (with both older and new versions). Please see below
{
"pkm:named-conditions":{
"named-condition":[
{
"name":"nc1",
"description": "d1",
"rules":[
{
"description":"test gbp tcp allow rule",
"position":10
}
]
},
{
"name":"nc2",
"description": "d1",
"rules":[
{
"description":"test gbp tcp allow rule",
"position":10
}
]
},
{
"name":"nc3",
"description": "d1",
"rules":[
{
"description":"test gbp tcp allow rule",
"position":10
}
]
},
{
"name":"nc4",
"description": "d1",
"rules":[
{
"description":"test gbp tcp allow rule",
"position":10
}
]
},
{
"name":"nc0",
"description": "d2",
"rules":[
{
"description":"test gbp tcp allow rule",
"position":10
},
{
"description":"test gbp tcp allow rule",
"position":20
}
]
}
]
}
} data2: {
"pkm:named-conditions":{
"named-condition":[
{
"name":"nc0",
"description": "d2-new",
"rules":[
{
"description":"test gbp tcp allow rule",
"position":20
}
]
}
]
}
} DIff: {
"pkm:named-conditions": {
"@": {
"yang:operation": "none"
},
"named-condition": [
{
"@": {
"yang:operation": "delete"
},
"name": "nc1",
"description": "d1",
"rules": [
{
"position": 10,
"description": "test gbp tcp allow rule"
}
]
},
{
"@": {
"yang:operation": "delete"
},
"name": "nc2",
"description": "d1",
"rules": [
{
"position": 10,
"description": "test gbp tcp allow rule"
}
]
},
{
"@": {
"yang:operation": "delete"
},
"name": "nc3",
"description": "d1",
"rules": [
{
"position": 10,
"description": "test gbp tcp allow rule"
}
]
},
{
"@": {
"yang:operation": "delete"
},
"name": "nc4",
"description": "d1",
"rules": [
{
"position": 10,
"description": "test gbp tcp allow rule"
}
]
},
{
"@": {
"yang:operation": "none"
},
"name": "nc0",
"description": "d2-new",
"@description": {
"yang:operation": "replace",
"yang:orig-default": false,
"yang:orig-value": "d2"
}
},
{
"@": {
"yang:operation": "none"
},
"name": "nc0",
"rules": [
{
"@": {
"yang:operation": "delete"
},
"position": 10,
"description": "test gbp tcp allow rule"
}
]
}
]
}
} As you can see above the diff for "nc0" is not consolidated in one list. This is the problem. nc1 to nc4 has only block, but nc0 has two blocks. Now, if i slightly modify data1 (case 2 below), the diff for nc0 is consolidated.
Data1: {
"pkm:named-conditions":{
"named-condition":[
{
"name":"nc1",
"description": "d1",
"rules":[
{
"description":"test gbp tcp allow rule",
"position":10
}
]
},
{
"name":"nc2",
"description": "d1",
"rules":[
{
"description":"test gbp tcp allow rule",
"position":10
}
]
},
{
"name":"nc3",
"description": "d1",
"rules":[
{
"description":"test gbp tcp allow rule",
"position":10
}
]
},
{
"name":"nc0",
"description": "d2",
"rules":[
{
"description":"test gbp tcp allow rule",
"position":10
},
{
"description":"test gbp tcp allow rule",
"position":20
}
]
}
]
}
} Data2: {
"pkm:named-conditions":{
"named-condition":[
{
"name":"nc0",
"description": "d2-new",
"rules":[
{
"description":"test gbp tcp allow rule",
"position":20
}
]
}
]
}
} DIff: {
"pkm:named-conditions": {
"@": {
"yang:operation": "none"
},
"named-condition": [
{
"@": {
"yang:operation": "delete"
},
"name": "nc1",
"description": "d1",
"rules": [
{
"position": 10,
"description": "test gbp tcp allow rule"
}
]
},
{
"@": {
"yang:operation": "delete"
},
"name": "nc2",
"description": "d1",
"rules": [
{
"position": 10,
"description": "test gbp tcp allow rule"
}
]
},
{
"@": {
"yang:operation": "delete"
},
"name": "nc3",
"description": "d1",
"rules": [
{
"position": 10,
"description": "test gbp tcp allow rule"
}
]
},
{
"@": {
"yang:operation": "none"
},
"name": "nc0",
"description": "d2-new",
"@description": {
"yang:operation": "replace",
"yang:orig-default": false,
"yang:orig-value": "d2"
},
"rules": [
{
"@": {
"yang:operation": "delete"
},
"position": 10,
"description": "test gbp tcp allow rule"
}
]
}
]
}
} If you compare case 1 and case 2, the only change is the number of named conditions in data1. In case 1, there are 5, whereas in case 2, there is 4. The changes for nc0 is same in both cases, but the diff comes out different depending on the number of elements in the diff. Now, nc0 has only one block in the diff. Pls let me know if you need any further inputs. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am currently using libyang 2.0.194, and trying to migrate to latest (2.1.55). I noticed that the output of diff API is different between the two libyang versions, for same input trees. Specifically, the output of latest 2.1.55 seems to have separate blocks for each changed xpath, whereas, in 2.0.194, the output is consolidated based on the prefix/keys of the changed xpaths.
Is this is a known behavior ? What is the correct expected format ? I can provide input and output data if needed for clarity.
Thanks
Praveen
Beta Was this translation helpful? Give feedback.
All reactions