From ac6991c1323a72b646eb01456cf31fee558e8498 Mon Sep 17 00:00:00 2001 From: bingwang Date: Mon, 13 Jun 2022 07:26:04 +0000 Subject: [PATCH 1/8] Add Yang model for SYSTEM_DEFAULTS table Signed-off-by: bingwang --- src/sonic-yang-models/setup.py | 2 + .../tests/system_defaults.json | 10 +++++ .../tests_config/system_defaults.json | 26 ++++++++++++ .../yang-models/sonic-system-defaults.yang | 41 +++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests/system_defaults.json create mode 100644 src/sonic-yang-models/tests/yang_model_tests/tests_config/system_defaults.json create mode 100644 src/sonic-yang-models/yang-models/sonic-system-defaults.yang diff --git a/src/sonic-yang-models/setup.py b/src/sonic-yang-models/setup.py index 3dfdde1cef89..b7790bd39692 100644 --- a/src/sonic-yang-models/setup.py +++ b/src/sonic-yang-models/setup.py @@ -104,6 +104,7 @@ def run(self): './yang-models/sonic-extension.yang', './yang-models/sonic-flex_counter.yang', './yang-models/sonic-feature.yang', + './yang-models/sonic-system-defaults.yang', './yang-models/sonic-interface.yang', './yang-models/sonic-kdump.yang', './yang-models/sonic-loopback-interface.yang', @@ -166,6 +167,7 @@ def run(self): './cvlyang-models/sonic-extension.yang', './cvlyang-models/sonic-flex_counter.yang', './cvlyang-models/sonic-feature.yang', + './cvlyang-models/sonic-system-defaults.yang', './cvlyang-models/sonic-interface.yang', './cvlyang-models/sonic-kdump.yang', './cvlyang-models/sonic-loopback-interface.yang', diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/system_defaults.json b/src/sonic-yang-models/tests/yang_model_tests/tests/system_defaults.json new file mode 100644 index 000000000000..1424cba58714 --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/system_defaults.json @@ -0,0 +1,10 @@ +{ + "SYSTEM_DEFAULTS_WITH_CORRECT_VALUES": { + "desc": "CONFIG SYSTEM_DEFAULTS TABLE WITH ALL THE CORRECT VALUES" + }, + "SYSTEM_DEFAULTS_WITH_INVALID_STATUS_VALUE" : { + "desc": "Referring invalid status value", + "eStrKey": "Pattern", + "eStr": "does not satisfy" + } +} diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests_config/system_defaults.json b/src/sonic-yang-models/tests/yang_model_tests/tests_config/system_defaults.json new file mode 100644 index 000000000000..a8ccc13c099d --- /dev/null +++ b/src/sonic-yang-models/tests/yang_model_tests/tests_config/system_defaults.json @@ -0,0 +1,26 @@ +{ + "SYSTEM_DEFAULTS_WITH_CORRECT_VALUES": { + "sonic-system-defaults:sonic-system-defaults": { + "sonic-system-defaults:SYSTEM_DEFAULTS": { + "SYSTEM_DEFAULTS_LIST": [ + { + "name": "tunnel_qos_remap", + "status": "enabled" + } + ] + } + } + }, + "SYSTEM_DEFAULTS_WITH_INVALID_STATUS_VALUE": { + "sonic-system-defaults:sonic-system-defaults": { + "sonic-system-defaults:SYSTEM_DEFAULTS": { + "SYSTEM_DEFAULTS_LIST": [ + { + "name": "tunnel_qos_remap", + "status": "invalid_status" + } + ] + } + } + } +} diff --git a/src/sonic-yang-models/yang-models/sonic-system-defaults.yang b/src/sonic-yang-models/yang-models/sonic-system-defaults.yang new file mode 100644 index 000000000000..263488de2200 --- /dev/null +++ b/src/sonic-yang-models/yang-models/sonic-system-defaults.yang @@ -0,0 +1,41 @@ +module sonic-system-defaults{ + + yang-version 1.1; + + namespace "http://github.com/Azure/system-defaults"; + prefix system-defaults; + + import sonic-types { + prefix stypes; + } + + description "SYSTEM_DEFAULTS Table yang Module for SONiC"; + + container sonic-system-defaults { + + container SYSTEM_DEFAULTS { + + description "system_defaults table in config_db.json"; + + list SYSTEM_DEFAULTS_LIST { + + key "name"; + + leaf name { + description "feature name in SYSTEM_DEFAULTS table"; + type string { + length 1..32; + } + } + + leaf status { + description "default status of the feature"; + type string { + pattern "enabled|disabled"; + } + } + + } + } + } +} From 3946938514423723c7c4f1e3148fd6f8026ac127 Mon Sep 17 00:00:00 2001 From: bingwang Date: Mon, 13 Jun 2022 08:39:48 +0000 Subject: [PATCH 2/8] Add Yang model for SYSTEM_DEFAULTS table Signed-off-by: bingwang --- .../yang-models/sonic-system-defaults.yang | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sonic-yang-models/yang-models/sonic-system-defaults.yang b/src/sonic-yang-models/yang-models/sonic-system-defaults.yang index 263488de2200..9c32c2986463 100644 --- a/src/sonic-yang-models/yang-models/sonic-system-defaults.yang +++ b/src/sonic-yang-models/yang-models/sonic-system-defaults.yang @@ -29,10 +29,10 @@ module sonic-system-defaults{ } leaf status { - description "default status of the feature"; + description "default status of the feature"; type string { - pattern "enabled|disabled"; - } + pattern "enabled|disabled"; + } } } From f28a040c35db3b8e9b49f836a521794940784a4d Mon Sep 17 00:00:00 2001 From: bingwang Date: Mon, 13 Jun 2022 09:33:12 +0000 Subject: [PATCH 3/8] Fix vs test Signed-off-by: bingwang --- src/sonic-yang-models/tests/files/sample_config_db.json | 5 +++++ 1 file changed, 5 insertions(+) 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 a042bc6a9473..ed0824c5c539 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -1874,6 +1874,11 @@ "LAG" ] } + }, + "SYSTEM_DEFAULTS": { + "tunnel_qos_remap": { + "status": "enabled" + } } }, "SAMPLE_CONFIG_DB_UNKNOWN": { From a25db3dc02855ceaa5db92a3efcc5a53719527dc Mon Sep 17 00:00:00 2001 From: bingwang Date: Mon, 27 Jun 2022 10:12:10 +0000 Subject: [PATCH 4/8] Update Configuration.md --- src/sonic-yang-models/doc/Configuration.md | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/sonic-yang-models/doc/Configuration.md b/src/sonic-yang-models/doc/Configuration.md index 2339a7859171..b35f8b72f7f7 100644 --- a/src/sonic-yang-models/doc/Configuration.md +++ b/src/sonic-yang-models/doc/Configuration.md @@ -52,6 +52,7 @@ Table of Contents * [Virtual router](#virtual-router) * [WRED_PROFILE](#wred_profile) * [PASSWORD_HARDENING](#password_hardening) + * [SYSTEM_DEFAULTS table](#) * [For Developers](#for-developers) * [Generating Application Config by Jinja2 Template](#generating-application-config-by-jinja2-template) * [Incremental Configuration by Subscribing to ConfigDB](#incremental-configuration-by-subscribing-to-configdb) @@ -1608,6 +1609,32 @@ The method could be: } ``` +### SYSTEM_DEFAULTS table +To have a better management of the features in SONiC, a new table `SYSTEM_DEFAULTS` is introduced. + +``` +"SYSTEM_DEFAULTS": { + "tunnel_qos_remap": { + "status": "enabled" + } + "default_bgp_status": { + "status": "down" + } + "synchronous_mode": { + "status": "enable" + } + "dhcp_server": { + "status": "enable" + } + } +``` +The default value of flags in `SYSTEM_DEFAULTS` table can be set in `init_cfg.json` and loaded into db at system startup. These flags are usually set at image being build, and are unlikely to change at runtime. + +If the values in `config_db.json` is changed by user, it will not be rewritten back by `init_cfg.json` as `config_db.json` is loaded after `init_cfg.json` in [docker_image_ctl.j2](https://github.com/Azure/sonic-buildimage/blob/master/files/build_templates/docker_image_ctl.j2) + +For the flags that can be changed by reconfiguration, we can update entries in `minigraph.xml`, and parse the new values in to config_db with minigraph parser at reloading minigraph. If there are duplicated entries in `init_cfg.json` and `minigraph.xml`, the values in `minigraph.xml` will overwritten the values defined in `init_cfg.json`. +#### 5.2.3 Update value directly in db memory + For Developers ============== From 049362cebae9024eea09d8afcbeda23fb9735175 Mon Sep 17 00:00:00 2001 From: bingwang Date: Mon, 27 Jun 2022 10:18:41 +0000 Subject: [PATCH 5/8] Update Configuration.md --- src/sonic-yang-models/doc/Configuration.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sonic-yang-models/doc/Configuration.md b/src/sonic-yang-models/doc/Configuration.md index b35f8b72f7f7..184acf4a553c 100644 --- a/src/sonic-yang-models/doc/Configuration.md +++ b/src/sonic-yang-models/doc/Configuration.md @@ -25,7 +25,7 @@ Table of Contents * [Device neighbor metada](#device-neighbor-metada) * [DSCP_TO_TC_MAP](#dscp_to_tc_map) * [FLEX_COUNTER_TABLE](#flex_counter_table) - * [KDUMP](#kdump) + * [KDUMP](#kdump) * [L2 Neighbors](#l2-neighbors) * [Loopback Interface](#loopback-interface) * [LOSSLESS_TRAFFIC_PATTERN](#LOSSLESS_TRAFFIC_PATTERN) @@ -51,8 +51,8 @@ Table of Contents * [VLAN_MEMBER](#vlan_member) * [Virtual router](#virtual-router) * [WRED_PROFILE](#wred_profile) - * [PASSWORD_HARDENING](#password_hardening) - * [SYSTEM_DEFAULTS table](#) + * [PASSWORD_HARDENING](#password_hardening) + * [SYSTEM_DEFAULTS table](#systemdefaults-table) * [For Developers](#for-developers) * [Generating Application Config by Jinja2 Template](#generating-application-config-by-jinja2-template) * [Incremental Configuration by Subscribing to ConfigDB](#incremental-configuration-by-subscribing-to-configdb) From 6aadc7f9e759c6d005ee001251ffd923ee95e9bf Mon Sep 17 00:00:00 2001 From: bingwang Date: Thu, 30 Jun 2022 04:50:34 +0000 Subject: [PATCH 6/8] Use admin_mode --- src/sonic-yang-models/yang-models/sonic-system-defaults.yang | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/sonic-yang-models/yang-models/sonic-system-defaults.yang b/src/sonic-yang-models/yang-models/sonic-system-defaults.yang index 9c32c2986463..a5160899777a 100644 --- a/src/sonic-yang-models/yang-models/sonic-system-defaults.yang +++ b/src/sonic-yang-models/yang-models/sonic-system-defaults.yang @@ -30,9 +30,7 @@ module sonic-system-defaults{ leaf status { description "default status of the feature"; - type string { - pattern "enabled|disabled"; - } + type stypes:admin_mode; } } From f2424df8d67a9b2ce226fad4aa1fa437169e3d8d Mon Sep 17 00:00:00 2001 From: bingwang Date: Thu, 30 Jun 2022 06:48:22 +0000 Subject: [PATCH 7/8] Fix vstest --- .../tests/yang_model_tests/tests/system_defaults.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sonic-yang-models/tests/yang_model_tests/tests/system_defaults.json b/src/sonic-yang-models/tests/yang_model_tests/tests/system_defaults.json index 1424cba58714..7d02dae1f95c 100644 --- a/src/sonic-yang-models/tests/yang_model_tests/tests/system_defaults.json +++ b/src/sonic-yang-models/tests/yang_model_tests/tests/system_defaults.json @@ -4,7 +4,6 @@ }, "SYSTEM_DEFAULTS_WITH_INVALID_STATUS_VALUE" : { "desc": "Referring invalid status value", - "eStrKey": "Pattern", - "eStr": "does not satisfy" + "eStrKey": "InvalidValue" } } From 3cb9e2f8ce49e2848146fb11277db8837eaef426 Mon Sep 17 00:00:00 2001 From: bingwang-ms <66248323+bingwang-ms@users.noreply.github.com> Date: Fri, 1 Jul 2022 09:04:51 +0800 Subject: [PATCH 8/8] Fix merge error --- src/sonic-yang-models/tests/files/sample_config_db.json | 1 + 1 file changed, 1 insertion(+) 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 3eab57e9ad37..1967e1629a8e 100644 --- a/src/sonic-yang-models/tests/files/sample_config_db.json +++ b/src/sonic-yang-models/tests/files/sample_config_db.json @@ -1894,6 +1894,7 @@ "SYSTEM_DEFAULTS": { "tunnel_qos_remap": { "status": "enabled" + } }, "LOSSLESS_TRAFFIC_PATTERN": { "AZURE": {