sonic-cfggen should return boolean values as lowercase true and false#22526
sonic-cfggen should return boolean values as lowercase true and false#22526bhouse-nexthop wants to merge 1 commit intosonic-net:masterfrom
Conversation
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
…net#22526) YANG mandates that boolean valeus are true and false, having the first letter be capital as is represented by Python would cause yang validation failures inside of libyang. This can be seen, for instance, when setting: ``` "MGMT_VRF_CONFIG": { "vrf_global": { "mgmtVrfEnabled": "true" } } ``` Then running `config save -y`. The written value is then "True", if then just running `config replace /etc/sonic/config_db.json` it would result in an error of: ``` Invalid value "True" in "mgmtVrfEnabled" element. ``` Signed-off-by: Brad House <bhouse@nexthop.ai>
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
build failures are caused by bad PR #22432 |
ee405bb to
d88c322
Compare
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
d88c322 to
f62721d
Compare
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Thanks @lguohan I made a couple minor modifications and replied to the rest. |
0dced08 to
4386703
Compare
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
these spurious test failures in completely unrelated code paths are getting bad. I just rebased to force a rebuild. |
Also probably needs a rebuild again? |
4386703 to
07f19c0
Compare
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
$!*% yep |
Second time it worked :-) |
|
@lguohan any chance you can look at this and let me know if you have similar concerns to @qiluo-msft ? It at most loads the yang models once per sonic-cfggen execution to do proper field type validation to prevent an invalid configdb yang schema from being written out. |
|
let me talk to qi when he is back tomorrow. do you have some measurable data to show that this won't add much overhead? |
|
btw, the pr description/title probably should update saying that introducing yang model validation in sonic-cfggen? |
The description does say it under the "How I did it" section. |
Considering this is only loading the yang models and not actually performing the validation step, I'd assume the hit would be negligible. That said, I don't have hard numbers. Let me see if I can collect some before / after numbers for you on real hardware. |
|
I am trying to repro the original issue mentioned in PR description, but failed to repro. I could not observe 'The written value is then "True"' admin@sonic:~$ sonic-db-cli CONFIG_DB hset "MGMT_VRF_CONFIG|vrf_global" "mgmtVrfEnabled" true
1
admin@sonic:~$ sonic-db-cli CONFIG_DB hgetall "MGMT_VRF_CONFIG|vrf_global"
{'mgmtVrfEnabled': 'true'}
admin@sonic:~$ sudo config save -y
Running command: /usr/local/bin/sonic-cfggen -d --print-data > /etc/sonic/config_db.json
admin@sonic:~$ grep -C 2 "mgmtVrfEnabled" /etc/sonic/config_db.json
"MGMT_VRF_CONFIG": {
"vrf_global": {
"mgmtVrfEnabled": "true"
}
}, |
I modified the config_db.json and didn't play with the sonic-db-cli. I haven't looked at how sonic-db-cli writes that, but I'm guessing its writing the 'true' as a string. A string would be preserved in the original case. It actually has to be in Redis as a boolean value for this issue to be observed. |
|
Performance numbers below. Platform: x86_64-mlnx_msn2700-r0 Pretty slow cpu: with patch: without patch: |
YANG mandates that boolean valeus are true and false, having
the first letter be capital as is represented by Python would
cause yang validation failures inside of libyang.
This can be seen, for instance, when setting:
```
"MGMT_VRF_CONFIG": {
"vrf_global": {
"mgmtVrfEnabled": "true"
}
}
```
Then running `config save -y`. The written value is then "True", if
then just running `config replace /etc/sonic/config_db.json` it would
result in an error of:
```
Invalid value "True" in "mgmtVrfEnabled" element.
```
Signed-off-by: Brad House <bhouse@nexthop.ai>
07f19c0 to
250c00f
Compare
|
/azp run Azure.sonic-buildimage |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Could you provide your repro steps for the original issue? I do not understand "It actually has to be in Redis as a boolean value" since redis only support string as value. If you modify config_db.json and trigger a bug, I prefer to treat it as invalid input bug and just fix the input validation logic and fail sonic-cfggen immediately, so yang dependency is not needed. |
|
steps to reproduce are:
The trigger to this behavior is the fact that somewhere the Pythonic True / False are being written when serializing from Redis. |
Why I did it
YANG mandates that boolean values are true and false, having the first letter be capital as is represented by Python would cause yang validation failures inside of libyang. Because of this, it appears a different yang type in
sonic-types.yanghas a secondaryboolean_typesthat is used that allows more formats.This can be seen, for instance, when setting:
Then running
config save -y. The written value is then "True", if then just runningconfig replace /etc/sonic/config_db.jsonit would result in an error of:Work item tracking
How I did it
Capture native yang boolean values by looking up the yang schema when writing the config_db.json via sonic-cfggen and ensure they are written as lowercase.
How to verify it
See above for reproduction method
Which release branch to backport (provide reason below if selected)
Tested branch (Please provide the tested image version)
master as of 20250502
Description for the changelog
sonic-cfggen should return boolean values as lowercase true and false
Link to config_db schema for YANG module changes
N/A
A picture of a cute animal (not mandatory but encouraged)
Fixes #22527
Signed-off-by: Brad House bhouse@nexthop.ai