Skip to content

Commit

Permalink
[pull config from device also does commit local config](#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
olofhagsand committed Dec 19, 2023
1 parent 01bbef5 commit bdbd3ad
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 11 additions & 5 deletions src/controller_device_recv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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){
Expand Down
47 changes: 47 additions & 0 deletions test/test-c-service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<hello xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<capabilities>
<capability>urn:ietf:params:netconf:base:1.0</capability>
</capabilities>
</hello>]]>]]>
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"
xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0"
message-id="42">
<edit-config>
<target><candidate/></target>
<default-operation>none</default-operation>
<config>
<services xmlns="http://clicon.org/controller">
<testA xmlns="urn:example:test" nc:operation="replace">
<name>fie</name>
<params>ZZ</params>
</testA>
</services>
</config>
</edit-config>
</rpc>]]>]]>
EOF
)

match=$(echo "$ret" | grep --null -Eo "<rpc-error>") || true
if [ -n "$match" ]; then
err "<ok/>" "$ret"
fi

new "show compare service"
expectpart "$($clixon_cli -1 -f $CFG -m configure show compare xml)" 0 "^+\ *<services xmlns=\"http://clicon.org/controller\">" "^+\ *<testA xmlns=\"urn:example:test\">" "^+\ *<name>fie</name>" "^+\ *<params>ZZ</params>"

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 "^+\ *<services xmlns=\"http://clicon.org/controller\">" "^+\ *<testA xmlns=\"urn:example:test\">" "^+\ *<name>fie</name>" "^+\ *<params>ZZ</params>"

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)
Expand Down

0 comments on commit bdbd3ad

Please sign in to comment.