From 13582aaa6da3e79675f97fb6ea9ae77e99be2271 Mon Sep 17 00:00:00 2001 From: Stepan Blyshchak <38952541+stepanblyschak@users.noreply.github.com> Date: Tue, 28 Dec 2021 09:42:05 +0200 Subject: [PATCH] [sonic-yang] fix the feature state type (#9587) - Why I did it The feature state can be a jinja template, like in this file - https://github.com/Azure/sonic-buildimage/blob/master/files/build_templates/init_cfg.json.j2#L39. Without this change it is not possible to validate a configuration file. - How I did it Relaxes the constraint on feature state. Feature state leaf can be any string. - How to verify it Run UT. Signed-off-by: Stepan Blyschak --- .../tests/files/sample_config_db.json | 9 ++++++++ .../tests/yang_model_tests/tests/feature.json | 7 +----- .../tests_config/feature.json | 22 ++++++------------- .../yang-models/sonic-feature.yang | 6 ++--- 4 files changed, 19 insertions(+), 25 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 0e4e07519b..455eed24b0 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -1280,6 +1280,15 @@ "high_mem_alert": "disabled", "state": "enabled", "set_owner": "kube" + }, + "dhcp_relay": { + "auto_restart": "enabled", + "has_global_scope": "false", + "has_per_asic_scope": "true", + "has_timer": "false", + "high_mem_alert": "disabled", + "state": "{% if not (DEVICE_METADATA is defined and DEVICE_METADATA['localhost'] is defined and DEVICE_METADATA['localhost']['type'] is defined and DEVICE_METADATA['localhost']['type'] != 'ToRRouter') %}enabled{% else %}disabled{% endif %}", + "set_owner": "kube" } }, "DHCP_RELAY": { 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 d18b693937..52dce58a2c 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 @@ -2,11 +2,6 @@ "FEATURE_WITH_CORRECT_VALUES": { "desc": "CONFIG FEATURE TABLE WITH ALL THE CORRECT VALUES" }, - "FEATURE_WITH_INVALID_STATE" : { - "desc": "Referring invalid feature state.", - "eStrKey": "Pattern", - "eStr": ["enabled|disabled|always_enabled|always_disabled"] - }, "FEATURE_WITH_INVALID_BOOLEAN_TYPE" : { "desc": "Referring invalid feature boolean types.", "eStrKey": "Pattern", @@ -20,4 +15,4 @@ "FEATURE_WITH_NO_OWNER" : { "desc": "Config feature table without set_owner" } -} \ 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 5f43cfc3a6..82e403cb14 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 @@ -47,23 +47,15 @@ "has_global_scope": "false", "has_per_asic_scope": "true", "set_owner": "kube" - } - ] - } - } - }, - "FEATURE_WITH_INVALID_STATE": { - "sonic-feature:sonic-feature": { - "sonic-feature:FEATURE": { - "FEATURE_LIST": [ + }, { - "name": "database", - "state": "dontcare", - "auto_restart": "always_enabled", + "name": "dhcp_relay", + "state": "{% if not (DEVICE_METADATA is defined and DEVICE_METADATA['localhost'] is defined and DEVICE_METADATA['localhost']['type'] is defined and DEVICE_METADATA['localhost']['type'] != 'ToRRouter') %}enabled{% else %}disabled{% endif %}", + "auto_restart": "disabled", "has_timer": "false", - "has_global_scope": "true", + "has_global_scope": "false", "has_per_asic_scope": "true", - "set_owner": "local" + "set_owner": "kube" } ] } @@ -118,4 +110,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/sonic-yang-models/yang-models/sonic-feature.yang b/src/sonic-yang-models/yang-models/sonic-feature.yang index 6240836e74..be46bef198 100644 --- a/src/sonic-yang-models/yang-models/sonic-feature.yang +++ b/src/sonic-yang-models/yang-models/sonic-feature.yang @@ -13,9 +13,7 @@ module sonic-feature{ typedef feature-state { description "configuration to set the feature running state"; - type string { - pattern "enabled|disabled|always_enabled|always_disabled"; - } + type string; } typedef feature-owner { @@ -91,4 +89,4 @@ module sonic-feature{ } } } -} \ No newline at end of file +}