BADTERM Error when trying to use cdb_num_instances API

Hi All,

My implementation is to get the context name values for context list.

Used a sample program to connect to confd and retrieve the number of context names in the list.

Facing the below error

==========================
bash-4.2# ./sample
TRACE Connected (cdb) to ConfD
TRACE CDB_NEW_SESSION  --> CONFD_OK
TRACE Established new CDB session to ConfD
TRACE CDB_NUM_INSTANCES /contexts/context --> CONFD_OK
BADTERM: {error,{cs_error,undefined,misc,internal,undefined,undefined,undefined,undefined,undefined,false}}
INTERNAL ERROR: Internal error, Bad term value
contexts = -1
TRACE CDB_END_SESSION  --> CONFD_OK
======================================

output from confd:

(config)# show full-configuration contexts context
contexts context local
 ip static-route 0.0.0.0/0 next-hop-address 10.94.109.254
 !
!
contexts context one 

=====================================

Program pseudo code:

int main(void)
{
    
    confd_init("SAMPLE", stderr, CONFD_TRACE);
    

    if ((d = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
      {
        printf("Failed to open subscription socket eb_ss\n");
        return CONFD_ERR;
      }

    if( CONFD_OK != cdb_connect(d, CDB_READ_SOCKET, (struct sockaddr *)&eb_addr, sizeof(struct sockaddr_in)))
      {
        printf("Failed to cdb_connect ss\n");
        //return CONFD_ERR;
      }
    cdb_start_session2(d, CONFD_RUNNING,0);
    n = cdb_num_instances(d, "/contexts/context");
    printf("contexts = %d\n", n);
    for( i = 0 ; i < n; i++)
      {
        char name[128];

        cdb_get_str(d, name ,128 , "/contexts/context[%d]/context-name", i);
        printf("context name %d\n", name);
      }
    cdb_end_session(d);
    cdb_close(d);
    return 0;
}

============================

Can you let us know any changes to be done in the above code,

pseudo of the yang file of contexts, context

container contexts {
    description
      "root model for set";
       ----------------
       ----------------
}

// second yang file:
augment "/ctxsipos:contexts" {
    description
      "xxxx-context";
    /*
    context (context-name) [ vpn-rd (vpn-val) ]
    */
    list context {
      key "context-name";
      description
        "Configure an operational context";
      leaf context-name {
        type string;
        description
          "Specify a named context to configure";
      }
      ------------------------
}

I had seen sample programs which are found working with the similar code. . Is it due to the augment addition of context to existing contexts container is it failing .

Thanks
Durga Prakash

Hello,

I do not know what is exactly wrong with your case.

You may try to look at examples.confd/user_guide_examples/simple_cdb and run it in your environment. If works - maybe modify so it resembles your code. What is in the example and not in your code is cdb_set_namespace call before cdb_num_instances, but it should be necessary only if top level element is not unique.

Hi,

I just updated the program examples.confd/user_guide_examples/simple_cdb and now it worked.

Will incorporate the same in our code.

Thanks a lot.

Durga.