ConfD User Community

Validating list key

Below is an example of the yang file i am using:

typedef utilities-enumeration
{
    type enumeration
    {
        enum all-utilities;
        enum util-a-enum;
        enum util-a-enum;
        enum util-a-enum;
        enum util-a-enum;
    }
    default all-utilities;
}

grouping utility-type
{
    leaf utility-name
    {
        type utility-enumeration;
    }
}

grouping utility-config
{
    container some-util-config
    {
    .
    .
    .
    }
}

grouping util-a-config-type
{
    container util-a-config
    {
        uses utility-config;
        must "../utility[utility-name]/utility-name = util-a-enum"
        {
            error-message "The util-a-enum must be specified for this utility";
        }
    }
}

grouping application-type
{
    container utilities
    {
        list utility
        {
            uses utility-type;
            key utility-name;
            uses util-a-config-type;
            uses util-b-config-type;
        }
    }
}

What needs to happen is that if util-a-config-type is configured as a utility, the utility-name should read util-a-enum. A similar thing needs to happen for util-b-config, etc.

However, the must statement in util-a-config is unable to find utility-name, and the commit fails. I have tried various paths and none worked.

  1. How should the xpath be specified in this must statement?
  2. What debug information can I use to understand how confd evaluates the must statement, so I can figure out the xpath by myself?

Thanks

If you have something like this:

$ pyang -f tree utilities.yang
module: utilities
   +--rw utilities
   |  +--rw utility* [utility-name]
   |     +--rw utility-name     utility-enumeration
   |     +--rw util-a-config
            your must() expression here
   |        +--rw some-util-config
   |           +--rw some-util?   string
$ confd_cli -u admin -C
admin connected from 127.0.0.1
# devtools true
# config       
Entering configuration mode terminal
# utilities utility util-a-enum util-a-config some-util-config some-util test
# pwd
Current submode path:
  utilities utility util-a-enum
# xpath must "current()/utility-name = 'util-a-enum'"                        
true

I.e. your must expression could be something like must "current()/../utility-name = 'util-a-enum'"

And as @waitai replied to you some time ago:

Thank you for your reply!

I did use the XPath trace log, but it has so much information that I couldn’t make heads or tails of it.

As for the ‘devtools’ option in the CLI: my CLI does not have this command. I believe we are using confd 3.7.1.

I will try your proposal and let you know.

Thanks again!

Howling

Worked! Thanks!

Could you tell me how to use devtools in version 3.7.1?

Thanks again

Upgrade to ConfD 6.3 or later, or do something like what @jlawitzke recommended to you some time ago.