Skip to content

Commit 958acaa

Browse files
committed
common UPDATE error-path in XML format
Updated libyang supports format-specific error-path.
1 parent b59a20c commit 958acaa

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ endif()
4444
set(NP2SRV_VERSION 2.4.0)
4545

4646
# libyang required version
47-
set(LIBYANG_DEP_VERSION 3.9.0)
48-
set(LIBYANG_DEP_SOVERSION 3.8.0)
47+
set(LIBYANG_DEP_VERSION 3.12.0)
48+
set(LIBYANG_DEP_SOVERSION 3.9.0)
4949
set(LIBYANG_DEP_SOVERSION_MAJOR 3)
5050

5151
# libnetconf2 required version

src/common.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,34 +1390,39 @@ np_err_reply_get_quoted_string(const char *msg, uint32_t index)
13901390
* @param[in] error_info_elem Array of NETCONF error-info elements.
13911391
* @param[in] error_info_val Array of NETCONF error-info element values.
13921392
* @param[in] error_info_count Count of items in @p error_info_elem and @p error_info_val.
1393-
* @return NC rpc-error opaque node tree.
1393+
* @return NC rpc-error node tree.
13941394
*/
13951395
static struct lyd_node *
13961396
np_err_create(const struct ly_ctx *ly_ctx, const char *error_type, const char *error_tag, const char *error_app_tag,
13971397
const char *error_path, const char *error_message, const char **error_info_elem, const char **error_info_val,
13981398
uint32_t error_info_count)
13991399
{
1400+
const struct lys_module *nc_mod;
14001401
struct lyd_node *e_first = NULL, *e, *err_info;
14011402
const char *ns;
14021403
uint32_t i;
14031404

1405+
/* get ietf-netconf module */
1406+
nc_mod = ly_ctx_get_module_implemented(ly_ctx, "ietf-netconf");
1407+
assert(nc_mod);
1408+
14041409
/* rpc-error */
1405-
if (lyd_new_opaq2(NULL, ly_ctx, "rpc-error", NULL, NULL, NC_NS_BASE, &e)) {
1410+
if (lyd_new_inner(NULL, nc_mod, "rpc-error", 0, &e)) {
14061411
goto error;
14071412
}
14081413

14091414
/* error-type */
1410-
if (lyd_new_opaq2(e, NULL, "error-type", error_type, NULL, NC_NS_BASE, NULL)) {
1415+
if (lyd_new_term(e, NULL, "error-type", error_type, 0, NULL)) {
14111416
goto error;
14121417
}
14131418

14141419
/* error-tag */
1415-
if (lyd_new_opaq2(e, NULL, "error-tag", error_tag, NULL, NC_NS_BASE, NULL)) {
1420+
if (lyd_new_term(e, NULL, "error-tag", error_tag, 0, NULL)) {
14161421
goto error;
14171422
}
14181423

14191424
/* error-severity */
1420-
if (lyd_new_opaq2(e, NULL, "error-severity", "error", NULL, NC_NS_BASE, NULL)) {
1425+
if (lyd_new_term(e, NULL, "error-severity", "error", 0, NULL)) {
14211426
goto error;
14221427
}
14231428

tests/test_error.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ test_max_elem(void **state)
127127
" <error-tag>operation-failed</error-tag>\n"
128128
" <error-severity>error</error-severity>\n"
129129
" <error-app-tag>too-many-elements</error-app-tag>\n"
130-
" <error-path>/errors:cont/l2[k='key3']</error-path>\n"
130+
" <error-path xmlns:e=\"urn:errors\">/e:cont/e:l2[e:k='key3']</error-path>\n"
131131
" <error-message xml:lang=\"en\">Too many elements.</error-message>\n"
132132
"</rpc-error>\n");
133133
FREE_TEST_VARS(st);
@@ -150,7 +150,7 @@ test_min_elem(void **state)
150150
" <error-tag>operation-failed</error-tag>\n"
151151
" <error-severity>error</error-severity>\n"
152152
" <error-app-tag>too-few-elements</error-app-tag>\n"
153-
" <error-path>/errors:cont2/l3[.='value']</error-path>\n"
153+
" <error-path xmlns:e=\"urn:errors\">/e:cont2/e:l3[.='value']</error-path>\n"
154154
" <error-message xml:lang=\"en\">Too few elements.</error-message>\n"
155155
"</rpc-error>\n");
156156
FREE_TEST_VARS(st);
@@ -173,7 +173,7 @@ test_must(void **state)
173173
" <error-tag>operation-failed</error-tag>\n"
174174
" <error-severity>error</error-severity>\n"
175175
" <error-app-tag>must-violation</error-app-tag>\n"
176-
" <error-path>/errors:l4</error-path>\n"
176+
" <error-path xmlns:e=\"urn:errors\">/e:l4</error-path>\n"
177177
" <error-message xml:lang=\"en\">Must condition \"/cont/l/k = 'key'\" not satisfied.</error-message>\n"
178178
"</rpc-error>\n");
179179
FREE_TEST_VARS(st);
@@ -196,7 +196,7 @@ test_require_instance(void **state)
196196
" <error-tag>data-missing</error-tag>\n"
197197
" <error-severity>error</error-severity>\n"
198198
" <error-app-tag>instance-required</error-app-tag>\n"
199-
" <error-path>/errors:l5</error-path>\n"
199+
" <error-path xmlns:e=\"urn:errors\">/e:l5</error-path>\n"
200200
" <error-message xml:lang=\"en\">Required leafref target with value \"val\" missing.</error-message>\n"
201201
"</rpc-error>\n");
202202
FREE_TEST_VARS(st);
@@ -211,7 +211,7 @@ test_require_instance(void **state)
211211
" <error-tag>data-missing</error-tag>\n"
212212
" <error-severity>error</error-severity>\n"
213213
" <error-app-tag>instance-required</error-app-tag>\n"
214-
" <error-path>/errors:l6</error-path>\n"
214+
" <error-path xmlns:e=\"urn:errors\">/e:l6</error-path>\n"
215215
" <error-message xml:lang=\"en\">Required instance-identifier \"/errors:target\" missing.</error-message>\n"
216216
"</rpc-error>\n");
217217
FREE_TEST_VARS(st);
@@ -234,7 +234,7 @@ test_mandatory_choice(void **state)
234234
" <error-tag>data-missing</error-tag>\n"
235235
" <error-severity>error</error-severity>\n"
236236
" <error-app-tag>mandatory-choice</error-app-tag>\n"
237-
" <error-path>/errors:cont3</error-path>\n"
237+
" <error-path xmlns:e=\"urn:errors\">/e:cont3</error-path>\n"
238238
" <error-message xml:lang=\"en\">Missing mandatory choice.</error-message>\n"
239239
" <error-info>\n"
240240
" <missing-choice xmlns=\"urn:ietf:params:xml:ns:yang:1\">ch</missing-choice>\n"
@@ -387,7 +387,7 @@ test_bad_element(void **state)
387387
" <error-type>application</error-type>\n"
388388
" <error-tag>bad-element</error-tag>\n"
389389
" <error-severity>error</error-severity>\n"
390-
" <error-path>/errors:num</error-path>\n"
390+
" <error-path xmlns:e=\"urn:errors\">/e:num</error-path>\n"
391391
" <error-message xml:lang=\"en\">Invalid non-number-encoded uint16 value \"string\".</error-message>\n"
392392
" <error-info>\n"
393393
" <bad-element>num</bad-element>\n"
@@ -404,7 +404,7 @@ test_bad_element(void **state)
404404
" <error-type>application</error-type>\n"
405405
" <error-tag>bad-element</error-tag>\n"
406406
" <error-severity>error</error-severity>\n"
407-
" <error-path>/errors:num</error-path>\n"
407+
" <error-path xmlns:e=\"urn:errors\">/e:num</error-path>\n"
408408
" <error-message xml:lang=\"en\">Unsatisfied range - value \"5\" is out of the allowed range.</error-message>\n"
409409
" <error-info>\n"
410410
" <bad-element>num</bad-element>\n"
@@ -421,7 +421,7 @@ test_bad_element(void **state)
421421
" <error-type>application</error-type>\n"
422422
" <error-tag>bad-element</error-tag>\n"
423423
" <error-severity>error</error-severity>\n"
424-
" <error-path>/errors:num</error-path>\n"
424+
" <error-path xmlns:e=\"urn:errors\">/e:num</error-path>\n"
425425
" <error-message xml:lang=\"en\">Value \"100000\" is out of type uint16 min/max bounds.</error-message>\n"
426426
" <error-info>\n"
427427
" <bad-element>num</bad-element>\n"
@@ -438,7 +438,7 @@ test_bad_element(void **state)
438438
" <error-type>application</error-type>\n"
439439
" <error-tag>bad-element</error-tag>\n"
440440
" <error-severity>error</error-severity>\n"
441-
" <error-path>/errors:str</error-path>\n"
441+
" <error-path xmlns:e=\"urn:errors\">/e:str</error-path>\n"
442442
" <error-message xml:lang=\"en\">Unsatisfied pattern - \"bb\" does not conform to \"a*\".</error-message>\n"
443443
" <error-info>\n"
444444
" <bad-element>str</bad-element>\n"

tests/test_other_client.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ test_missing_element(void **state)
294294
"<error-tag>data-missing</error-tag>"
295295
"<error-severity>error</error-severity>"
296296
"<error-app-tag>mandatory-choice</error-app-tag>"
297-
"<error-path>/ietf-netconf-nmda:edit-data</error-path>"
297+
"<error-path xmlns:ncds=\"urn:ietf:params:xml:ns:yang:ietf-netconf-nmda\">/ncds:edit-data</error-path>"
298298
"<error-message xml:lang=\"en\">Missing mandatory choice.</error-message>"
299299
"<error-info>"
300300
"<missing-choice xmlns=\"urn:ietf:params:xml:ns:yang:1\">edit-content</missing-choice>"
@@ -317,7 +317,7 @@ test_missing_element(void **state)
317317
"<error-type>protocol</error-type>"
318318
"<error-tag>missing-element</error-tag>"
319319
"<error-severity>error</error-severity>"
320-
"<error-path>/ietf-netconf-monitoring:get-schema</error-path>"
320+
"<error-path xmlns:ncm=\"urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring\">/ncm:get-schema</error-path>"
321321
"<error-message xml:lang=\"en\">An expected element is missing.</error-message>"
322322
"<error-info><bad-element>identifier</bad-element></error-info>"
323323
"</rpc-error></rpc-reply>", sess->msgid);
@@ -342,7 +342,7 @@ test_missing_element(void **state)
342342
"<error-tag>data-missing</error-tag>"
343343
"<error-severity>error</error-severity>"
344344
"<error-app-tag>mandatory-choice</error-app-tag>"
345-
"<error-path>/ietf-netconf:get-config/source</error-path>"
345+
"<error-path xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">/nc:get-config/nc:source</error-path>"
346346
"<error-message xml:lang=\"en\">Missing mandatory choice.</error-message>"
347347
"<error-info><missing-choice xmlns=\"urn:ietf:params:xml:ns:yang:1\">config-source</missing-choice></error-info>"
348348
"</rpc-error></rpc-reply>", sess->msgid);

tests/test_rpc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ test_kill(void **state)
313313
" <error-type>protocol</error-type>\n"
314314
" <error-tag>access-denied</error-tag>\n"
315315
" <error-severity>error</error-severity>\n"
316-
" <error-path>/ietf-netconf:kill-session</error-path>\n"
316+
" <error-path xmlns:nc=\"urn:ietf:params:xml:ns:netconf:base:1.0\">/nc:kill-session</error-path>\n"
317317
" <error-message xml:lang=\"en\">Executing the operation is denied "
318318
"because \"%s\" NACM authorization failed.</error-message>\n"
319319
" </rpc-error>\n"

0 commit comments

Comments
 (0)