Skip to content

Commit 13582aa

Browse files
[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 <[email protected]>
1 parent 36d8660 commit 13582aa

File tree

4 files changed

+19
-25
lines changed

4 files changed

+19
-25
lines changed

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

+9
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,15 @@
12801280
"high_mem_alert": "disabled",
12811281
"state": "enabled",
12821282
"set_owner": "kube"
1283+
},
1284+
"dhcp_relay": {
1285+
"auto_restart": "enabled",
1286+
"has_global_scope": "false",
1287+
"has_per_asic_scope": "true",
1288+
"has_timer": "false",
1289+
"high_mem_alert": "disabled",
1290+
"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 %}",
1291+
"set_owner": "kube"
12831292
}
12841293
},
12851294
"DHCP_RELAY": {

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
"FEATURE_WITH_CORRECT_VALUES": {
33
"desc": "CONFIG FEATURE TABLE WITH ALL THE CORRECT VALUES"
44
},
5-
"FEATURE_WITH_INVALID_STATE" : {
6-
"desc": "Referring invalid feature state.",
7-
"eStrKey": "Pattern",
8-
"eStr": ["enabled|disabled|always_enabled|always_disabled"]
9-
},
105
"FEATURE_WITH_INVALID_BOOLEAN_TYPE" : {
116
"desc": "Referring invalid feature boolean types.",
127
"eStrKey": "Pattern",
@@ -20,4 +15,4 @@
2015
"FEATURE_WITH_NO_OWNER" : {
2116
"desc": "Config feature table without set_owner"
2217
}
23-
}
18+
}

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

+7-15
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,15 @@
4747
"has_global_scope": "false",
4848
"has_per_asic_scope": "true",
4949
"set_owner": "kube"
50-
}
51-
]
52-
}
53-
}
54-
},
55-
"FEATURE_WITH_INVALID_STATE": {
56-
"sonic-feature:sonic-feature": {
57-
"sonic-feature:FEATURE": {
58-
"FEATURE_LIST": [
50+
},
5951
{
60-
"name": "database",
61-
"state": "dontcare",
62-
"auto_restart": "always_enabled",
52+
"name": "dhcp_relay",
53+
"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 %}",
54+
"auto_restart": "disabled",
6355
"has_timer": "false",
64-
"has_global_scope": "true",
56+
"has_global_scope": "false",
6557
"has_per_asic_scope": "true",
66-
"set_owner": "local"
58+
"set_owner": "kube"
6759
}
6860
]
6961
}
@@ -118,4 +110,4 @@
118110
}
119111
}
120112
}
121-
}
113+
}

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ module sonic-feature{
1313

1414
typedef feature-state {
1515
description "configuration to set the feature running state";
16-
type string {
17-
pattern "enabled|disabled|always_enabled|always_disabled";
18-
}
16+
type string;
1917
}
2018

2119
typedef feature-owner {
@@ -91,4 +89,4 @@ module sonic-feature{
9189
}
9290
}
9391
}
94-
}
92+
}

0 commit comments

Comments
 (0)