Skip to content

Commit 9150093

Browse files
committed
Fixed: [Multiple deviations to same grouping when CLICON_YANG_USE_ORIGINAL doesnt work](#629)
1 parent 137b88f commit 9150093

File tree

3 files changed

+75
-13
lines changed

3 files changed

+75
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Developers may need to change their code
7575
7676
### Corrected Bugs
7777
78+
* Fixed: [Multiple deviations to same grouping when CLICON_YANG_USE_ORIGINAL doesnt work](https://github.com/clicon/clixon/issues/629)
7879
* Fixed: [YANG identityref from uses/grouping from separate module does not work](https://github.com/clicon/clixon/issues/628)
7980
* Fixed: YANG error-app-tag identifies as error-message causing false duplicate
8081
* Fixed: YANG error-app-tag not in range and length as it should

lib/src/clixon_yang.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,8 @@ yn_iter(yang_stmt *yparent,
15311531
* Special case: look in imported INPUTs as well (for (sub)modules.
15321532
* This could need an optimized lookup, especially the INPUT case.
15331533
* Most common use for the special case, ie in openconfig, is grouping and identity
1534+
* Note also in the case of the use-orig optimization that uses the child of
1535+
* the original if that exists rather than the actual child.
15341536
* @param[in] yn Yang node, current context node.
15351537
* @param[in] keyword if 0 match any keyword. Actual type: enum rfc_6020
15361538
* @param[in] argument String compare w argument. if NULL, match any.
@@ -1556,13 +1558,6 @@ yang_find(yang_stmt *yn,
15561558
if (yang_flag_get(yn, YANG_FLAG_FIND) != 0x0)
15571559
return NULL;
15581560
yang_flag_set(yn, YANG_FLAG_FIND);
1559-
if (_yang_use_orig &&
1560-
(yorig = yang_orig_get(yn)) != NULL &&
1561-
uses_orig_ptr(keyword)){
1562-
yret = yang_find(yorig, keyword, argument);
1563-
yang_flag_reset(yn, YANG_FLAG_FIND);
1564-
return yret;
1565-
}
15661561
for (i=0; i<yn->ys_len; i++){
15671562
ys = yn->ys_stmt[i];
15681563
if (keyword == 0 || ys->ys_keyword == keyword){
@@ -1572,7 +1567,6 @@ yang_find(yang_stmt *yn,
15721567
break;
15731568
}
15741569
}
1575-
#if 1
15761570
/* Special case: if not match and yang node is module or submodule, extend
15771571
* search to include submodules
15781572
* It would be nice to get rid of this special case, and then also remove
@@ -1589,7 +1583,18 @@ yang_find(yang_stmt *yn,
15891583
yretsub = yang_find(ym, keyword, argument);
15901584
}
15911585
}
1592-
#endif
1586+
}
1587+
1588+
if (yret != NULL && yang_flag_get(yret, YANG_FLAG_REFINE))
1589+
;
1590+
else {
1591+
if (_yang_use_orig &&
1592+
(yorig = yang_orig_get(yn)) != NULL &&
1593+
uses_orig_ptr(keyword)){
1594+
yret = yang_find(yorig, keyword, argument);
1595+
yang_flag_reset(yn, YANG_FLAG_FIND);
1596+
return yret;
1597+
}
15931598
}
15941599
yang_flag_reset(yn, YANG_FLAG_FIND);
15951600
return yret?yret:yretsub;
@@ -2732,7 +2737,9 @@ yang_deviation(yang_stmt *ys,
27322737
}
27332738
break;
27342739
}
2735-
if (ytc){
2740+
if (_yang_use_orig && yang_orig_get(ytarget) != NULL)
2741+
;
2742+
else {
27362743
/* Remove old */
27372744
if (ys_prune_self(ytc) < 0)
27382745
goto done;

test/test_yang_deviation.sh

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@ module example-base{
6464
leaf my {
6565
/* deviate replaces with int and default -42 */
6666
type uint16;
67+
mandatory false;
6768
}
6869
}
6970
}
7071
uses system-top;
72+
container again {
73+
uses system-top;
74+
}
7175
}
7276
EOF
7377

@@ -95,7 +99,7 @@ function testrun()
9599
start_backend -s init -f "$cfg"
96100
fi
97101

98-
new "wait backend"
102+
new "wait backend 1"
99103
wait_backend
100104

101105
new "Add user bob"
@@ -280,7 +284,7 @@ if [ "$BE" -ne 0 ]; then
280284
start_backend -s init -f "$cfg"
281285
fi
282286

283-
new "wait backend"
287+
new "wait backend 2"
284288
wait_backend
285289

286290
new "show default value, expect deviated"
@@ -340,7 +344,7 @@ if [ "$BE" -ne 0 ]; then
340344
start_backend -s init -f "$cfg"
341345
fi
342346

343-
new "wait backend"
347+
new "wait backend 3"
344348
wait_backend
345349

346350
new "set negative value"
@@ -355,6 +359,56 @@ expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS>
355359
new "netconf validate expect fail"
356360
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><validate><source><candidate/></source></validate></rpc>" "" "<rpc-reply $DEFAULTNS><rpc-error><error-type>application</error-type><error-tag>bad-element</error-tag><error-info><bad-element>my</bad-element></error-info><error-severity>error</error-severity><error-message>Number 98735 out of range: -128 - 127</error-message></rpc-error></rpc-reply>"
357361

362+
cat <<EOF > $fyangdev
363+
module example-deviations{
364+
yang-version 1.1;
365+
prefix ed;
366+
namespace "urn:example:deviations";
367+
import example-base {
368+
prefix base;
369+
}
370+
typedef mytype {
371+
type int8;
372+
}
373+
deviation /base:system/base:my {
374+
deviate replace {
375+
mandatory true;
376+
}
377+
}
378+
deviation /base:again/base:system/base:my {
379+
deviate replace {
380+
mandatory true;
381+
}
382+
}
383+
}
384+
EOF
385+
386+
if [ "$BE" -ne 0 ]; then
387+
new "kill old backend"
388+
sudo clixon_backend -zf "$cfg"
389+
if [ $? -ne 0 ]; then
390+
err
391+
fi
392+
new "start backend -s init -f $cfg -o CLICON_YANG_USE_ORIGINAL=true"
393+
start_backend -s init -f "$cfg -o CLICON_YANG_USE_ORIGINAL=true"
394+
fi
395+
396+
# use-original optimization and two deviations with separate uses to same grouping
397+
new "wait backend 4"
398+
wait_backend
399+
400+
new "set system without my"
401+
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><edit-config><target><candidate/></target><config><system xmlns=\"urn:example:base\"><daytime>Sept17</daytime></system></config></edit-config></rpc>" "" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
402+
403+
new "netconf validate fail"
404+
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><validate><source><candidate/></source></validate></rpc>" "" "<rpc-reply $DEFAULTNS><rpc-error><error-type>application</error-type><error-tag>missing-element</error-tag><error-info><bad-element>my</bad-element></error-info><error-severity>error</error-severity><error-message>Mandatory variable of system in module example-base</error-message></rpc-error></rpc-reply>"
405+
406+
new "set system my"
407+
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><edit-config><target><candidate/></target><config><system xmlns=\"urn:example:base\"><my>17</my></system></config></edit-config></rpc>" "" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
408+
409+
new "netconf validate ok"
410+
expecteof_netconf "$clixon_netconf -qf $cfg" 0 "$DEFAULTHELLO" "<rpc $DEFAULTNS><validate><source><candidate/></source></validate></rpc>" "" "<rpc-reply $DEFAULTNS><ok/></rpc-reply>"
411+
358412
if [ "$BE" -ne 0 ]; then
359413
new "Kill backend"
360414
# Check if premature kill

0 commit comments

Comments
 (0)