From c16a335f651685c4858d2d7aad48688a05fc598f Mon Sep 17 00:00:00 2001 From: Mykola Gerasymenko Date: Wed, 1 Dec 2021 09:56:10 -0800 Subject: [PATCH 1/3] [DPB][YANG] Fix cases when boolean is used in different literal cases * Add boolean as typedef to sonic-types * Fix boolean in sonic-feature yang model * Fix boolean in sonic-flex_counter yang model Signed-off-by: Mykola Gerasymenko --- src/sonic-yang-models/yang-models/sonic-feature.yang | 12 ++++++------ .../yang-models/sonic-flex_counter.yang | 6 +++++- .../yang-templates/sonic-types.yang.j2 | 5 +++++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/sonic-yang-models/yang-models/sonic-feature.yang b/src/sonic-yang-models/yang-models/sonic-feature.yang index 0a7b29c6ae08..51a9cbac9081 100644 --- a/src/sonic-yang-models/yang-models/sonic-feature.yang +++ b/src/sonic-yang-models/yang-models/sonic-feature.yang @@ -42,22 +42,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 { diff --git a/src/sonic-yang-models/yang-models/sonic-flex_counter.yang b/src/sonic-yang-models/yang-models/sonic-flex_counter.yang index 099a20a9c3ab..8b2e9c88b37a 100644 --- a/src/sonic-yang-models/yang-models/sonic-flex_counter.yang +++ b/src/sonic-yang-models/yang-models/sonic-flex_counter.yang @@ -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 { @@ -24,7 +28,7 @@ module sonic-flex_counter { } typedef flex_delay_status { - type boolean; + type stypes:boolean_type; } description "FLEX_COUNTER_TABLE part of config_db.json"; diff --git a/src/sonic-yang-models/yang-templates/sonic-types.yang.j2 b/src/sonic-yang-models/yang-templates/sonic-types.yang.j2 index c28ea16c00bd..dcf5eeb243b6 100644 --- a/src/sonic-yang-models/yang-templates/sonic-types.yang.j2 +++ b/src/sonic-yang-models/yang-templates/sonic-types.yang.j2 @@ -222,6 +222,11 @@ module sonic-types { } } + typedef boolean_type { + type string { + pattern "false|true|False|True"; + } + } /* Required for CVL */ From ebf4e581b6e2d58713851409c9be99f754c54382 Mon Sep 17 00:00:00 2001 From: Mykola Gerasymenko Date: Thu, 2 Dec 2021 09:25:27 -0800 Subject: [PATCH 2/3] Add test-cases for new boolean_type --- .../tests/files/sample_config_db.json | 6 ++--- .../tests/yang_model_tests/tests/feature.json | 5 +++++ .../tests_config/feature.json | 22 ++++++++++++++++--- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/sonic-yang-models/tests/files/sample_config_db.json b/src/sonic-yang-models/tests/files/sample_config_db.json index 2ed16e6a3eb9..b37341fe6b73 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -1201,9 +1201,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" }, diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/feature.json b/src/sonic-yang-models/tests/yang_model_tests/tests/feature.json index 372f51a8c12a..338087556267 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/feature.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/feature.json @@ -6,5 +6,10 @@ "desc": "Referring invalid feature state.", "eStrKey": "Pattern", "eStr": ["enabled|disabled|always_enabled"] + }, + "FEATURE_WITH_INVALID_BOOLEAN_TYPE" : { + "desc": "Referring invalid feature boolean types.", + "eStrKey": "Pattern", + "eStr": ["false|true|False|True"] } } \ No newline at end of file diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/feature.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/feature.json index 661cf1db2b53..b6316460b9d1 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests_config/feature.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/feature.json @@ -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" }, { "name": "swss", @@ -62,5 +62,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" + } + ] + } + } } } \ No newline at end of file From 208f8b9dcbc1dd5aa89af268e75e54e26fc8ecbd Mon Sep 17 00:00:00 2001 From: Mykola Gerasymenko Date: Fri, 10 Dec 2021 00:47:55 -0800 Subject: [PATCH 3/3] Add import sonic-types to use boolean_type Signed-off-by: Mykola Gerasymenko --- src/sonic-yang-models/yang-models/sonic-feature.yang | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/sonic-yang-models/yang-models/sonic-feature.yang b/src/sonic-yang-models/yang-models/sonic-feature.yang index 7d6ca5e66a1c..6240836e74ee 100644 --- a/src/sonic-yang-models/yang-models/sonic-feature.yang +++ b/src/sonic-yang-models/yang-models/sonic-feature.yang @@ -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 {