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

Mandatory Fields in Read Only Data #125

Open
Joel-Cripps opened this issue Aug 21, 2020 · 1 comment
Open

Mandatory Fields in Read Only Data #125

Joel-Cripps opened this issue Aug 21, 2020 · 1 comment

Comments

@Joel-Cripps
Copy link

Hey there,
When validating mandatory fields in read-only data I receive a Data must be defined error.

The Code:

            let validateobjState = openconfig_interfaces_model.validate({
                        'openconfig-interfaces:interfaces': {
                            interface: [
                                {
                                    name: getRequest?.results[0]?.name,
                                    config: {
                                        name: getRequest?.results[0]?.name,
                                    },
                                    //Read-only data:
                                    state: {
                                        name: getRequest?.results[0]?.name,
                                        type: 'IF_ETHERNET', 
                                        mtu: getRequest?.results[0]?.mtu,
                                        'loopback-mode': false,
                                        description: getRequest?.results[0]?.description,
                                        enabled: getRequest?.results[0]?.status === 'up' ? true : false,
                                        ifindex: getRequest?.results[0]?.status?.vindex,
                                        'admin-status': 'DOWN',  <-----------Mandatory field
                                        'oper-status': getRequest?.results[0]?.status === 'up' ? 'UP' : 'DOWN'
                                    }
                                }
                            ]
                        }
                    });

The Yang Model:

    leaf admin-status {
      type enumeration {
        enum UP {
          description
            "Ready to pass packets.";
        }
        enum DOWN {
          description
            "Not ready to pass packets and not in some test mode.";
        }
        enum TESTING {
          description
            "In some test mode.";
        }
      }
      mandatory true;

The error:

(node:700819) UnhandledPromiseRejectionWarning: ExpressionError: [module(openconfig-interfaces)/grouping(interface-common-state)/leaf(admin-status)/mandatory] predicate validation error: AssertionError [ERR_ASSERTION]: data must be defined
    at Function.error (src/node_modules/yang-js/lib/element.js:62:17)
    at Function.error (src/node_modules/yang-js/lib/expression.js:140:21)
    at Function.apply (src/node_modules/yang-js/lib/expression.js:110:22)
    at Function.eval (src/node_modules/yang-js/lib/expression.js:127:23)
    at Function.eval (src/node_modules/yang-js/lib/yang.js:238:22)
    at Function.transform (src/node_modules/yang-js/lib/lang/extensions.js:1089:25)
    at Function.apply (src/node_modules/yang-js/lib/expression.js:93:33)
    at Property.<anonymous> (src/node_modules/yang-js/lib/property.js:199:34)
    at Property.set (src/node_modules/yang-js/lib/property.js:203:12)
    at Property.attach (src/node_modules/yang-js/lib/property.js:347:16)

If I change the value of mandatory to false, the validation is successful.

If I change the value to false and change admin-status to admin-status:"asdfasdfadsf" the validation will generate a correct enum error: (node:700190) UnhandledPromiseRejectionWarning: Error: [enumeration] type violation for 'asdfasdfadsf' on UP,DOWN,TESTING

let me know if you have any questions

@sekur
Copy link
Collaborator

sekur commented Aug 21, 2020

Thanks @Joel-Cripps for reporting this issue. I'll take a look and let you know what I find.

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

No branches or pull requests

2 participants