Skip to content

Commit 81e2aec

Browse files
authored
[minigraph] new workflow for golden path (#2396)
#### What I did Change the behavior that load_minigraph will consume golden config by default. New behavior: `config load_minigraph`: No longer consume golden config. `config load_minigraph --golden_config`: Consume default golden config. /etc/sonic/golden_config_db.json `config load_minigraph --golden_config FilePath`: Consume golden config with FilePath #### How I did it Make golden_config click.Option() and add an argument for golden config path. #### How to verify it UT test. #### Previous command output (if the output of a command-line utility has changed) sudo config load_minigraph -h Usage: config load_minigraph [OPTIONS] Reconfigure based on minigraph. Options: -y, --yes -n, --no_service_restart Do not restart docker services -t, --traffic_shift_away Keep device in maintenance with TSA -p, --golden_config_path TEXT specify Golden Config path -?, -h, --help Show this message and exit. #### New command output (if the output of a command-line utility has changed) admin@vlab-01:~$ sudo config load_minigraph --golden_config_path -h Usage: config load_minigraph [OPTIONS] Reconfigure based on minigraph. Options: -y, --yes -n, --no_service_restart Do not restart docker services -t, --traffic_shift_away Keep device in maintenance with TSA -o, --override_config Enable config override. Proceed with default path. -p, --golden_config_path TEXT Provide golden config path to override. Use with --override_config -h, -?, --help Show this message and exit.
1 parent c1206aa commit 81e2aec

File tree

2 files changed

+22
-35
lines changed

2 files changed

+22
-35
lines changed

config/main.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1727,9 +1727,10 @@ def load_mgmt_config(filename):
17271727
expose_value=False, prompt='Reload config from minigraph?')
17281728
@click.option('-n', '--no_service_restart', default=False, is_flag=True, help='Do not restart docker services')
17291729
@click.option('-t', '--traffic_shift_away', default=False, is_flag=True, help='Keep device in maintenance with TSA')
1730-
@click.option('-p', '--golden_config_path', help='The path of golden config file')
1730+
@click.option('-o', '--override_config', default=False, is_flag=True, help='Enable config override. Proceed with default path.')
1731+
@click.option('-p', '--golden_config_path', help='Provide golden config path to override. Use with --override_config')
17311732
@clicommon.pass_db
1732-
def load_minigraph(db, no_service_restart, traffic_shift_away, golden_config_path):
1733+
def load_minigraph(db, no_service_restart, traffic_shift_away, override_config, golden_config_path):
17331734
"""Reconfigure based on minigraph."""
17341735
log.log_info("'load_minigraph' executing...")
17351736

@@ -1802,20 +1803,19 @@ def load_minigraph(db, no_service_restart, traffic_shift_away, golden_config_pat
18021803
# Keep device isolated with TSA
18031804
if traffic_shift_away:
18041805
clicommon.run_command("TSA", display_cmd=True)
1805-
if golden_config_path or not golden_config_path and os.path.isfile(DEFAULT_GOLDEN_CONFIG_DB_FILE):
1806+
if override_config:
18061807
log.log_warning("Golden configuration may override System Maintenance state. Please execute TSC to check the current System mode")
18071808
click.secho("[WARNING] Golden configuration may override Traffic-shift-away state. Please execute TSC to check the current System mode")
18081809

18091810
# Load golden_config_db.json
1810-
if golden_config_path:
1811+
if override_config:
1812+
if golden_config_path is None:
1813+
golden_config_path = DEFAULT_GOLDEN_CONFIG_DB_FILE
18111814
if not os.path.isfile(golden_config_path):
18121815
click.secho("Cannot find '{}'!".format(golden_config_path),
18131816
fg='magenta')
18141817
raise click.Abort()
18151818
override_config_by(golden_config_path)
1816-
else:
1817-
if os.path.isfile(DEFAULT_GOLDEN_CONFIG_DB_FILE):
1818-
override_config_by(DEFAULT_GOLDEN_CONFIG_DB_FILE)
18191819

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

tests/config_test.py

+15-28
Original file line numberDiff line numberDiff line change
@@ -411,52 +411,39 @@ def is_file_side_effect(filename):
411411
assert result.exit_code == 0
412412
assert expected_output in result.output
413413

414-
def test_load_minigraph_with_golden_config(self, get_cmd_module, setup_single_broadcom_asic):
415-
with mock.patch(
416-
"utilities_common.cli.run_command",
417-
mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command:
418-
(config, show) = get_cmd_module
419-
db = Db()
420-
golden_config = {}
421-
self.check_golden_config(db, config, golden_config,
422-
"config override-config-table /etc/sonic/golden_config_db.json")
423-
424-
def check_golden_config(self, db, config, golden_config, expected_output):
425-
def is_file_side_effect(filename):
426-
return True if 'golden_config' in filename else False
427-
with mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)):
428-
runner = CliRunner()
429-
result = runner.invoke(config.config.commands["load_minigraph"], ["-y"], obj=db)
430-
print(result.exit_code)
431-
print(result.output)
432-
assert result.exit_code == 0
433-
assert expected_output in result.output
434-
435414
def test_load_minigraph_with_non_exist_golden_config_path(self, get_cmd_module):
436415
def is_file_side_effect(filename):
437416
return True if 'golden_config' in filename else False
438417
with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command, \
439418
mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)):
440419
(config, show) = get_cmd_module
441420
runner = CliRunner()
442-
result = runner.invoke(config.config.commands["load_minigraph"], ["-p", "non_exist.json", "-y"])
421+
result = runner.invoke(config.config.commands["load_minigraph"], ["--override_config", "--golden_config_path", "non_exist.json", "-y"])
443422
assert result.exit_code != 0
444423
assert "Cannot find 'non_exist.json'" in result.output
445424

446-
def test_load_minigraph_with_golden_config_path(self, get_cmd_module):
425+
def test_load_minigraph_with_specified_golden_config_path(self, get_cmd_module):
447426
def is_file_side_effect(filename):
448427
return True if 'golden_config' in filename else False
449428
with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command, \
450429
mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)):
451430
(config, show) = get_cmd_module
452431
runner = CliRunner()
453-
result = runner.invoke(config.config.commands["load_minigraph"], ["-p", "golden_config.json", "-y"])
454-
print(result.exit_code)
455-
print(result.output)
456-
traceback.print_tb(result.exc_info[2])
432+
result = runner.invoke(config.config.commands["load_minigraph"], ["--override_config", "--golden_config_path", "golden_config.json", "-y"])
457433
assert result.exit_code == 0
458434
assert "config override-config-table golden_config.json" in result.output
459435

436+
def test_load_minigraph_with_default_golden_config_path(self, get_cmd_module):
437+
def is_file_side_effect(filename):
438+
return True if 'golden_config' in filename else False
439+
with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command, \
440+
mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)):
441+
(config, show) = get_cmd_module
442+
runner = CliRunner()
443+
result = runner.invoke(config.config.commands["load_minigraph"], ["--override_config", "-y"])
444+
assert result.exit_code == 0
445+
assert "config override-config-table /etc/sonic/golden_config_db.json" in result.output
446+
460447
def test_load_minigraph_with_traffic_shift_away(self, get_cmd_module):
461448
with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command:
462449
(config, show) = get_cmd_module
@@ -477,7 +464,7 @@ def is_file_side_effect(filename):
477464
db = Db()
478465
golden_config = {}
479466
runner = CliRunner()
480-
result = runner.invoke(config.config.commands["load_minigraph"], ["-ty"])
467+
result = runner.invoke(config.config.commands["load_minigraph"], ["-ty", "--override_config"])
481468
print(result.exit_code)
482469
print(result.output)
483470
traceback.print_tb(result.exc_info[2])

0 commit comments

Comments
 (0)