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

Add 'traffic_shift_away' option to config load_minigraph #2240

Merged
merged 6 commits into from
Jul 8, 2022
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
10 changes: 9 additions & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1685,8 +1685,9 @@ def load_mgmt_config(filename):
@click.option('-y', '--yes', is_flag=True, callback=_abort_if_false,
expose_value=False, prompt='Reload config from minigraph?')
@click.option('-n', '--no_service_restart', default=False, is_flag=True, help='Do not restart docker services')
@click.option('-t', '--traffic_shift_away', default=False, is_flag=True, help='Keep device in maintenance with TSA')
@clicommon.pass_db
def load_minigraph(db, no_service_restart):
def load_minigraph(db, no_service_restart, traffic_shift_away):
"""Reconfigure based on minigraph."""
log.log_info("'load_minigraph' executing...")

Expand Down Expand Up @@ -1756,6 +1757,13 @@ def load_minigraph(db, no_service_restart):
cfggen_namespace_option = " -n {}".format(namespace)
clicommon.run_command(db_migrator + ' -o set_version' + cfggen_namespace_option)

# Keep device isolated with TSA
if traffic_shift_away:
clicommon.run_command("TSA", display_cmd=True)
if os.path.isfile(DEFAULT_GOLDEN_CONFIG_DB_FILE):
log.log_warning("Golden configuration may override System Maintenance state. Please execute TSC to check the current System mode")
click.secho("[WARNING] Golden configuration may override Traffic-shift-away state. Please execute TSC to check the current System mode")

# Load golden_config_db.json
if os.path.isfile(DEFAULT_GOLDEN_CONFIG_DB_FILE):
override_config_by(DEFAULT_GOLDEN_CONFIG_DB_FILE)
Expand Down
4 changes: 3 additions & 1 deletion doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -5149,9 +5149,11 @@ When user specifies the optional argument "-n" or "--no-service-restart", this c
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
running on the device.

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.

- Usage:
```
config load_minigraph [-y|--yes] [-n|--no-service-restart]
config load_minigraph [-y|--yes] [-n|--no-service-restart] [-t|--traffic-shift-away]
```

- Example:
Expand Down
28 changes: 28 additions & 0 deletions tests/config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,34 @@ def is_file_side_effect(filename):
assert result.exit_code == 0
assert expected_output in result.output

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:
(config, show) = get_cmd_module
runner = CliRunner()
result = runner.invoke(config.config.commands["load_minigraph"], ["-ty"])
print(result.exit_code)
print(result.output)
traceback.print_tb(result.exc_info[2])
assert result.exit_code == 0
assert "TSA" in result.output

def test_load_minigraph_with_traffic_shift_away_with_golden_config(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:
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)):
(config, show) = get_cmd_module
db = Db()
golden_config = {}
runner = CliRunner()
result = runner.invoke(config.config.commands["load_minigraph"], ["-ty"])
print(result.exit_code)
print(result.output)
traceback.print_tb(result.exc_info[2])
assert result.exit_code == 0
assert "TSA" in result.output
assert "[WARNING] Golden configuration may override Traffic-shift-away state" in result.output

@classmethod
def teardown_class(cls):
os.environ['UTILITIES_UNIT_TESTING'] = "0"
Expand Down