Skip to content

Commit afd4098

Browse files
[DPB][YANG] Fix cases when boolean is used in different literal cases (#9418)
Fixes #9326 #### Why I did it When we try execute DPB from CLI we have error: `libyang[0]: Invalid value "False" in "has_global_scope" element. (path: /sonic-feature:sonic-feature/FEATURE/FEATURE_LIST[name='bgp']/has_global_scope)` The reason for this issue is that has_global_scope and other have been stored in redis database with value False or True form capital letter: ``` "FEATURE":{ "bgp":{ "auto_restart":"enabled", "has_global_scope":"False", "has_per_asic_scope":"True", "has_timer":"False", "high_mem_alert":"disabled", "state":"enabled" } ``` But yang model support boolean just in lowercase letters (https://datatracker.ietf.org/doc/html/rfc6020#section-9.5.1). #### How I did it Added boolean to sonic-types as typedef with different literal cases. #### How to verify it Run the command config interface breakout <breakout_mode> **NOTE:** To verify this fix, the following PRs that fix other problems in SONiC must be merged into master: 1) /pull/9075 2) /pull/9276
1 parent 5384b30 commit afd4098

File tree

6 files changed

+49
-14
lines changed

6 files changed

+49
-14
lines changed

src/sonic-yang-models/tests/files/sample_config_db.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,9 +1220,9 @@
12201220
"FEATURE": {
12211221
"bgp": {
12221222
"auto_restart": "enabled",
1223-
"has_global_scope": "false",
1224-
"has_per_asic_scope": "true",
1225-
"has_timer": "false",
1223+
"has_global_scope": "False",
1224+
"has_per_asic_scope": "True",
1225+
"has_timer": "False",
12261226
"high_mem_alert": "disabled",
12271227
"state": "enabled",
12281228
"set_owner": "local"

src/sonic-yang-models/tests/yang_model_tests/tests/feature.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
"eStrKey": "Pattern",
88
"eStr": ["enabled|disabled|always_enabled|always_disabled"]
99
},
10+
"FEATURE_WITH_INVALID_BOOLEAN_TYPE" : {
11+
"desc": "Referring invalid feature boolean types.",
12+
"eStrKey": "Pattern",
13+
"eStr": ["false|true|False|True"]
14+
},
1015
"FEATURE_WITH_INVALID_OWNER" : {
1116
"desc": "Referring invalid feature set_owner field.",
1217
"eStrKey": "Pattern",

src/sonic-yang-models/tests/yang_model_tests/tests_config/feature.json

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"name": "database",
88
"state": "always_enabled",
99
"auto_restart": "always_enabled",
10-
"has_timer": "false",
11-
"has_global_scope": "true",
12-
"has_per_asic_scope": "true",
10+
"has_timer": "False",
11+
"has_global_scope": "True",
12+
"has_per_asic_scope": "True",
1313
"set_owner": "local"
1414
},
1515
{
@@ -101,5 +101,21 @@
101101
]
102102
}
103103
}
104+
},
105+
"FEATURE_WITH_INVALID_BOOLEAN_TYPE": {
106+
"sonic-feature:sonic-feature": {
107+
"sonic-feature:FEATURE": {
108+
"FEATURE_LIST": [
109+
{
110+
"name": "database",
111+
"state": "always_enabled",
112+
"auto_restart": "always_enabled",
113+
"has_timer": "FALSE",
114+
"has_global_scope": "TRUE",
115+
"has_per_asic_scope": "TRUE"
116+
}
117+
]
118+
}
119+
}
104120
}
105121
}

src/sonic-yang-models/yang-models/sonic-feature.yang

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ module sonic-feature{
55
namespace "http://github.com/Azure/sonic-feature";
66
prefix feature;
77

8+
import sonic-types {
9+
prefix stypes;
10+
}
11+
812
description "Feature Table yang Module for SONiC";
9-
13+
1014
typedef feature-state {
1115
description "configuration to set the feature running state";
1216
type string {
@@ -53,22 +57,22 @@ module sonic-feature{
5357
leaf has_timer {
5458
description "This configuration identicates if there is
5559
timer associated to this feature";
56-
type boolean;
57-
default false;
60+
type stypes:boolean_type;
61+
default "false";
5862
}
5963

6064
leaf has_global_scope {
6165
description "This configuration identicates there will only one service
6266
spawned for the device";
63-
type boolean;
64-
default false;
67+
type stypes:boolean_type;
68+
default "false";
6569
}
6670

6771
leaf has_per_asic_scope {
6872
description "This configuration identicates there will only one service
6973
spawned per asic";
70-
type boolean;
71-
default false;
74+
type stypes:boolean_type;
75+
default "false";
7276
}
7377

7478
leaf high_mem_alert {

src/sonic-yang-models/yang-models/sonic-flex_counter.yang

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ module sonic-flex_counter {
55
namespace "http://github.com/Azure/sonic-flex_counter";
66
prefix flex_counter;
77

8+
import sonic-types {
9+
prefix stypes;
10+
}
11+
812
description "FLEX COUNTER YANG Module for SONiC OS";
913

1014
revision 2020-04-10 {
@@ -24,7 +28,7 @@ module sonic-flex_counter {
2428
}
2529

2630
typedef flex_delay_status {
27-
type boolean;
31+
type stypes:boolean_type;
2832
}
2933

3034
typedef poll_interval {

src/sonic-yang-models/yang-templates/sonic-types.yang.j2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ module sonic-types {
217217
}
218218
}
219219

220+
typedef boolean_type {
221+
type string {
222+
pattern "false|true|False|True";
223+
}
224+
}
225+
220226
typedef mac-addr-and-mask {
221227
type string {
222228
pattern "[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}|[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}/[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}";

0 commit comments

Comments
 (0)