Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ygot.Diff generating gnmi update TypeVal as bool for leaf type yang.Empty #473

Closed
soumiksamanta opened this issue Nov 23, 2020 · 6 comments · Fixed by #476
Closed

ygot.Diff generating gnmi update TypeVal as bool for leaf type yang.Empty #473

soumiksamanta opened this issue Nov 23, 2020 · 6 comments · Fixed by #476

Comments

@soumiksamanta
Copy link
Contributor

ygot v0.8.11

I have this yang defined

module dummy {
    yang-version "1";
    namespace "urn:dummy/dummy";
    prefix "dummy";
    grouping dummy-entry {
        list entries {
            key "name";
            leaf name {
                type string;
            }
            leaf city {
                type string;
            }
            leaf primary {
                type empty;
            }
        }
    }
    uses dummy-entry;
}

I created two Device{} structs with the following jsons

Object1:

{
    "entries":[
      {  
            "name": "samanta",
            "city": "xyz"
      }
    ]
}

Object2:

{
    "entries":[
      {  
            "name": "samanta",
            "city": "xyz"
      },
      {  
            "name": "soumik",
            "city": "abc"
      }
    ]
}
dummy1Data := &dummy.Device{}
dummy.Unmarshal("object1.json", dummy1Data)
dummy2Data := &dummy.Device{}
dummy.Unmarshal("object2.json", dummy2Data)

Now when I try to do a diff of dummy1Data and dummy2Data
diffData, err = ygot.Diff(dummy2Data, dummy1Data)

I get the following gnmi.Notification object

update: <
  path: <
    elem: <
      name: "entries"
      key: <
        key: "name"
        value: "samanta"
      >
    >
    elem: <
      name: "primary"
    >
  >
  val: <
    bool_val: false
  >
>
update: <
  path: <
    elem: <
      name: "entries"
      key: <
        key: "name"
        value: "soumik"
      >
    >
    elem: <
      name: "city"
    >
  >
  val: <
    string_val: "abc"
  >
>
update: <
  path: <
    elem: <
      name: "entries"
      key: <
        key: "name"
        value: "soumik"
      >
    >
    elem: <
      name: "name"
    >
  >
  val: <
    string_val: "soumik"
  >
>
update: <
  path: <
    elem: <
      name: "entries"
      key: <
        key: "name"
        value: "soumik"
      >
    >
    elem: <
      name: "primary"
    >
  >
  val: <
    bool_val: false
  >
>
update: <
  path: <
    elem: <
      name: "entries"
      key: <
        key: "name"
        value: "samanta"
      >
    >
    elem: <
      name: "city"
    >
  >
  val: <
    string_val: "xyz"
  >
>
update: <
  path: <
    elem: <
      name: "entries"
      key: <
        key: "name"
        value: "samanta"
      >
    >
    elem: <
      name: "name"
    >
  >
  val: <
    string_val: "samanta"
  >
>

In the notification object, the yang.Empty path "primary" is set as value "bool". which is not conforming to the yang model. And as per https://tools.ietf.org/html/rfc7951#section-6.9 yang.Empty is actually a slice

@soumiksamanta
Copy link
Contributor Author

May be similar to #291

@soumiksamanta
Copy link
Contributor Author

soumiksamanta commented Nov 24, 2020

@robshakir Actually I want to get the gnmiNotifications encoded in JSON_IETF, wherein a YangEmpty leaf if not present should not create an update with bool(false).

@wenovus
Copy link
Collaborator

wenovus commented Nov 24, 2020

Reproduced, taking a look.

@soumiksamanta
Copy link
Contributor Author

diff --git a/ygot/render_test.go b/ygot/render_test.go
index 3e06ad7..52f0a18 100644
--- a/ygot/render_test.go
+++ b/ygot/render_test.go
@@ -918,8 +918,9 @@ func (*pathElemExample) IsYANGGoStruct() {}
 
 // pathElemExampleChild is an example struct that is used as a list child struct.
 type pathElemExampleChild struct {
-       Val        *string `path:"val|config/val"`
-       OtherField *uint8  `path:"other-field"`
+       Val        *string   `path:"val|config/val"`
+       OtherField *uint8    `path:"other-field"`
+       Empty      YANGEmpty `path:"empty-field"`
 }

Just added the above empty field to pathElemExampleChild, and the Diff tests failed

  1. "add an item to a list"
  2. "remove item from list"

@wenovus
Copy link
Collaborator

wenovus commented Nov 24, 2020

Thanks, added a similar test to the fix.

@wenovus
Copy link
Collaborator

wenovus commented Nov 24, 2020

in v.0.8.12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants