Skip to content

Commit 318fcc8

Browse files
committed
[minigraph] add option to specify golden path in load_minigraph
1 parent f0ce586 commit 318fcc8

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

config/main.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,8 +1718,9 @@ def load_mgmt_config(filename):
17181718
expose_value=False, prompt='Reload config from minigraph?')
17191719
@click.option('-n', '--no_service_restart', default=False, is_flag=True, help='Do not restart docker services')
17201720
@click.option('-t', '--traffic_shift_away', default=False, is_flag=True, help='Keep device in maintenance with TSA')
1721+
@click.option('-p', '--golden_config_path', help='specify Golden Config path')
17211722
@clicommon.pass_db
1722-
def load_minigraph(db, no_service_restart, traffic_shift_away):
1723+
def load_minigraph(db, no_service_restart, traffic_shift_away, golden_config_path):
17231724
"""Reconfigure based on minigraph."""
17241725
log.log_info("'load_minigraph' executing...")
17251726

@@ -1797,8 +1798,15 @@ def load_minigraph(db, no_service_restart, traffic_shift_away):
17971798
click.secho("[WARNING] Golden configuration may override Traffic-shift-away state. Please execute TSC to check the current System mode")
17981799

17991800
# Load golden_config_db.json
1800-
if os.path.isfile(DEFAULT_GOLDEN_CONFIG_DB_FILE):
1801-
override_config_by(DEFAULT_GOLDEN_CONFIG_DB_FILE)
1801+
if golden_config_path:
1802+
if not os.path.isfile(golden_config_path):
1803+
click.secho("Cannot find '{}'!".format(golden_config_path),
1804+
fg='magenta')
1805+
raise click.Abort()
1806+
override_config_by(golden_config_path)
1807+
else:
1808+
if os.path.isfile(DEFAULT_GOLDEN_CONFIG_DB_FILE):
1809+
override_config_by(DEFAULT_GOLDEN_CONFIG_DB_FILE)
18021810

18031811
# We first run "systemctl reset-failed" to remove the "failed"
18041812
# status from all services before we attempt to restart them

tests/config_test.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,20 @@ def is_file_side_effect(filename):
430430
assert result.exit_code == 0
431431
assert expected_output in result.output
432432

433+
def test_load_minigraph_with_golden_config_path(self, get_cmd_module):
434+
def is_file_side_effect(filename):
435+
return True if 'golden_config' in filename else False
436+
with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command, \
437+
mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)):
438+
(config, show) = get_cmd_module
439+
runner = CliRunner()
440+
result = runner.invoke(config.config.commands["load_minigraph"], ["-p", "golden_config.json", "-y"])
441+
print(result.exit_code)
442+
print(result.output)
443+
traceback.print_tb(result.exc_info[2])
444+
assert result.exit_code == 0
445+
assert "config override-config-table golden_config.json" in result.output
446+
433447
def test_load_minigraph_with_traffic_shift_away(self, get_cmd_module):
434448
with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command:
435449
(config, show) = get_cmd_module

0 commit comments

Comments
 (0)