Skip to content

Commit 782c33a

Browse files
authored
[yang] Enforce yang full support in full config command (sonic-net#3716)
What I did Add strict YANG validation for full config command. How I did it Fail if found table with no YANG support How to verify it UT
1 parent a5b7a90 commit 782c33a

File tree

4 files changed

+31
-134
lines changed

4 files changed

+31
-134
lines changed

config/main.py

+7
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,13 @@ def config_file_yang_validation(filename):
14021402
fg='magenta')
14031403
raise click.Abort()
14041404

1405+
sy.tablesWithOutYang.pop('bgpraw', None)
1406+
if len(sy.tablesWithOutYang):
1407+
click.secho("Config tables are missing yang models: {}".format(str(sy.tablesWithOutYang.keys())),
1408+
fg='magenta')
1409+
raise click.Abort()
1410+
1411+
14051412
# This is our main entrypoint - the main 'config' command
14061413
@click.group(cls=clicommon.AbbreviationGroup, context_settings=CONTEXT_SETTINGS)
14071414
@click.pass_context

tests/config_override_input/new_feature_config.json

-124
This file was deleted.

tests/config_override_test.py

-10
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
DATA_DIR = os.path.join(SCRIPT_DIR, "config_override_input")
1515
EMPTY_INPUT = os.path.join(DATA_DIR, "empty_input.json")
1616
PARTIAL_CONFIG_OVERRIDE = os.path.join(DATA_DIR, "partial_config_override.json")
17-
NEW_FEATURE_CONFIG = os.path.join(DATA_DIR, "new_feature_config.json")
1817
FULL_CONFIG_OVERRIDE = os.path.join(DATA_DIR, "full_config_override.json")
1918
PORT_CONFIG_OVERRIDE = os.path.join(DATA_DIR, "port_config_override.json")
2019
EMPTY_TABLE_REMOVAL = os.path.join(DATA_DIR, "empty_table_removal.json")
@@ -125,15 +124,6 @@ def test_golden_config_db_partial(self):
125124
db, config, read_data['running_config'], read_data['golden_config'],
126125
read_data['expected_config'])
127126

128-
def test_golden_config_db_new_feature(self):
129-
"""Golden Config append NEW_FEATURE_TABLE"""
130-
db = Db()
131-
with open(NEW_FEATURE_CONFIG, "r") as f:
132-
read_data = json.load(f)
133-
self.check_override_config_table(
134-
db, config, read_data['running_config'], read_data['golden_config'],
135-
read_data['expected_config'])
136-
137127
def test_golden_config_db_full(self):
138128
"""Golden Config makes change to every table in configDB"""
139129
db = Db()

tests/config_test.py

+24
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,30 @@ def read_json_file_side_effect(filename):
11921192
assert result.exit_code != 0
11931193
assert "Authentication with 'tacacs+' is not allowed when passkey not exists." in result.output
11941194

1195+
@mock.patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs',
1196+
mock.MagicMock(return_value=("dummy_path", None)))
1197+
def test_load_minigraph_no_yang_failure(self, get_cmd_module):
1198+
def is_file_side_effect(filename):
1199+
return True if 'golden_config' in filename else False
1200+
1201+
def read_json_file_side_effect(filename):
1202+
return {
1203+
"NEW_FEATURE": {
1204+
"global": {
1205+
"state": "enable"
1206+
}
1207+
}
1208+
}
1209+
1210+
with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)), \
1211+
mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)), \
1212+
mock.patch('config.main.read_json_file', mock.MagicMock(side_effect=read_json_file_side_effect)):
1213+
(config, _) = get_cmd_module
1214+
runner = CliRunner()
1215+
result = runner.invoke(config.config.commands["load_minigraph"], ["--override_config", "-y"])
1216+
assert result.exit_code != 0
1217+
assert "Config tables are missing yang models: dict_keys(['NEW_FEATURE'])" in result.output
1218+
11951219
@mock.patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', mock.MagicMock(return_value=("dummy_path", None)))
11961220
def test_load_minigraph_with_traffic_shift_away(self, get_cmd_module):
11971221
with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command:

0 commit comments

Comments
 (0)