From bdbd3adfc5bdff5d471f516ccffa1293d5347d40 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Tue, 19 Dec 2023 22:23:14 +0100 Subject: [PATCH] [pull config from device also does commit local config](https://github.com/clicon/clixon-controller/issues/82) --- CHANGELOG.md | 1 + src/controller_device_recv.c | 16 ++++++++---- test/test-c-service.sh | 47 ++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5c2dd6..0e478e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ Expected: February 2024 ### Corrected Bugs +* Fixed: [pull config from device also does commit local config](https://github.com/clicon/clixon-controller/issues/82) * Fixed: [Commit don't push configuration if service is configured](https://github.com/clicon/clixon-controller/issues/78) * Fixed: ["commit diff" after applying a service always seems to show a diff](https://github.com/clicon/clixon-controller/issues/70) * Fixed: [Backend may exit with assertion if the device return warnings](https://github.com/clicon/clixon-controller/issues/77) diff --git a/src/controller_device_recv.c b/src/controller_device_recv.c index 646dce4..6d02e10 100644 --- a/src/controller_device_recv.c +++ b/src/controller_device_recv.c @@ -321,11 +321,16 @@ device_state_recv_config(clixon_handle h, } goto ok; } - if ((ret = xmldb_put(h, "candidate", OP_NONE, xt, NULL, cbret)) < 0) + /* + * Write changed device to tmp-db, make a regular commit from tmp-db + * If not revert, write changed device to candidate + */ + if (xmldb_copy(h, "running", "tmp") < 0) + goto done; + if ((ret = xmldb_put(h, "tmp", OP_NONE, xt, NULL, cbret)) < 0) goto done; if (ret == 1){ - /* XXX trigger plugin which starts a commit transaction */ - if ((ret = candidate_commit(h, NULL, "candidate", 0, 0, cbret)) < 0){ + if ((ret = candidate_commit(h, NULL, "tmp", 0, 0, cbret)) < 0){ /* Handle that candidate_commit can return < 0 if transaction ongoing */ cprintf(cbret, "%s", clixon_err_reason()); ret = 0; @@ -340,8 +345,6 @@ device_state_recv_config(clixon_handle h, } } if (ret == 0){ /* discard */ - xmldb_copy(h, "running", "candidate"); - xmldb_modified_set(h, "candidate", 0); /* reset dirty bit */ clixon_debug(CLIXON_DBG_DEFAULT, "%s", cbuf_get(cbret)); if (device_close_connection(dh, "Failed to commit: %s", cbuf_get(cbret)) < 0) goto done; @@ -350,6 +353,9 @@ device_state_recv_config(clixon_handle h, else { device_handle_sync_time_set(dh, NULL); } + if ((ret = xmldb_put(h, "candidate", OP_NONE, xt, NULL, cbret)) < 0) + goto done; + xmldb_delete(h, "tmp"); if ((ret = device_config_write(h, name, "SYNCED", xt, cbret)) < 0) goto done; if (ret == 0){ diff --git a/test/test-c-service.sh b/test/test-c-service.sh index 7cb66ca..45d3bb2 100755 --- a/test/test-c-service.sh +++ b/test/test-c-service.sh @@ -605,6 +605,53 @@ if [ -n "$match" ]; then err "Bx is removed in $NAME" "$ret" fi + +# Edit service, pull, check service still in candidate, +# see https://github.com/clicon/clixon-controller/issues/82 +new "edit testC" +ret=$(${clixon_netconf} -0 -f $CFG < + + + urn:ietf:params:netconf:base:1.0 + +]]>]]> + + + + none + + + + fie + ZZ + + + + +]]>]]> +EOF +) + +match=$(echo "$ret" | grep --null -Eo "") || true +if [ -n "$match" ]; then + err "" "$ret" +fi + +new "show compare service" +expectpart "$($clixon_cli -1 -f $CFG -m configure show compare xml)" 0 "^+\ *" "^+\ *" "^+\ *fie" "^+\ *ZZ" + +new "Pull replace" +expectpart "$(${clixon_cli} -1f $CFG pull)" 0 "" + +new "Verify show compare still there" +expectpart "$($clixon_cli -1 -f $CFG -m configure show compare xml)" 0 "^+\ *" "^+\ *" "^+\ *fie" "^+\ *ZZ" + +new "Rollback hostnames on openconfig*" +expectpart "$($clixon_cli -1 -f $CFG -m configure rollback)" 0 "" + # Negative errors new "Create empty testA" ret=$(${clixon_cli} -m configure -1f $CFG set services testA foo 2> /dev/null)