General-purpose upgrade

This commit is contained in:
Olof hagsand 2020-02-12 16:40:52 +01:00
parent 3748eefb8e
commit b6812793f9
18 changed files with 286 additions and 165 deletions

View file

@ -67,6 +67,7 @@
#include "clixon_yang.h"
#include "clixon_xml.h"
#include "clixon_xml_sort.h"
#include "clixon_yang_module.h"
#include "clixon_options.h"
#include "clixon_plugin.h"
#include "clixon_xpath_ctx.h"

View file

@ -69,12 +69,11 @@
#include "clixon_file.h"
#include "clixon_yang.h"
#include "clixon_xml.h"
#include "clixon_yang_module.h"
#include "clixon_plugin.h"
#include "clixon_options.h"
#include "clixon_data.h"
#include "clixon_yang_module.h"
#include "clixon_datastore.h"
#include "clixon_datastore_write.h"
#include "clixon_datastore_read.h"

View file

@ -245,7 +245,8 @@ text_read_modstate(clicon_handle h,
if ((xmodst = xml_find_type(xt, NULL, "modules-state", CX_ELMNT)) == NULL){
/* 1) There is no modules-state info in the file */
}
else if (xmcache && msd){
else if (xmcache && msd){ /* There is module state. */
msd->md_status = 1;
/* Create diff trees */
if (xml_parse_string("<modules-state xmlns=\"urn:ietf:params:xml:ns:yang:ietf-yang-library\"/>", yspec, &msd->md_del) < 0)
goto done;
@ -258,6 +259,13 @@ text_read_modstate(clicon_handle h,
/* 3) For each module state m in the file */
while ((xm = xml_child_each(xmodst, xm, CX_ELMNT)) != NULL) {
if (strcmp(xml_name(xm), "module-set-id") == 0){
if (xml_body(xm) && (msd->md_set_id = strdup(xml_body(xm))) == NULL){
clicon_err(OE_UNIX, errno, "strdup");
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)

View file

@ -59,6 +59,7 @@
#include "clixon_handle.h"
#include "clixon_yang.h"
#include "clixon_xml.h"
#include "clixon_yang_module.h"
#include "clixon_plugin.h"
/* List of plugins XXX
@ -467,27 +468,34 @@ clixon_plugin_extension(clicon_handle h,
}
return retval;
}
/*! Call plugin module repair in all plugins
/*! Call plugingeneral-purpose datastore upgrade in all plugins
*
* Repair datastore on load before or as an alternative to the upgrading mechanism
* @param[in] h Clicon handle
* @param[in] db Name of datastore, eg "running", "startup" or "tmp"
* @param[in] xt XML tree. Upgrade this "in place"
* @param[in] msd Module-state diff, info on datastore module-state
* @retval -1 Error
* @retval 0 OK
* Upgrade datastore on load before or as an alternative to module-specific upgrading mechanism
* @param[in] h Clicon handle
* Call plugin start functions (if defined)
* @note Start functions used to have argc/argv. Use clicon_argv_get() instead
*/
int
clixon_plugin_xmldb_repair(clicon_handle h,
char *db,
cxobj *xt)
clixon_plugin_datastore_upgrade(clicon_handle h,
char *db,
cxobj *xt,
modstate_diff_t *msd)
{
clixon_plugin *cp;
int i;
xmldb_repair_t *repairfn;
datastore_upgrade_t *repairfn;
for (i = 0; i < _clixon_nplugins; i++) {
cp = &_clixon_plugins[i];
if ((repairfn = cp->cp_api.ca_xmldb_repair) == NULL)
if ((repairfn = cp->cp_api.ca_datastore_upgrade) == NULL)
continue;
if (repairfn(h, db, xt) < 0) {
if (repairfn(h, db, xt, msd) < 0) {
clicon_debug(1, "%s() failed", __FUNCTION__);
return -1;
}

View file

@ -64,6 +64,7 @@
#include "clixon_xml.h"
#include "clixon_options.h"
#include "clixon_data.h"
#include "clixon_yang_module.h"
#include "clixon_plugin.h"
#include "clixon_string.h"
#include "clixon_xpath_ctx.h"

View file

@ -64,6 +64,7 @@
#include "clixon_yang.h"
#include "clixon_xml.h"
#include "clixon_options.h"
#include "clixon_yang_module.h"
#include "clixon_plugin.h"
#include "clixon_xml_nsctx.h"
#include "clixon_xpath_ctx.h"
@ -708,7 +709,7 @@ xml_tree_prune_flagged(cxobj *xt,
/*! Add prefix:namespace pair to xml node, set cache, prefix, etc
*/
int
static int
add_namespace(cxobj *x1, /* target */
cxobj *x1p,
char *prefix1,
@ -746,6 +747,49 @@ add_namespace(cxobj *x1, /* target */
return retval;
}
/*! Change namespace of XML node
*
* @param[in] x XML node
* @param[in] namespace Change to this namespace (if it does not already belong to it)
* @param[in] prefix If change, use this namespace
* @param 0 OK
* @param -1 Error
*/
int
xml_namespace_change(cxobj *x,
char *namespace,
char *prefix)
{
int retval = -1;
cxobj *xp;
char *ns0 = NULL; /* existing namespace */
char *prefix0 = NULL; /* existing prefix */
ns0 = NULL;
if (xml2ns(x, xml_prefix(x), &ns0) < 0)
goto done;
if (strcmp(ns0, namespace) == 0)
goto ok; /* Already has right namespace */
/* Is namespace already declared? */
if (xml2prefix(x, namespace, &prefix0) == 1){
/* Yes it is declared and the prefix is pexists */
if (xml_prefix_set(x, prefix0) < 0)
goto done;
}
else{ /* Namespace does not exist, add it */
if ((xp = xml_parent(x)) == NULL){
clicon_err(OE_XML, ENOENT, "XML node must have parent");
goto done;
}
if (add_namespace(x, xp, prefix0, namespace) < 0)
goto done;
}
ok:
retval = 0;
done:
return retval;
}
/*! Add default values (if not set)
* @param[in] xt XML tree with some node marked
* @param[in] arg Ignored

View file

@ -122,11 +122,11 @@ static const map_str2int xpath_tree_map[] = {
static const map_str2int axis_type_map[] = {
{"NaN", A_NAN},
{"ancestor", A_ANCESTOR},
{"ancestor-or-selgf", A_ANCESTOR_OR_SELF},
{"ancestor-or-self", A_ANCESTOR_OR_SELF},
{"attribute", A_ATTRIBUTE},
{"child", A_CHILD},
{"descendant", A_DESCENDANT},
{"descendeant-or-self", A_DESCENDANT_OR_SELF},
{"descendant-or-self", A_DESCENDANT_OR_SELF},
{"following", A_FOLLOWING},
{"following-sibling", A_FOLLOWING_SIBLING},
{"namespace", A_NAMESPACE},

View file

@ -362,8 +362,19 @@ xp_eval_step(xp_ctx *xc0,
}
ctx_nodeset_replace(xc, vec, veclen);
break;
case A_DESCENDANT:
case A_DESCENDANT_OR_SELF:
for (i=0; i<xc->xc_size; i++){
xv = xc->xc_nodeset[i];
if (nodetest_recursive(xv, xs->xs_c0, CX_ELMNT, 0x0, nsc, localonly, &vec, &veclen) < 0)
goto done;
}
for (i=0; i<veclen; i++){
x = vec[i];
if (cxvec_append(x, &xc->xc_nodeset, &xc->xc_size) < 0)
goto done;
}
break;
case A_DESCENDANT:
for (i=0; i<xc->xc_size; i++){
xv = xc->xc_nodeset[i];
if (nodetest_recursive(xv, xs->xs_c0, CX_ELMNT, 0x0, nsc, localonly, &vec, &veclen) < 0)

View file

@ -87,6 +87,7 @@
#include "clixon_yang.h"
#include "clixon_hash.h"
#include "clixon_xml.h"
#include "clixon_yang_module.h"
#include "clixon_plugin.h"
#include "clixon_data.h"
#include "clixon_options.h"

View file

@ -74,10 +74,10 @@
#include "clixon_xpath.h"
#include "clixon_options.h"
#include "clixon_data.h"
#include "clixon_yang_module.h"
#include "clixon_plugin.h"
#include "clixon_netconf_lib.h"
#include "clixon_xml_map.h"
#include "clixon_yang_module.h"
#include "clixon_yang_internal.h" /* internal */
modstate_diff_t *
@ -97,6 +97,8 @@ modstate_diff_free(modstate_diff_t *md)
{
if (md == NULL)
return 0;
if (md->md_set_id)
free(md->md_set_id);
if (md->md_del)
xml_free(md->md_del);
if (md->md_mod)

View file

@ -94,6 +94,7 @@
#include "clixon_yang.h"
#include "clixon_hash.h"
#include "clixon_xml.h"
#include "clixon_yang_module.h"
#include "clixon_plugin.h"
#include "clixon_options.h"
#include "clixon_yang.h"