Skip to content

Commit

Permalink
Add CONTROLLER_YANG_DUMP_DIR debug option for dumping all YANG files
Browse files Browse the repository at this point in the history
  • Loading branch information
olofhagsand committed Aug 30, 2024
1 parent 5eed708 commit 1b82e5a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@
*/
#undef CONTROLLER_EXTRA_PUSH_SYNC

/*! Dump all schemas in disc from devices regardless of local file cache, debug option
*
* Save all files under ${CONTROLLER_YANG_DUMP_DIR}/${devname}/
* Since this disables the local store cache, all yang files from all devices will be fetched
* which may result in slower and more disk-space.
* NOTE: all devname dirs must be created a priori, they are not created automatically
*/
#undef CONTROLLER_YANG_DUMP_DIR
// #define CONTROLLER_YANG_DUMP_DIR "/usr/local/share/clixon/controller/dump"

#define ACTION_PROCESS "Action process"

/*! Controller debug levels
Expand Down
28 changes: 27 additions & 1 deletion src/controller_device_recv.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,11 @@ device_state_recv_get_schema(device_handle dh,
clixon_err(OE_YANG, 0, "schema mount dir not set");
goto done;
}
cprintf(cb, "%s/%s", dir, modname);
#ifdef CONTROLLER_YANG_DUMP_DIR
cprintf(cb, "%s", CONTROLLER_YANG_DUMP_DIR);
cprintf(cb, "/%s", device_handle_name_get(dh));
#endif
cprintf(cb, "/%s", modname);
if (revision)
cprintf(cb, "@%s", revision);
cprintf(cb, ".yang");
Expand All @@ -512,6 +516,28 @@ device_state_recv_get_schema(device_handle dh,
goto done;
}
fflush(f);
#ifdef CONTROLLER_YANG_DUMP_DIR
{
cbuf *cb2 = NULL;

/* Check if exists as local file */
if ((ret = yang_file_find_match(h, modname, revision, NULL)) < 0)
goto done;
if (ret == 0) {
/* If not exists, copy back to mount-dir */
if ((cb2 = cbuf_new()) == NULL){
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
cprintf(cb, "%s", dir);
cprintf(cb, "/%s", modname);
if (revision)
cprintf(cb, "@%s", revision);
if (clicon_file_copy(cbuf_get(cb), cbuf_get(cb2)) < 0)
goto done;
}
}
#endif
retval = 1;
done:
if (f)
Expand Down
2 changes: 2 additions & 0 deletions src/controller_device_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ device_send_get_schema_next(clixon_handle h,
name = xml_find_body(x, "name");
revision = xml_find_body(x, "revision");
(*nr)++;
#ifndef CONTROLLER_YANG_DUMP_DIR
/* Check if already loaded */
if (yang_find_module_by_name_revision(yspec, name, revision) != NULL)
continue;
Expand All @@ -250,6 +251,7 @@ device_send_get_schema_next(clixon_handle h,
goto done;
if (ret == 1)
continue;
#endif
/* May be some concurrency here if several devices requests same yang simultaneously
* To avoid that one needs to keep track if another request has been sent.
*/
Expand Down

0 comments on commit 1b82e5a

Please sign in to comment.