From fa257ebb88cba656b3091f1a6b3cdf6c8cc7ddab Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Wed, 12 Feb 2020 17:37:23 +0100 Subject: [PATCH] datastore upgrade bugs --- example/main/example_backend.c | 25 +++++++++++++++++-------- lib/src/clixon_datastore_read.c | 1 - lib/src/clixon_xpath_eval.c | 4 ++++ test/test_datastore_repair.sh | 6 +++--- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/example/main/example_backend.c b/example/main/example_backend.c index 27035ce9..a12679dc 100644 --- a/example/main/example_backend.c +++ b/example/main/example_backend.c @@ -71,11 +71,15 @@ static int _reset = 0; */ static int _state = 0; -/*! Variable to control upgrade callbacks. +/*! Variable to control module-specific upgrade callbacks. * If set, call test-case for upgrading ietf-interfaces, otherwise call * auto-upgrade */ -static int _upgrade = 0; +static int _module_upgrade = 0; + +/*! Variable to control general-purpose upgrade callbacks. + */ +static int _general_upgrade = 0; /*! Variable to control transaction logging (for debug) * If set, call syslog for every transaction callback @@ -456,9 +460,11 @@ example_upgrade(clicon_handle h, int i; const char **pp; + if (_general_upgrade == 0) + goto ok; if (strcmp(db, "startup") != 0) /* skip other than startup datastore */ goto ok; - if (msd->md_status) /* skip if there is proper module-state in datastore */ + if (msd && msd->md_status) /* skip if there is proper module-state in datastore */ goto ok; yspec = clicon_dbspec_yang(h); /* Get all yangs */ /* Get canonical namespaces for using "normalized" prefixes */ @@ -793,7 +799,7 @@ static clixon_plugin_api api = { .ca_trans_revert=main_revert, /* trans revert */ .ca_trans_end=main_end, /* trans end */ .ca_trans_abort=main_abort, /* trans abort */ - .ca_datastore_upgrade=example_upgrade /* gneral-purpose upgrade. */ + .ca_datastore_upgrade=example_upgrade /* general-purpose upgrade. */ }; /*! Backend plugin initialization @@ -818,7 +824,7 @@ clixon_plugin_init(clicon_handle h) goto done; opterr = 0; optind = 1; - while ((c = getopt(argc, argv, "rsut:")) != -1) + while ((c = getopt(argc, argv, "rsuUt:")) != -1) switch (c) { case 'r': _reset = 1; @@ -826,8 +832,11 @@ clixon_plugin_init(clicon_handle h) case 's': _state = 1; break; - case 'u': - _upgrade = 1; + case 'u': /* module-specific upgrade */ + _module_upgrade = 1; + break; + case 'U': /* general-purpose upgrade */ + _general_upgrade = 1; break; case 't': /* transaction log */ _transaction_log = 1; @@ -885,7 +894,7 @@ clixon_plugin_init(clicon_handle h) /* Upgrade callback: if you start the backend with -- -u you will get the * test interface example. Otherwise the auto-upgrade feature is enabled. */ - if (_upgrade){ + if (_module_upgrade == 1){ if (upgrade_callback_register(h, upgrade_2016, "urn:example:interfaces", 20140508, 20160101, NULL) < 0) goto done; if (upgrade_callback_register(h, upgrade_2018, "urn:example:interfaces", 20160101, 20180220, NULL) < 0) diff --git a/lib/src/clixon_datastore_read.c b/lib/src/clixon_datastore_read.c index ab0d16e1..2bcc10dd 100644 --- a/lib/src/clixon_datastore_read.c +++ b/lib/src/clixon_datastore_read.c @@ -265,7 +265,6 @@ text_read_modstate(clicon_handle h, goto done; } } - continue; /* ignore other tags, such as module-set-id */ if (strcmp(xml_name(xm), "module")) continue; /* ignore other tags, such as module-set-id */ if ((name = xml_find_body(xm, "name")) == NULL) diff --git a/lib/src/clixon_xpath_eval.c b/lib/src/clixon_xpath_eval.c index f712fcad..1c3a7b77 100644 --- a/lib/src/clixon_xpath_eval.c +++ b/lib/src/clixon_xpath_eval.c @@ -373,6 +373,10 @@ xp_eval_step(xp_ctx *xc0, if (cxvec_append(x, &xc->xc_nodeset, &xc->xc_size) < 0) goto done; } + if (vec){ + free(vec); + vec = NULL; + } break; case A_DESCENDANT: for (i=0; ixc_size; i++){ diff --git a/test/test_datastore_repair.sh b/test/test_datastore_repair.sh index 2a98d1e6..640e9b48 100755 --- a/test/test_datastore_repair.sh +++ b/test/test_datastore_repair.sh @@ -81,7 +81,7 @@ EOF ) testrun(){ - new "test params: -f $cfg" + new "test params: -f $cfg -- -U" # Bring your own backend if [ $BE -ne 0 ]; then # kill old backend (if any) @@ -90,8 +90,8 @@ testrun(){ if [ $? -ne 0 ]; then err fi - new "start backend -s startup -f $cfg" - start_backend -s startup -f $cfg + new "start backend -s startup -f $cfg -- -U" + start_backend -s startup -f $cfg -- -U new "waiting" wait_backend