Skip to content

Commit

Permalink
[DPB][YANG] Fix cases when boolean is used in different literal cases (
Browse files Browse the repository at this point in the history
…sonic-net#9418)

Fixes sonic-net#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) sonic-net/pull/9075
2) sonic-net/pull/9276
  • Loading branch information
mykolaxgerasymenko authored Dec 10, 2021
1 parent 5384b30 commit afd4098
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/sonic-yang-models/tests/files/sample_config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1220,9 +1220,9 @@
"FEATURE": {
"bgp": {
"auto_restart": "enabled",
"has_global_scope": "false",
"has_per_asic_scope": "true",
"has_timer": "false",
"has_global_scope": "False",
"has_per_asic_scope": "True",
"has_timer": "False",
"high_mem_alert": "disabled",
"state": "enabled",
"set_owner": "local"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"eStrKey": "Pattern",
"eStr": ["enabled|disabled|always_enabled|always_disabled"]
},
"FEATURE_WITH_INVALID_BOOLEAN_TYPE" : {
"desc": "Referring invalid feature boolean types.",
"eStrKey": "Pattern",
"eStr": ["false|true|False|True"]
},
"FEATURE_WITH_INVALID_OWNER" : {
"desc": "Referring invalid feature set_owner field.",
"eStrKey": "Pattern",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"name": "database",
"state": "always_enabled",
"auto_restart": "always_enabled",
"has_timer": "false",
"has_global_scope": "true",
"has_per_asic_scope": "true",
"has_timer": "False",
"has_global_scope": "True",
"has_per_asic_scope": "True",
"set_owner": "local"
},
{
Expand Down Expand Up @@ -101,5 +101,21 @@
]
}
}
},
"FEATURE_WITH_INVALID_BOOLEAN_TYPE": {
"sonic-feature:sonic-feature": {
"sonic-feature:FEATURE": {
"FEATURE_LIST": [
{
"name": "database",
"state": "always_enabled",
"auto_restart": "always_enabled",
"has_timer": "FALSE",
"has_global_scope": "TRUE",
"has_per_asic_scope": "TRUE"
}
]
}
}
}
}
18 changes: 11 additions & 7 deletions src/sonic-yang-models/yang-models/sonic-feature.yang
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ module sonic-feature{
namespace "http://github.com/Azure/sonic-feature";
prefix feature;

import sonic-types {
prefix stypes;
}

description "Feature Table yang Module for SONiC";

typedef feature-state {
description "configuration to set the feature running state";
type string {
Expand Down Expand Up @@ -53,22 +57,22 @@ module sonic-feature{
leaf has_timer {
description "This configuration identicates if there is
timer associated to this feature";
type boolean;
default false;
type stypes:boolean_type;
default "false";
}

leaf has_global_scope {
description "This configuration identicates there will only one service
spawned for the device";
type boolean;
default false;
type stypes:boolean_type;
default "false";
}

leaf has_per_asic_scope {
description "This configuration identicates there will only one service
spawned per asic";
type boolean;
default false;
type stypes:boolean_type;
default "false";
}

leaf high_mem_alert {
Expand Down
6 changes: 5 additions & 1 deletion src/sonic-yang-models/yang-models/sonic-flex_counter.yang
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ module sonic-flex_counter {
namespace "http://github.com/Azure/sonic-flex_counter";
prefix flex_counter;

import sonic-types {
prefix stypes;
}

description "FLEX COUNTER YANG Module for SONiC OS";

revision 2020-04-10 {
Expand All @@ -24,7 +28,7 @@ module sonic-flex_counter {
}

typedef flex_delay_status {
type boolean;
type stypes:boolean_type;
}

typedef poll_interval {
Expand Down
6 changes: 6 additions & 0 deletions src/sonic-yang-models/yang-templates/sonic-types.yang.j2
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ module sonic-types {
}
}

typedef boolean_type {
type string {
pattern "false|true|False|True";
}
}

typedef mac-addr-and-mask {
type string {
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}";
Expand Down

0 comments on commit afd4098

Please sign in to comment.