Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[config] no op if Golden Config is invalid #3367

Merged
merged 6 commits into from
Jun 18, 2024
Merged
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
8 changes: 8 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1841,6 +1841,14 @@ def load_minigraph(db, no_service_restart, traffic_shift_away, override_config,
fg='magenta')
raise click.Abort()

# Dependency check golden config json
config_to_check = read_json_file(golden_config_path)
if multi_asic.is_multi_asic():
host_config = config_to_check.get('localhost', {})
else:
host_config = config_to_check
table_hard_dependency_check(host_config)

#Stop services before config push
if not no_service_restart:
log.log_notice("'load_minigraph' stopping services...")
Expand Down
50 changes: 47 additions & 3 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,13 @@ def is_file_side_effect(filename):
def test_load_minigraph_with_specified_golden_config_path(self, get_cmd_module):
def is_file_side_effect(filename):
return True if 'golden_config' in filename else False

def read_json_file_side_effect(filename):
return {}

with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command, \
mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)):
mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)), \
mock.patch('config.main.read_json_file', mock.MagicMock(side_effect=read_json_file_side_effect)):
(config, show) = get_cmd_module
runner = CliRunner()
result = runner.invoke(config.config.commands["load_minigraph"], ["--override_config", "--golden_config_path", "golden_config.json", "-y"])
Expand All @@ -774,14 +779,48 @@ def is_file_side_effect(filename):
def test_load_minigraph_with_default_golden_config_path(self, get_cmd_module):
def is_file_side_effect(filename):
return True if 'golden_config' in filename else False

def read_json_file_side_effect(filename):
return {}

with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command, \
mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)):
mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)), \
mock.patch('config.main.read_json_file', mock.MagicMock(side_effect=read_json_file_side_effect)):
(config, show) = get_cmd_module
runner = CliRunner()
result = runner.invoke(config.config.commands["load_minigraph"], ["--override_config", "-y"])
assert result.exit_code == 0
assert "config override-config-table /etc/sonic/golden_config_db.json" in result.output

@mock.patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs',
mock.MagicMock(return_value=("dummy_path", None)))
def test_load_minigraph_hard_dependency_check(self, get_cmd_module):
def is_file_side_effect(filename):
return True if 'golden_config' in filename else False

def read_json_file_side_effect(filename):
return {
"AAA": {
"authentication": {
"login": "tacacs+"
}
},
"TACPLUS": {
"global": {
"passkey": ""
}
}
}

with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)), \
mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)), \
mock.patch('config.main.read_json_file', mock.MagicMock(side_effect=read_json_file_side_effect)):
(config, _) = get_cmd_module
runner = CliRunner()
result = runner.invoke(config.config.commands["load_minigraph"], ["--override_config", "-y"])
assert result.exit_code != 0
assert "Authentication with 'tacacs+' is not allowed when passkey not exits." in result.output

@mock.patch('sonic_py_common.device_info.get_paths_to_platform_and_hwsku_dirs', mock.MagicMock(return_value=("dummy_path", None)))
def test_load_minigraph_with_traffic_shift_away(self, get_cmd_module):
with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command:
Expand All @@ -799,7 +838,12 @@ def test_load_minigraph_with_traffic_shift_away_with_golden_config(self, get_cmd
with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command:
def is_file_side_effect(filename):
return True if 'golden_config' in filename else False
with mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)):

def read_json_file_side_effect(filename):
return {}

with mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)), \
mock.patch('config.main.read_json_file', mock.MagicMock(side_effect=read_json_file_side_effect)):
(config, show) = get_cmd_module
db = Db()
golden_config = {}
Expand Down
Loading