diff --git a/example/main/example_backend_nacm.c b/example/main/example_backend_nacm.c index 8258b372..77c1f5bd 100644 --- a/example/main/example_backend_nacm.c +++ b/example/main/example_backend_nacm.c @@ -100,11 +100,19 @@ nacm_validate(clixon_handle h, if (_transaction_log) transaction_log(h, td, LOG_NOTICE, __FUNCTION__); if (_validate_fail_xpath){ - if (_validate_fail_toggle==0 && - xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){ - _validate_fail_toggle = 1; /* toggle if triggered */ - clixon_err(OE_XML, 0, "User error"); - return -1; /* induce fail */ + if (xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)) { + if (_validate_fail_toggle==0) { + _validate_fail_toggle = 1; /* toggle if triggered */ + clixon_err(OE_XML, 0, "User error"); + return -1; /* induce fail */ + } else if (_validate_fail_toggle==2) { + _validate_fail_toggle = 0; /* toggle if triggered */ + clixon_plugin_rpc_err(h, NULL, + "application", "test_error_tag", + "test_error_info", "error", + "test_error_data %d", 1234); + return -1; /* induce fail */ + } } } return 0; @@ -130,7 +138,7 @@ nacm_commit(clixon_handle h, if (_validate_fail_xpath){ if (_validate_fail_toggle==1 && xpath_first(transaction_target(td), NULL, "%s", _validate_fail_xpath)){ - _validate_fail_toggle = 0; /* toggle if triggered */ + _validate_fail_toggle = 2; /* toggle if triggered */ clixon_err(OE_XML, 0, "User error"); return -1; /* induce fail */ } diff --git a/test/test_transaction.sh b/test/test_transaction.sh index 1745d9ca..7837a424 100755 --- a/test/test_transaction.sh +++ b/test/test_transaction.sh @@ -11,7 +11,8 @@ # 4. Validate user-error (invalidation by user callback) # 5. Commit user-error (invalidation by user callback) # -- to here only basic callback tests (that they occur). Below transaction data -# 6. Detailed transaction vector add/del/change tests +# 6. Validate user-error with plugin_rpc_err (invalidation by user callback) +# 7. Detailed transaction vector add/del/change tests # For the last test, the yang is a list with three members, so that you can do # add/delete/change in a single go. # The user-error uses a trick feature in the example nacm plugin which is started @@ -277,7 +278,34 @@ for op in abort; do let line++ done -# 6. Detailed transaction vector add/del/change tests +# 6. Validate only user-error with plugin_rpc_err (invalidation by user callback) +# XXX Note Commit user-error must immediately preceede this due to toggling +# in nacm/transaction example test module +let nr++ +new "6. Validate user-error with plugin_rpc_err ($errnr is invalid)" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "$errnr99" "" "" + +new "Validate user-error validate (should fail)" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "applicationtest_error_tagerrortest_error_infotest_error_data 1234" + +new "Validate user-error discard-changes" +expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" + +for op in begin validate; do + checklog "$nr main_$op add: $errnr99" $line + let line++ + checklog "$nr nacm_$op add: $errnr99" $line + let line++ +done +# No error message here, don't increment line. +for op in abort; do + checklog "$nr main_$op add: $errnr99" $line + let line++ + checklog "$nr nacm_$op add: $errnr99" $line + let line++ +done + +# 7. Detailed transaction vector add/del/change tests let nr++ let base=nr new "Add base $base entry" @@ -289,7 +317,7 @@ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" " let line+=12 let nr++ -new "6. netconf mixed change: change b, del c, add d" +new "7. netconf mixed change: change b, del c, add d" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "$base420" "" "" new "netconf commit change" @@ -325,7 +353,7 @@ let line+=12 # Variant check that only b,c let nr++ -new "7. netconf insert b,c between end-points" +new "8. netconf insert b,c between end-points" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "$base11" "" "" new "netconf commit base" @@ -339,7 +367,7 @@ for op in begin validate complete commit commit_done end; do let line++ done -new "8. Choice" +new "9. Choice" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "true" "" "" new "netconf commit same" @@ -374,7 +402,7 @@ let line++ checklog "$nr nacm_end add: true" $line let line++ -new "9. Choice/case with empty type" +new "10. Choice/case with empty type" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "" "" "" new "netconf commit first" @@ -411,7 +439,7 @@ let line++ #--------------------------------------------- -new "10. Choice/case with anydata" +new "11. Choice/case with anydata" expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "a" "" "" new "netconf commit first"