Skip to content

Commit acbe722

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

File tree

8 files changed

+124
-15
lines changed

8 files changed

+124
-15
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: 30 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;
@@ -219,6 +220,30 @@ schema_diff_find_module(const struct ly_ctx *ctx, const char *nodeid, LY_VALUE_F
219220
*name = nam;
220221
}
221222

223+
/**
224+
* @brief Check changes of a 'yang-version'.
225+
*
226+
* @param[in] yvsn1 First yang-version.
227+
* @param[in] yvsn2 Second yang-version.
228+
* @param[in] parent_changed Parent statement of the change.
229+
* @param[in] changed Changed statement.
230+
* @param[in,out] changes Changes to add to.
231+
* @return LY_ERR value.
232+
*/
233+
static LY_ERR
234+
schema_diff_yangversion_change(uint8_t yvsn1, uint8_t yvsn2,
235+
enum lys_diff_changed_e parent_changed, enum lys_diff_changed_e changed,
236+
struct lys_diff_changes_s *changes)
237+
{
238+
if (yvsn1 != yvsn2) {
239+
/* modified */
240+
LY_CHECK_RET(schema_diff_add_change(LYS_CHANGE_MODIFIED, parent_changed,
241+
changed, 1, changes));
242+
}
243+
244+
return LY_SUCCESS;
245+
}
246+
222247
LY_ERR
223248
schema_diff_text_bc(const char *text1, const char *text2, enum lys_diff_changed_e parent_changed,
224249
enum lys_diff_changed_e changed, struct lys_diff_changes_s *changes)
@@ -587,6 +612,10 @@ schema_diff_module_identities_change(const struct lysc_ident *idents1, const str
587612
static LY_ERR
588613
schema_diff_module_change(const struct lys_module *mod1, const struct lys_module *mod2, struct lys_diff_s *diff)
589614
{
615+
/* yang-version */
616+
LY_CHECK_RET(schema_diff_yangversion_change(mod1->version, mod2->version,
617+
LYS_CHANGED_NONE, LYS_CHANGED_YANG_VERSION, &diff->module_changes));
618+
590619
/* organization */
591620
LY_CHECK_RET(schema_diff_text_bc(mod1->org, mod2->org, LYS_CHANGED_NONE, LYS_CHANGED_ORGANIZATION,
592621
&diff->module_changes));

src/schema_diff.h

Lines changed: 2 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
/**

src/schema_diff_tree.c

Lines changed: 34 additions & 13 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;
@@ -1556,7 +1558,7 @@ schema_diff_imports(const struct lys_module *mod, const struct lysc_node *schema
15561558
}
15571559

15581560
/**
1559-
* @brief Create cmp YANG data from direct text substatement of 'module'.
1561+
* @brief Create cmp YANG data from direct 'module' substatement.
15601562
*
15611563
* @param[in] change Change to use.
15621564
* @param[in] mod1 Old module.
@@ -1566,7 +1568,7 @@ schema_diff_imports(const struct lys_module *mod, const struct lysc_node *schema
15661568
* @return LY_ERR value.
15671569
*/
15681570
static LY_ERR
1569-
schema_diff_module_text(const struct lys_diff_change_s *change, const struct lys_module *mod1,
1571+
schema_diff_module_substmt(const struct lys_diff_change_s *change, const struct lys_module *mod1,
15701572
const struct lys_module *mod2, ly_bool with_parsed, struct lyd_node *diff_list)
15711573
{
15721574
LY_ERR rc = LY_SUCCESS;
@@ -1605,6 +1607,9 @@ schema_diff_module_text(const struct lys_diff_change_s *change, const struct lys
16051607
text_old = mod1->ref;
16061608
text_new = mod2->ref;
16071609
break;
1610+
case LYS_CHANGED_YANG_VERSION:
1611+
node_name = "yang-version";
1612+
break;
16081613
default:
16091614
LOGINT(mod1->ctx);
16101615
rc = LY_EINT;
@@ -1617,16 +1622,32 @@ schema_diff_module_text(const struct lys_diff_change_s *change, const struct lys
16171622
/* change info */
16181623
LY_CHECK_GOTO(rc = schema_diff_change_info(change, mod_cmp_list), cleanup);
16191624

1620-
if (text_old) {
1621-
/* old */
1622-
LY_CHECK_GOTO(rc = lyd_new_inner(mod_cmp_list, NULL, "old", 0, &cont), cleanup);
1623-
LY_CHECK_GOTO(rc = lyd_new_term(cont, NULL, node_name, text_old, 0, NULL), cleanup);
1624-
}
1625+
if (change->changed != LYS_CHANGED_YANG_VERSION) {
1626+
/* text substatement */
1627+
if (text_old) {
1628+
/* old */
1629+
LY_CHECK_GOTO(rc = lyd_new_inner(mod_cmp_list, NULL, "old", 0, &cont), cleanup);
1630+
LY_CHECK_GOTO(rc = lyd_new_term(cont, NULL, node_name, text_old, 0, NULL), cleanup);
1631+
}
16251632

1626-
if (text_new) {
1627-
/* new */
1628-
LY_CHECK_GOTO(rc = lyd_new_inner(mod_cmp_list, NULL, "new", 0, &cont), cleanup);
1629-
LY_CHECK_GOTO(rc = lyd_new_term(cont, NULL, node_name, text_new, 0, NULL), cleanup);
1633+
if (text_new) {
1634+
/* new */
1635+
LY_CHECK_GOTO(rc = lyd_new_inner(mod_cmp_list, NULL, "new", 0, &cont), cleanup);
1636+
LY_CHECK_GOTO(rc = lyd_new_term(cont, NULL, node_name, text_new, 0, NULL), cleanup);
1637+
}
1638+
} else {
1639+
/* yang-version substatement */
1640+
if (mod1->version) {
1641+
LY_CHECK_GOTO(rc = lyd_new_inner(mod_cmp_list, NULL, "old", 0, &cont), cleanup);
1642+
LY_CHECK_GOTO(rc = lyd_new_term(cont, NULL, node_name,
1643+
mod1->version == LYS_VERSION_1_1 ? "1.1" : "1", 0, NULL), cleanup);
1644+
}
1645+
1646+
if (mod2->version) {
1647+
LY_CHECK_GOTO(rc = lyd_new_inner(mod_cmp_list, NULL, "new", 0, &cont), cleanup);
1648+
LY_CHECK_GOTO(rc = lyd_new_term(cont, NULL, node_name,
1649+
mod2->version == LYS_VERSION_1_1 ? "1.1" : "1", 0, NULL), cleanup);
1650+
}
16301651
}
16311652

16321653
cleanup:
@@ -3024,9 +3045,9 @@ schema_diff_module(const struct lys_diff_s *diff, const struct lys_module *mod1,
30243045
LY_ERR rc = LY_SUCCESS;
30253046
uint32_t i;
30263047

3027-
/* text substmts */
3048+
/* yang-version and text substmts */
30283049
for (i = 0; i < diff->module_changes.count; ++i) {
3029-
LY_CHECK_GOTO(rc = schema_diff_module_text(&diff->module_changes.changes[i], mod1, mod2, diff->with_parsed,
3050+
LY_CHECK_GOTO(rc = schema_diff_module_substmt(&diff->module_changes.changes[i], mod1, mod2, diff->with_parsed,
30303051
diff_list), cleanup);
30313052
}
30323053

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)