You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
xmldb_get0 with "candidate" as db will yield invalid results if it has been called on a validate/commit callback in a context of the first backend transaction.
Instead of returning the startup config as expected, it will return the candidate state as it was on the previous backend run.
Example
Compile the following simple backend plugin:
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <syslog.h>
#include <unistd.h>
/* clicon */
#include "cligen/cligen.h"
/* Clicon library functions. */
#include "clixon/clixon.h"
/* These include signatures for plugin and transaction callbacks. */
#include "clixon/clixon_backend.h"
void dump_datastore(clicon_handle h, const char *datastore) {
cxobj *obj;
ret = xmldb_get0(h, datastore, NULL, NULL, 0, &obj, NULL);
clicon_xml2file(stdout, obj, 0, 1);
}
int main_validate(clicon_handle h, transaction_data td) {
clicon_debug(1, "%s", __FUNCTION__);
transaction_log(h, td, 1, __FUNCTION__);
dump_datastore(h, "candidate");
return 0;
}
/*! Example callback:
* This is called on commit. Identify modifications and adjust machine state
*/
int main_commit(clicon_handle h, transaction_data td) {
clicon_debug(1, "%s", __FUNCTION__);
transaction_log(h, td, 1, __FUNCTION__);
dump_datastore(h, "candidate");
return 0;
}
clixon_plugin_api *clixon_plugin_init(clicon_handle h);
static clixon_plugin_api api = {
"core", /* name */
clixon_plugin_init, /* init - must be called clixon_plugin_init */
.ca_trans_validate = main_validate, /* trans validate */
.ca_trans_commit = main_commit, /* trans commit */
};
clixon_plugin_api *clixon_plugin_init(clicon_handle h) { return &api; }
Open clixon cli, write:
set parameter A value B
commit
copy running startup
set parameter A value A
Fixed by always clearing db on startup.
Actually, this wasnt really an error, since candidate is not really a part of the startup mechanism, but I agree it could cause side-effect problems that candidate retained state from the previous run.
Please verify?
Description
xmldb_get0 with "candidate" as db will yield invalid results if it has been called on a validate/commit callback in a context of the first backend transaction.
Instead of returning the startup config as expected, it will return the candidate state as it was on the previous backend run.
Example
Compile the following simple backend plugin:
Open clixon cli, write:
Restart backend.
Expected result:
Actual:
Notes
Looks like simply clearing the candidate database on plugin init solves the issue.
The text was updated successfully, but these errors were encountered: