Skip to content

Commit a255838

Browse files
wen587yxieca
authored andcommitted
[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 99425a8 commit a255838

2 files changed

Lines changed: 22 additions & 35 deletions

File tree

config/main.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,9 +1645,10 @@ def load_mgmt_config(filename):
16451645
expose_value=False, prompt='Reload config from minigraph?')
16461646
@click.option('-n', '--no_service_restart', default=False, is_flag=True, help='Do not restart docker services')
16471647
@click.option('-t', '--traffic_shift_away', default=False, is_flag=True, help='Keep device in maintenance with TSA')
1648-
@click.option('-p', '--golden_config_path', help='The path of golden config file')
1648+
@click.option('-o', '--override_config', default=False, is_flag=True, help='Enable config override. Proceed with default path.')
1649+
@click.option('-p', '--golden_config_path', help='Provide golden config path to override. Use with --override_config')
16491650
@clicommon.pass_db
1650-
def load_minigraph(db, no_service_restart, traffic_shift_away, golden_config_path):
1651+
def load_minigraph(db, no_service_restart, traffic_shift_away, override_config, golden_config_path):
16511652
"""Reconfigure based on minigraph."""
16521653
log.log_info("'load_minigraph' executing...")
16531654

@@ -1720,20 +1721,19 @@ def load_minigraph(db, no_service_restart, traffic_shift_away, golden_config_pat
17201721
# Keep device isolated with TSA
17211722
if traffic_shift_away:
17221723
clicommon.run_command("TSA", display_cmd=True)
1723-
if golden_config_path or not golden_config_path and os.path.isfile(DEFAULT_GOLDEN_CONFIG_DB_FILE):
1724+
if override_config:
17241725
log.log_warning("Golden configuration may override System Maintenance state. Please execute TSC to check the current System mode")
17251726
click.secho("[WARNING] Golden configuration may override Traffic-shift-away state. Please execute TSC to check the current System mode")
17261727

17271728
# Load golden_config_db.json
1728-
if golden_config_path:
1729+
if override_config:
1730+
if golden_config_path is None:
1731+
golden_config_path = DEFAULT_GOLDEN_CONFIG_DB_FILE
17291732
if not os.path.isfile(golden_config_path):
17301733
click.secho("Cannot find '{}'!".format(golden_config_path),
17311734
fg='magenta')
17321735
raise click.Abort()
17331736
override_config_by(golden_config_path)
1734-
else:
1735-
if os.path.isfile(DEFAULT_GOLDEN_CONFIG_DB_FILE):
1736-
override_config_by(DEFAULT_GOLDEN_CONFIG_DB_FILE)
17371737

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

tests/config_test.py

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -376,52 +376,39 @@ def is_file_side_effect(filename):
376376
assert result.exit_code == 0
377377
assert expected_output in result.output
378378

379-
def test_load_minigraph_with_golden_config(self, get_cmd_module, setup_single_broadcom_asic):
380-
with mock.patch(
381-
"utilities_common.cli.run_command",
382-
mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command:
383-
(config, show) = get_cmd_module
384-
db = Db()
385-
golden_config = {}
386-
self.check_golden_config(db, config, golden_config,
387-
"config override-config-table /etc/sonic/golden_config_db.json")
388-
389-
def check_golden_config(self, db, config, golden_config, expected_output):
390-
def is_file_side_effect(filename):
391-
return True if 'golden_config' in filename else False
392-
with mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)):
393-
runner = CliRunner()
394-
result = runner.invoke(config.config.commands["load_minigraph"], ["-y"], obj=db)
395-
print(result.exit_code)
396-
print(result.output)
397-
assert result.exit_code == 0
398-
assert expected_output in result.output
399-
400379
def test_load_minigraph_with_non_exist_golden_config_path(self, get_cmd_module):
401380
def is_file_side_effect(filename):
402381
return True if 'golden_config' in filename else False
403382
with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command, \
404383
mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)):
405384
(config, show) = get_cmd_module
406385
runner = CliRunner()
407-
result = runner.invoke(config.config.commands["load_minigraph"], ["-p", "non_exist.json", "-y"])
386+
result = runner.invoke(config.config.commands["load_minigraph"], ["--override_config", "--golden_config_path", "non_exist.json", "-y"])
408387
assert result.exit_code != 0
409388
assert "Cannot find 'non_exist.json'" in result.output
410389

411-
def test_load_minigraph_with_golden_config_path(self, get_cmd_module):
390+
def test_load_minigraph_with_specified_golden_config_path(self, get_cmd_module):
412391
def is_file_side_effect(filename):
413392
return True if 'golden_config' in filename else False
414393
with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command, \
415394
mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)):
416395
(config, show) = get_cmd_module
417396
runner = CliRunner()
418-
result = runner.invoke(config.config.commands["load_minigraph"], ["-p", "golden_config.json", "-y"])
419-
print(result.exit_code)
420-
print(result.output)
421-
traceback.print_tb(result.exc_info[2])
397+
result = runner.invoke(config.config.commands["load_minigraph"], ["--override_config", "--golden_config_path", "golden_config.json", "-y"])
422398
assert result.exit_code == 0
423399
assert "config override-config-table golden_config.json" in result.output
424400

401+
def test_load_minigraph_with_default_golden_config_path(self, get_cmd_module):
402+
def is_file_side_effect(filename):
403+
return True if 'golden_config' in filename else False
404+
with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command, \
405+
mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)):
406+
(config, show) = get_cmd_module
407+
runner = CliRunner()
408+
result = runner.invoke(config.config.commands["load_minigraph"], ["--override_config", "-y"])
409+
assert result.exit_code == 0
410+
assert "config override-config-table /etc/sonic/golden_config_db.json" in result.output
411+
425412
def test_load_minigraph_with_traffic_shift_away(self, get_cmd_module):
426413
with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command:
427414
(config, show) = get_cmd_module
@@ -442,7 +429,7 @@ def is_file_side_effect(filename):
442429
db = Db()
443430
golden_config = {}
444431
runner = CliRunner()
445-
result = runner.invoke(config.config.commands["load_minigraph"], ["-ty"])
432+
result = runner.invoke(config.config.commands["load_minigraph"], ["-ty", "--override_config"])
446433
print(result.exit_code)
447434
print(result.output)
448435
traceback.print_tb(result.exc_info[2])

0 commit comments

Comments
 (0)