Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2161,7 +2161,10 @@ def reload(db, filename, yes, load_sysinfo, no_service_restart, force, file_form
click.echo("Input {} config file(s) separated by comma for multiple files ".format(num_cfg_file))
return

if filename is not None and filename != "/dev/stdin":
if filename is None and file_format == 'config_db':
# Validate the default config before stopping services and flushing CONFIG_DB.
config_file_yang_validation(DEFAULT_CONFIG_DB_FILE)
elif filename is not None and filename != "/dev/stdin":
if multi_asic.is_multi_asic():
for cfg_file in cfg_files:
if cfg_file is not None:
Expand Down
25 changes: 23 additions & 2 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,12 @@ def setup_class(cls):
open(cls.dummy_cfg_file, 'w').close()

def test_config_reload(self, get_cmd_module, setup_single_broadcom_asic):
with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command:
(config, show) = get_cmd_module
(config, show) = get_cmd_module

with mock.patch(
"utilities_common.cli.run_command",
mock.MagicMock(side_effect=mock_run_command_side_effect)), \
mock.patch.object(config, "config_file_yang_validation") as mock_validate_config:

jsonfile_config = os.path.join(mock_db_path, "config_db.json")
jsonfile_init_cfg = os.path.join(mock_db_path, "init_cfg.json")
Expand All @@ -753,6 +757,23 @@ def test_config_reload(self, get_cmd_module, setup_single_broadcom_asic):

assert "\n".join([line.rstrip() for line in result.output.split('\n')][:2]) == \
reload_config_with_sys_info_command_output.format(config.SYSTEM_RELOAD_LOCK)
mock_validate_config.assert_called_once_with(jsonfile_config)

def test_config_reload_default_config_validation_failure(self, get_cmd_module, setup_single_broadcom_asic):
(config, show) = get_cmd_module

jsonfile_config = os.path.join(mock_db_path, "config_db.json")
config.DEFAULT_CONFIG_DB_FILE = jsonfile_config

with mock.patch("utilities_common.cli.run_command") as mock_run_command, \
mock.patch.object(
config, "config_file_yang_validation", side_effect=click.Abort) as mock_validate_config:
runner = CliRunner()
result = runner.invoke(config.config.commands["reload"], ["-y", "-f"])

assert result.exit_code != 0
mock_validate_config.assert_called_once_with(jsonfile_config)
mock_run_command.assert_not_called()

def test_config_reload_stdin(self, get_cmd_module, setup_single_broadcom_asic):
def mock_json_load(f):
Expand Down
Loading