Skip to content

Commit 50f289b

Browse files
author
Per Andersson
committed
schema diff UPDATE support for yang-version diff
1 parent aead67e commit 50f289b

File tree

9 files changed

+152
-2
lines changed

9 files changed

+152
-2
lines changed

modules/ietf-yang-schema-comparison@2025-10-20.yang

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ module ietf-yang-schema-comparison {
304304
description
305305
"YANG statement 'when'.";
306306
}
307+
enum "yang-version" {
308+
description
309+
"YANG statement 'yang-version'.";
310+
}
307311
}
308312
description
309313
"Type of the statement that a change affects.";
@@ -914,6 +918,11 @@ module ietf-yang-schema-comparison {
914918
grouping module-substmts {
915919
description
916920
"All non-data-definition substatements of a module.";
921+
leaf yang-version {
922+
type string;
923+
description
924+
"YANG version substatement value.";
925+
}
917926
leaf prefix {
918927
if-feature parsed-schema;
919928
type string;

src/schema_diff.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ schema_diff_stmt2changed(enum ly_stmt stmt)
8989
case LY_STMT_SYNTAX_LEFT_BRACE:
9090
case LY_STMT_SYNTAX_RIGHT_BRACE:
9191
case LY_STMT_SYNTAX_SEMICOLON:
92-
case LY_STMT_YANG_VERSION:
9392
case LY_STMT_YIN_ELEMENT:
9493
/* invalid */
9594
LOGINT(NULL);
@@ -194,6 +193,8 @@ schema_diff_stmt2changed(enum ly_stmt stmt)
194193
return LYS_CHANGED_VALUE;
195194
case LY_STMT_WHEN:
196195
return LYS_CHANGED_WHEN;
196+
case LY_STMT_YANG_VERSION:
197+
return LYS_CHANGED_YANG_VERSION;
197198
}
198199

199200
return LYS_CHANGED_NONE;
@@ -587,6 +588,10 @@ schema_diff_module_identities_change(const struct lysc_ident *idents1, const str
587588
static LY_ERR
588589
schema_diff_module_change(const struct lys_module *mod1, const struct lys_module *mod2, struct lys_diff_s *diff)
589590
{
591+
/* yang-version */
592+
LY_CHECK_RET(schema_diff_yangversion_change(mod1->version, mod2->version, LYS_CHANGED_NONE, LYS_CHANGED_YANG_VERSION,
593+
&diff->module_changes));
594+
590595
/* organization */
591596
LY_CHECK_RET(schema_diff_text_bc(mod1->org, mod2->org, LYS_CHANGED_NONE, LYS_CHANGED_ORGANIZATION,
592597
&diff->module_changes));

src/schema_diff.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ enum lys_diff_changed_e {
9292
LYS_CHANGED_UNIQUE,
9393
LYS_CHANGED_UNITS,
9494
LYS_CHANGED_VALUE,
95-
LYS_CHANGED_WHEN
95+
LYS_CHANGED_WHEN,
96+
LYS_CHANGED_YANG_VERSION
9697
};
9798

9899
/**
@@ -440,6 +441,20 @@ LY_ERR schema_diff_ext_insts_change(const struct lysc_ext_instance *exts1, const
440441
*/
441442
LY_ERR schema_diff_nodes_change_r(const struct lysc_node *node1, const struct lysc_node *node2, struct lys_diff_s *diff);
442443

444+
/**
445+
* @brief Check changes of a 'yang-version'.
446+
*
447+
* @param[in] yvsn1 First yang-version.
448+
* @param[in] yvsn2 Second yang-version.
449+
* @param[in] parent_changed Parent statement of the change.
450+
* @param[in] changed Changed statement.
451+
* @param[in,out] changes Changes to add to.
452+
* @return LY_ERR value.
453+
*/
454+
LY_ERR schema_diff_yangversion_change(uint8_t yvsn1, uint8_t yvsn2,
455+
enum lys_diff_changed_e parent_changed, enum lys_diff_changed_e changed,
456+
struct lys_diff_changes_s *changes);
457+
443458
/**
444459
* @brief Check changes of an 'if-feature' array.
445460
*

src/schema_diff_change_parsed.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,20 @@ schema_diff_has_bc_pext(const struct ly_ctx *ctx, const struct lysp_ext_instance
391391
return 0;
392392
}
393393

394+
LY_ERR
395+
schema_diff_yangversion_change(uint8_t yvsn1, uint8_t yvsn2,
396+
enum lys_diff_changed_e parent_changed, enum lys_diff_changed_e changed,
397+
struct lys_diff_changes_s *changes)
398+
{
399+
if (yvsn1 != yvsn2) {
400+
/* modified */
401+
LY_CHECK_RET(schema_diff_add_change(LYS_CHANGE_MODIFIED, parent_changed,
402+
changed, 1, changes));
403+
}
404+
405+
return LY_SUCCESS;
406+
}
407+
394408
LY_ERR
395409
schema_diff_iffeatures_change(const struct lysp_qname *iffs1, uint16_t flags1, const struct lysp_qname *iffs2,
396410
enum lys_diff_changed_e parent_changed, struct lys_diff_changes_s *changes)

src/schema_diff_tree.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ schema_diff_changed2str(enum lys_diff_changed_e ch)
144144
return "unique";
145145
case LYS_CHANGED_WHEN:
146146
return "when";
147+
case LYS_CHANGED_YANG_VERSION:
148+
return "yang-version";
147149
}
148150

149151
return NULL;
@@ -1555,6 +1557,53 @@ schema_diff_imports(const struct lys_module *mod, const struct lysc_node *schema
15551557
return rc;
15561558
}
15571559

1560+
/**
1561+
* @brief Create cmp YANG data from direct text substatement of 'module'.
1562+
*
1563+
* @param[in] change Change to use.
1564+
* @param[in] mod1 Old module.
1565+
* @param[in] mod2 New module.
1566+
* @param[in] with_parsed Whether 'parsed-schema' feature is enabled.
1567+
* @param[in,out] diff_list Node to append to.
1568+
* @return LY_ERR value.
1569+
*/
1570+
static LY_ERR
1571+
schema_diff_module_version(const struct lys_diff_change_s *change, const struct lys_module *mod1,
1572+
const struct lys_module *mod2, struct lyd_node *diff_list)
1573+
{
1574+
LY_ERR rc = LY_SUCCESS;
1575+
struct lyd_node *mod_cmp_list, *cont;
1576+
const char *node_name;
1577+
1578+
/* The only change handled. */
1579+
if (change->changed != LYS_CHANGED_YANG_VERSION) {
1580+
goto cleanup;
1581+
}
1582+
1583+
node_name = "yang-version";
1584+
1585+
/* module comparison */
1586+
LY_CHECK_GOTO(rc = lyd_new_list(diff_list, NULL, "module-comparison", 0, &mod_cmp_list), cleanup);
1587+
1588+
/* change info */
1589+
LY_CHECK_GOTO(rc = schema_diff_change_info(change, mod_cmp_list), cleanup);
1590+
1591+
if (mod1->version) {
1592+
LY_CHECK_GOTO(rc = lyd_new_inner(mod_cmp_list, NULL, "old", 0, &cont), cleanup);
1593+
LY_CHECK_GOTO(rc = lyd_new_term(cont, NULL, node_name,
1594+
mod1->version == LYS_VERSION_1_1 ? "1.1" : "1", 0, NULL), cleanup);
1595+
}
1596+
1597+
if (mod2->version) {
1598+
LY_CHECK_GOTO(rc = lyd_new_inner(mod_cmp_list, NULL, "new", 0, &cont), cleanup);
1599+
LY_CHECK_GOTO(rc = lyd_new_term(cont, NULL, node_name,
1600+
mod2->version == LYS_VERSION_1_1 ? "1.1" : "1", 0, NULL), cleanup);
1601+
}
1602+
1603+
cleanup:
1604+
return rc;
1605+
}
1606+
15581607
/**
15591608
* @brief Create cmp YANG data from direct text substatement of 'module'.
15601609
*
@@ -1605,6 +1654,9 @@ schema_diff_module_text(const struct lys_diff_change_s *change, const struct lys
16051654
text_old = mod1->ref;
16061655
text_new = mod2->ref;
16071656
break;
1657+
case LYS_CHANGED_YANG_VERSION:
1658+
/* not a textual field, ignore */
1659+
goto cleanup;
16081660
default:
16091661
LOGINT(mod1->ctx);
16101662
rc = LY_EINT;
@@ -3024,6 +3076,12 @@ schema_diff_module(const struct lys_diff_s *diff, const struct lys_module *mod1,
30243076
LY_ERR rc = LY_SUCCESS;
30253077
uint32_t i;
30263078

3079+
/* yang-version */
3080+
for (i = 0; i < diff->module_changes.count; ++i) {
3081+
LY_CHECK_GOTO(rc = schema_diff_module_version(&diff->module_changes.changes[i], mod1, mod2, diff_list),
3082+
cleanup);
3083+
}
3084+
30273085
/* text substmts */
30283086
for (i = 0; i < diff->module_changes.count; ++i) {
30293087
LY_CHECK_GOTO(rc = schema_diff_module_text(&diff->module_changes.changes[i], mod1, mod2, diff->with_parsed,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module yang-version {
2+
yang-version 1;
3+
namespace "urn:test:yang-version";
4+
prefix yvsn;
5+
6+
revision 2000-01-01;
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module yang-version {
2+
yang-version 1.1;
3+
namespace "urn:test:yang-version";
4+
prefix yvsn;
5+
6+
revision 2000-01-02;
7+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"ietf-yang-schema-comparison:schema-comparison": {
3+
"schema": [
4+
{
5+
"source": {
6+
"module": "yang-version",
7+
"revision": "2000-01-01"
8+
},
9+
"target": {
10+
"module": "yang-version",
11+
"revision": "2000-01-02"
12+
},
13+
"conformance": "non-backwards-compatible",
14+
"module-comparison": [
15+
{
16+
"changed": [
17+
{
18+
"stmt": "yang-version",
19+
"change": "modified",
20+
"conformance": "non-backwards-compatible"
21+
}
22+
],
23+
"old": {
24+
"yang-version": "1"
25+
},
26+
"new": {
27+
"yang-version": "1.1"
28+
}
29+
}
30+
]
31+
}
32+
]
33+
}
34+
}

tests/utests/schema_comparison/test_schema_comparison.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ test_non_backwards_compatible(void **state)
225225
schema_comparison(st, "ext-inst");
226226
schema_comparison(st, "presence");
227227
schema_comparison(st, "union");
228+
schema_comparison(st, "yang-version");
228229
}
229230

230231
int

0 commit comments

Comments
 (0)