diff --git a/config/vlan.py b/config/vlan.py index 03660ab0af..75135b3ed7 100644 --- a/config/vlan.py +++ b/config/vlan.py @@ -26,7 +26,8 @@ def set_dhcp_relay_table(table, config_db, vlan_name, value): def is_dhcp_relay_running(): - out, _ = clicommon.run_command("systemctl show dhcp_relay.service --property ActiveState --value", return_cmd=True) + out, _ = clicommon.run_command(["systemctl", "show", "dhcp_relay.service", "--property", "ActiveState", "--value"], + return_cmd=True) return out.strip() == "active" diff --git a/tests/mock_tables/config_db.json b/tests/mock_tables/config_db.json index 8861d43a75..510f57eb6e 100644 --- a/tests/mock_tables/config_db.json +++ b/tests/mock_tables/config_db.json @@ -2691,5 +2691,10 @@ "alias": "Fabric2", "isolateStatus": "False", "lanes": "2" + }, + "DHCP_RELAY|Vlan1000": { + "dhcpv6_servers": [ + "fc02:2000::1" + ] } } diff --git a/tests/vlan_test.py b/tests/vlan_test.py index 13364f76e6..9722ced6d0 100644 --- a/tests/vlan_test.py +++ b/tests/vlan_test.py @@ -760,3 +760,37 @@ def teardown_class(cls): os.environ['UTILITIES_UNIT_TESTING'] = "0" bgp_util.run_bgp_command = cls._old_run_bgp_command print("TEARDOWN") + + def test_config_vlan_del_dhcp_relay_restart(self): + runner = CliRunner() + db = Db() + obj = {"config_db": db.cfgdb} + + # remove vlan IP`s + result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["remove"], + ["Vlan1000", "192.168.0.1/21"], obj=obj) + print(result.exit_code, result.output) + assert result.exit_code != 0 + + result = runner.invoke(config.config.commands["interface"].commands["ip"].commands["remove"], + ["Vlan1000", "fc02:1000::1/64"], obj=obj) + print(result.exit_code, result.output) + assert result.exit_code != 0 + + # remove vlan members + vlan_member = db.cfgdb.get_table("VLAN_MEMBER") + keys = [(k, v) for k, v in vlan_member if k == "Vlan{}".format(1000)] + for _, v in keys: + result = runner.invoke(config.config.commands["vlan"].commands["member"].commands["del"], ["1000", v], obj=db) + print(result.exit_code) + print(result.output) + assert result.exit_code == 0 + + origin_run_command_func = config.vlan.clicommon.run_command + config.vlan.clicommon.run_command = mock.MagicMock(return_value=("active", 0)) + result = runner.invoke(config.config.commands["vlan"].commands["del"], ["1000"], obj=db) + print(result.exit_code) + print(result.output) + assert result.exit_code == 0 + + config.vlan.clicommon.run_command = origin_run_command_func diff --git a/utilities_common/dhcp_relay_util.py b/utilities_common/dhcp_relay_util.py index b9c0b4e20f..4a0ab5a2e4 100644 --- a/utilities_common/dhcp_relay_util.py +++ b/utilities_common/dhcp_relay_util.py @@ -7,9 +7,9 @@ def restart_dhcp_relay_service(): Restart dhcp_relay service """ click.echo("Restarting DHCP relay service...") - clicommon.run_command("systemctl stop dhcp_relay", display_cmd=False) - clicommon.run_command("systemctl reset-failed dhcp_relay", display_cmd=False) - clicommon.run_command("systemctl start dhcp_relay", display_cmd=False) + clicommon.run_command(["systemctl", "stop", "dhcp_relay"], display_cmd=False) + clicommon.run_command(["systemctl", "reset-failed", "dhcp_relay"], display_cmd=False) + clicommon.run_command(["systemctl", "start", "dhcp_relay"], display_cmd=False) def handle_restart_dhcp_relay_service():