Skip to content

Commit

Permalink
fixes #907 - check ordered-by updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj4668 committed May 23, 2024
1 parent 283cfbf commit d4159de
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 2 deletions.
1 change: 1 addition & 0 deletions env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export PYTHONPATH="$PWD:$PYTHONPATH"
export YANG_MODPATH="$PWD/modules:$YANG_MODPATH"
export PYANG_XSLT_DIR="$PWD/xslt"
export PYANG_RNG_LIBDIR="$PWD/schema"
export PYANG="$PWD/bin/pyang"
export W="$PWD"
18 changes: 18 additions & 0 deletions pyang/plugins/check_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,22 @@ def chk_unique(old, new, ctx):
else:
err_def_added(u, ctx)

def chk_ordered_by(old, new, ctx):
oldorderedby = old.search_one('ordered-by')
neworderedby = new.search_one('ordered-by')
if oldorderedby is None and neworderedby is None:
pass
elif oldorderedby is None and neworderedby is not None and \
neworderedby.arg == 'user':
err_def_added(neworderedby, ctx)
elif oldorderedby is not None and neworderedby is None and \
oldorderedby.arg == 'user':
err_def_removed(oldorderedby, new, ctx)
elif oldorderedby is not None and neworderedby is not None and \
oldorderedby.arg != neworderedby.arg:
err_add(ctx.errors, neworderedby.pos, 'CHK_DEF_CHANGED',
('ordered-by', neworderedby.arg, oldorderedby.arg))

def chk_leaf(old, new, ctx):
chk_type(old.search_one('type'), new.search_one('type'), ctx)
chk_units(old, new, ctx)
Expand All @@ -659,6 +675,7 @@ def chk_leaf_list(old, new, ctx):
chk_type(old.search_one('type'), new.search_one('type'), ctx)
chk_units(old, new, ctx)
chk_min_max(old, new, ctx)
chk_ordered_by(old, new, ctx)

def chk_container(old, new, ctx):
chk_presence(old, new, ctx)
Expand All @@ -669,6 +686,7 @@ def chk_list(old, new, ctx):
chk_key(old, new, ctx)
chk_unique(old, new, ctx)
chk_i_children(old, new, ctx)
chk_ordered_by(old, new, ctx)

def chk_choice(old, new, ctx):
chk_mandatory(old, new, ctx)
Expand Down
24 changes: 22 additions & 2 deletions test/test_update/a.yang
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ module a {
}
leaf a_union {
type my-union1;
}
}
leaf b_union {
type my-union3;
}
Expand All @@ -127,15 +127,35 @@ module a {

leaf bbb {
type uint16;
}
}

leaf-list baz2 {
type string;
}

leaf-list baz3 {
type string;
ordered-by user;
min-elements 1;
max-elements 5;
}

leaf-list baz4 {
type int32;
ordered-by system;
}

leaf-list baz5 {
type int32;
}

leaf-list baz6 {
type int32;
ordered-by system;
}

leaf-list baz7 {
type int32;
}

}
21 changes: 21 additions & 0 deletions test/test_update/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,28 @@ module a {

leaf-list baz3 {
type string;
ordered-by system;
min-elements 2;
max-elements 4;
}

leaf-list baz4 {
type int32;
}

leaf-list baz5 {
type int32;
ordered-by system;
}

leaf-list baz6 {
type int32;
ordered-by user;
}

leaf-list baz7 {
type int32;
ordered-by user;
}

}
3 changes: 3 additions & 0 deletions test/test_update/expect/a.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ [email protected]:166: error: CHK_DEF_ADDED
[email protected]:167: error: CHK_DEF_ADDED
[email protected]:172: error: CHK_DEF_CHANGED
[email protected]:173: error: CHK_DEF_CHANGED
[email protected]:174: error: CHK_DEF_CHANGED
[email protected]:188: error: CHK_DEF_CHANGED
[email protected]:193: error: CHK_DEF_ADDED

0 comments on commit d4159de

Please sign in to comment.