Skip to content

Commit 504ebe6

Browse files
tjchadagayxieca
authored andcommitted
Add 'traffic_shift_away' option to config load_minigraph (#2240)
1 parent 4079e4a commit 504ebe6

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

config/main.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1611,8 +1611,9 @@ def load_mgmt_config(filename):
16111611
@click.option('-y', '--yes', is_flag=True, callback=_abort_if_false,
16121612
expose_value=False, prompt='Reload config from minigraph?')
16131613
@click.option('-n', '--no_service_restart', default=False, is_flag=True, help='Do not restart docker services')
1614+
@click.option('-t', '--traffic_shift_away', default=False, is_flag=True, help='Keep device in maintenance with TSA')
16141615
@clicommon.pass_db
1615-
def load_minigraph(db, no_service_restart):
1616+
def load_minigraph(db, no_service_restart, traffic_shift_away):
16161617
"""Reconfigure based on minigraph."""
16171618
log.log_info("'load_minigraph' executing...")
16181619

@@ -1682,6 +1683,13 @@ def load_minigraph(db, no_service_restart):
16821683
cfggen_namespace_option = " -n {}".format(namespace)
16831684
clicommon.run_command(db_migrator + ' -o set_version' + cfggen_namespace_option)
16841685

1686+
# Keep device isolated with TSA
1687+
if traffic_shift_away:
1688+
clicommon.run_command("TSA", display_cmd=True)
1689+
if os.path.isfile(DEFAULT_GOLDEN_CONFIG_DB_FILE):
1690+
log.log_warning("Golden configuration may override System Maintenance state. Please execute TSC to check the current System mode")
1691+
click.secho("[WARNING] Golden configuration may override Traffic-shift-away state. Please execute TSC to check the current System mode")
1692+
16851693
# Load golden_config_db.json
16861694
if os.path.isfile(DEFAULT_GOLDEN_CONFIG_DB_FILE):
16871695
override_config_by(DEFAULT_GOLDEN_CONFIG_DB_FILE)

doc/Command-Reference.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -5149,9 +5149,11 @@ When user specifies the optional argument "-n" or "--no-service-restart", this c
51495149
running on the device. One use case for this option is during boot time when config-setup service loads minigraph configuration and there is no services
51505150
running on the device.
51515151
5152+
When user specifies the optional argument "-t" or "--traffic-shift-away", this command executes TSA command at the end to ensure the device remains in maintenance after loading minigraph.
5153+
51525154
- Usage:
51535155
```
5154-
config load_minigraph [-y|--yes] [-n|--no-service-restart]
5156+
config load_minigraph [-y|--yes] [-n|--no-service-restart] [-t|--traffic-shift-away]
51555157
```
51565158
51575159
- Example:

tests/config_test.py

+28
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,34 @@ def is_file_side_effect(filename):
402402
assert result.exit_code == 0
403403
assert expected_output in result.output
404404

405+
def test_load_minigraph_with_traffic_shift_away(self, get_cmd_module):
406+
with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command:
407+
(config, show) = get_cmd_module
408+
runner = CliRunner()
409+
result = runner.invoke(config.config.commands["load_minigraph"], ["-ty"])
410+
print(result.exit_code)
411+
print(result.output)
412+
traceback.print_tb(result.exc_info[2])
413+
assert result.exit_code == 0
414+
assert "TSA" in result.output
415+
416+
def test_load_minigraph_with_traffic_shift_away_with_golden_config(self, get_cmd_module):
417+
with mock.patch("utilities_common.cli.run_command", mock.MagicMock(side_effect=mock_run_command_side_effect)) as mock_run_command:
418+
def is_file_side_effect(filename):
419+
return True if 'golden_config' in filename else False
420+
with mock.patch('os.path.isfile', mock.MagicMock(side_effect=is_file_side_effect)):
421+
(config, show) = get_cmd_module
422+
db = Db()
423+
golden_config = {}
424+
runner = CliRunner()
425+
result = runner.invoke(config.config.commands["load_minigraph"], ["-ty"])
426+
print(result.exit_code)
427+
print(result.output)
428+
traceback.print_tb(result.exc_info[2])
429+
assert result.exit_code == 0
430+
assert "TSA" in result.output
431+
assert "[WARNING] Golden configuration may override Traffic-shift-away state" in result.output
432+
405433
@classmethod
406434
def teardown_class(cls):
407435
os.environ['UTILITIES_UNIT_TESTING'] = "0"

0 commit comments

Comments
 (0)