From 5b5a8e63f3775d8ad34c53cc7b3a22e45ff947a4 Mon Sep 17 00:00:00 2001 From: Tejaswini Chadaga Date: Wed, 29 Jun 2022 07:18:35 +0000 Subject: [PATCH 1/4] Adding load_minigraph option --- config/main.py | 7 ++++++- tests/config_test.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/config/main.py b/config/main.py index 16aea6b610..2992b5912d 100644 --- a/config/main.py +++ b/config/main.py @@ -1641,8 +1641,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...") @@ -1712,6 +1713,10 @@ def load_minigraph(db, no_service_restart): if os.path.isfile(DEFAULT_GOLDEN_CONFIG_DB_FILE): override_config_by(DEFAULT_GOLDEN_CONFIG_DB_FILE) + # Keep device in maintenance with TSA + if traffic_shift_away: + clicommon.run_command("TSA", display_cmd=True) + # We first run "systemctl reset-failed" to remove the "failed" # status from all services before we attempt to restart them if not no_service_restart: diff --git a/tests/config_test.py b/tests/config_test.py index 87b66f7e61..31ba737905 100644 --- a/tests/config_test.py +++ b/tests/config_test.py @@ -356,6 +356,17 @@ 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 + @classmethod def teardown_class(cls): os.environ['UTILITIES_UNIT_TESTING'] = "0" From c433ba9dd63f85ccf65f60644ad7e56cb13453a1 Mon Sep 17 00:00:00 2001 From: Tejaswini Chadaga Date: Wed, 29 Jun 2022 07:32:58 +0000 Subject: [PATCH 2/4] Doc update --- doc/Command-Reference.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index ebba414a53..b11ececb92 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -5106,9 +5106,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: From 0908d432411eed18cc9d693211ceba4dd6060604 Mon Sep 17 00:00:00 2001 From: Tejaswini Chadaga Date: Fri, 8 Jul 2022 01:59:14 +0000 Subject: [PATCH 3/4] Moved TSA check before golden config override --- config/main.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/config/main.py b/config/main.py index da1b83496e..f95c64c2b8 100644 --- a/config/main.py +++ b/config/main.py @@ -1757,14 +1757,17 @@ def load_minigraph(db, no_service_restart, traffic_shift_away): 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) - # Keep device in maintenance with TSA - if traffic_shift_away: - clicommon.run_command("TSA", display_cmd=True) - # We first run "systemctl reset-failed" to remove the "failed" # status from all services before we attempt to restart them if not no_service_restart: From 9bff4e4a47da31910294c78d3a8c3371b047eb36 Mon Sep 17 00:00:00 2001 From: Tejaswini Chadaga Date: Fri, 8 Jul 2022 22:02:57 +0000 Subject: [PATCH 4/4] Added another test case --- tests/config_test.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/config_test.py b/tests/config_test.py index 06fc1ddf35..18fa251e9b 100644 --- a/tests/config_test.py +++ b/tests/config_test.py @@ -446,6 +446,23 @@ def test_load_minigraph_with_traffic_shift_away(self, get_cmd_module): 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"