I want to simulate a negative scenario while provisioning some commands on configuration mode.
Ex: “Command Timed out.”
The way I have implemented now is connecting and subscribing to cdb for a particular container/leaf. (In my case its /system/contact) and then try to provision one of the command with commit. The Network device has to wait for an indefinite amount of time, after that it should fail with “Command Time out”.
Actual Behaviour:
admin@NE-1% set system contact abc
[edit]
admin@NE-1% commit
Commit complete.
Expected Behaviour:
admin@NE-1% set system contact abc
[edit]
admin@NE-1% commit
Command Timed out
The solution I tried:
I tried decreasing the queryTimeout in confd.conf
<capi>
<newSessionTimeout>PT120S</newSessionTimeout>
<queryTimeout>PT120S</queryTimeout>
</capi>
and Increasing the wait time after commit on the device (sleep(600)) to be more than queryTimeout.
Code snippet:
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/poll.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <system.h>
#ifndef MAX_ARGS
#define MAX_ARGS 32
#endif#ifndef BUFSIZ
#define BUFSIZ 1024
#endif/CONFD and custom libraries/
#include <confd_lib.h>
#include <confd_dp.h>
#include <confd_cdb.h>
#include <confd_maapi.h>
#include <confd_cdb.h>/* Our daemon context as a global variable */
static struct confd_daemon_ctx *dctx;
struct listElement *list_map = NULL;
int debuglevel = CONFD_SILENT;int main(int argc, char *argv[]){
struct sockaddr_in addr; int debuglevel = CONFD_SILENT; int subsock; int status; int spoint; confd_init("cdb_listen_att", stderr, debuglevel); addr.sin_addr.s_addr = inet_addr("127.0.0.1"); addr.sin_family = AF_INET; addr.sin_port = htons(CONFD_PORT); if (confd_load_schemas((struct sockaddr*)&addr, sizeof (struct sockaddr_in)) != CONFD_OK) { confd_fatal("Failed to load schemas from confd\n"); } if ((dctx = confd_init_daemon("cdb_listen_att")) == NULL){ confd_fatal("Failed to initialize confdlib\n"); } if ((subsock = socket(PF_INET, SOCK_STREAM, 0)) < 0 ) { confd_fatal("Failed to open ctlsocket\n"); } if (cdb_connect(subsock, CDB_SUBSCRIPTION_SOCKET, (struct sockaddr*)&addr, sizeof (struct sockaddr_in)) < 0) confd_fatal("Sub: Failed to cdb_connect() to confd \n"); if ((status = cdb_subscribe(subsock, 3, sys_ns, &spoint, "/system/contact/")) != CONFD_OK) { fprintf(stderr, "Terminate: subscribe %d\n", status); exit(0); } if (cdb_subscribe_done(subsock) != CONFD_OK) confd_fatal("cdb_subscribe_done() failed"); printf("Subscription point = %d\n", spoint); while (1) { struct pollfd set[1]; set[0].fd = subsock; set[0].events = POLLIN; set[0].revents = 0; if (poll(set, sizeof(set)/sizeof(*set), -1) < 0) { perror("Poll failed:"); continue; } else{ printf("Wait Time for the Command Timeout\n"); sleep(600); } /* Check for I/O */ if (set[0].revents & POLLIN) { int sub_points[1]; int reslen; if ((status = cdb_read_subscription_socket(subsock, &sub_points[0], &reslen)) != CONFD_OK) exit(status); if ((status = cdb_sync_subscription_socket(subsock, CDB_DONE_PRIORITY)) != CONFD_OK) { exit(status); } } }
}
yang for system :
container system {
description
“System related configurations”;
leaf contact {
type string;
description
“Contact information for this system”;
}
}
P.S: You can use any provisioning command. To reproduce in your setup. the only line you need to change in code snippet is.
if ((status = cdb_subscribe(subsock, 3, sys_ns, &spoint, “/system/contact/”))
change the namespace and the container/leaf where the delay should happen for commit, eventually occurring Command Timed out.