Skip to content

Commit 9e3d692

Browse files
committed
Revert "Add YANG validation for config reload if file is given (sonic-net#3576)"
This reverts commit 89bb87a.
1 parent 6d583a5 commit 9e3d692

File tree

2 files changed

+9
-49
lines changed

2 files changed

+9
-49
lines changed

config/main.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,19 +1372,6 @@ def multiasic_write_to_db(filename, load_sysinfo):
13721372
migrate_db_to_lastest(ns)
13731373

13741374

1375-
def config_file_yang_validation(filename):
1376-
config_to_check = read_json_file(filename)
1377-
sy = sonic_yang.SonicYang(YANG_DIR)
1378-
sy.loadYangModel()
1379-
try:
1380-
sy.loadData(configdbJson=config_to_check)
1381-
sy.validate_data_tree()
1382-
except sonic_yang.SonicYangException as e:
1383-
click.secho("{} fails YANG validation! Error: {}".format(filename, str(e)),
1384-
fg='magenta')
1385-
raise click.Abort()
1386-
1387-
13881375
# This is our main entrypoint - the main 'config' command
13891376
@click.group(cls=clicommon.AbbreviationGroup, context_settings=CONTEXT_SETTINGS)
13901377
@click.pass_context
@@ -1826,13 +1813,6 @@ def reload(db, filename, yes, load_sysinfo, no_service_restart, force, file_form
18261813
click.echo("Input {} config file(s) separated by comma for multiple files ".format(num_cfg_file))
18271814
return
18281815

1829-
if filename is not None:
1830-
if multi_asic.is_multi_asic():
1831-
# Multiasic has not 100% fully validated. Thus pass here.
1832-
pass
1833-
else:
1834-
config_file_yang_validation(filename)
1835-
18361816
#Stop services before config push
18371817
if not no_service_restart:
18381818
log.log_notice("'reload' stopping services...")
@@ -2023,7 +2003,15 @@ def load_minigraph(db, no_service_restart, traffic_shift_away, override_config,
20232003
# Multiasic has not 100% fully validated. Thus pass here.
20242004
pass
20252005
else:
2026-
config_file_yang_validation(golden_config_path)
2006+
sy = sonic_yang.SonicYang(YANG_DIR)
2007+
sy.loadYangModel()
2008+
try:
2009+
sy.loadData(configdbJson=config_to_check)
2010+
sy.validate_data_tree()
2011+
except sonic_yang.SonicYangException as e:
2012+
click.secho("{} fails YANG validation! Error: {}".format(golden_config_path, str(e)),
2013+
fg='magenta')
2014+
raise click.Abort()
20272015

20282016
# Dependency check golden config json
20292017
if multi_asic.is_multi_asic():

tests/config_test.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,34 +1432,6 @@ def test_reload_yang_config(self, get_cmd_module,
14321432
assert "\n".join([l.rstrip() for l in result.output.split('\n')]) \
14331433
== RELOAD_YANG_CFG_OUTPUT.format(config.SYSTEM_RELOAD_LOCK)
14341434

1435-
def test_reload_config_fails_yang_validation(self, get_cmd_module, setup_single_broadcom_asic):
1436-
with open(self.dummy_cfg_file, 'w') as f:
1437-
device_metadata = {
1438-
"DEVICE_METADATA": {
1439-
"localhost": {
1440-
"invalid_hwsku": "some_hwsku"
1441-
}
1442-
}
1443-
}
1444-
f.write(json.dumps(device_metadata))
1445-
1446-
with mock.patch(
1447-
"utilities_common.cli.run_command",
1448-
mock.MagicMock(side_effect=mock_run_command_side_effect)
1449-
):
1450-
(config, _) = get_cmd_module
1451-
runner = CliRunner()
1452-
1453-
result = runner.invoke(
1454-
config.config.commands["reload"],
1455-
[self.dummy_cfg_file, '-y', '-f'])
1456-
1457-
print(result.exit_code)
1458-
print(result.output)
1459-
traceback.print_tb(result.exc_info[2])
1460-
assert result.exit_code != 0
1461-
assert "fails YANG validation! Error" in result.output
1462-
14631435
@classmethod
14641436
def teardown_class(cls):
14651437
os.environ['UTILITIES_UNIT_TESTING'] = "0"

0 commit comments

Comments
 (0)