lib: make nb_candidate_edit() more flexible

Certain operations, like removing non-presence containers or
modifying list keys, are not considered to be valid from the
perspective of the northbound layer. This is because we want to
implement a minimum set of northbound configuration callbacks and
use them to process all possible configuration changes.

The removal of a np-container [1], for example, can be processed by
calling the "delete" callback of all of its child nodes (recursion
is used for np-container child nodes). Similarly, the modification
of a list key can be processed as if the corresponding list entry
was removed and readded with updated key values. This strategy saves
us the burden of implementing lots of extra configuration callbacks.

That said, the nb_operation_is_valid() function shouldn't be used
for anything other than checking which callbacks are valid for
which YANG nodes. Using it in the nb_candidate_edit() function
is inappropriate as we want as much flexibility as possible when
editing a candidate configuration. We should allow CLI commands,
for example, to remove np-containers (the northbound layer will then
figure out which callbacks need to be called when this candidate
is committed). Remove the check.

[1] We can't do the same for presence containers since they have a
"create" callback associated with them.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
Renato Westphal 2019-04-15 19:04:30 -03:00
parent c650e48c54
commit ec3ee0ebb8

View File

@ -454,13 +454,6 @@ int nb_candidate_edit(struct nb_config *candidate,
struct lyd_node *dnode;
char xpath_edit[XPATH_MAXLEN];
if (!nb_operation_is_valid(operation, nb_node->snode)) {
flog_warn(EC_LIB_NB_CANDIDATE_EDIT_ERROR,
"%s: %s operation not valid for %s", __func__,
nb_operation_name(operation), xpath);
return NB_ERR;
}
/* Use special notation for leaf-lists (RFC 6020, section 9.13.5). */
if (nb_node->snode->nodetype == LYS_LEAFLIST)
snprintf(xpath_edit, sizeof(xpath_edit), "%s[.='%s']", xpath,