add config dhcp_server disable (#17689)

This commit is contained in:
Xichen96 2024-01-10 12:59:13 +08:00 committed by GitHub
parent b2ca36aa1c
commit 5987dcf59e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 4 deletions

View File

@ -143,3 +143,18 @@ class TestConfigDHCPServer(object):
result = runner.invoke(dhcp_server.dhcp_server.commands["ipv4"].commands["enable"], ["Vlan200"], obj=db)
assert result.exit_code == 2, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
def test_config_dhcp_server_ipv4_disable_already_exist(self, mock_db):
runner = CliRunner()
db = clicommon.Db()
db.db = mock_db
result = runner.invoke(dhcp_server.dhcp_server.commands["ipv4"].commands["disable"], ["Vlan100"], obj=db)
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
assert mock_db.get("CONFIG_DB", "DHCP_SERVER_IPV4|Vlan300", "state") == "disabled"
def test_config_dhcp_server_ipv4_disable_does_not_exist(self, mock_db):
runner = CliRunner()
db = clicommon.Db()
db.db = mock_db
result = runner.invoke(dhcp_server.dhcp_server.commands["ipv4"].commands["disable"], ["Vlan200"], obj=db)
assert result.exit_code == 2, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)

View File

@ -91,7 +91,7 @@ def dhcp_server_ipv4_add(db, mode, lease_time, dup_gw_nm, gateway, netmask, dhcp
ctx.fail("gateway and netmask must be valid ipv4 string")
key = "DHCP_SERVER_IPV4|" + dhcp_interface
if dbconn.exists("CONFIG_DB", key):
ctx.fail("Dhcp_interface %s already exist".format(dhcp_interface))
ctx.fail("Dhcp_interface {} already exist".format(dhcp_interface))
else:
dbconn.hmset("CONFIG_DB", key, {
"mode": mode,
@ -110,10 +110,10 @@ def dhcp_server_ipv4_del(db, dhcp_interface):
dbconn = db.db
key = "DHCP_SERVER_IPV4|" + dhcp_interface
if dbconn.exists("CONFIG_DB", key):
click.echo("Dhcp interface %s exists in config db, proceed to delete".format(dhcp_interface))
click.echo("Dhcp interface {} exists in config db, proceed to delete".format(dhcp_interface))
dbconn.delete("CONFIG_DB", key)
else:
ctx.fail("Dhcp interface %s does not exist in config db".format(dhcp_interface))
ctx.fail("Dhcp interface {} does not exist in config db".format(dhcp_interface))
@dhcp_server_ipv4.command(name="enable")
@ -126,7 +126,20 @@ def dhcp_server_ipv4_enable(db, dhcp_interface):
if dbconn.exists("CONFIG_DB", key):
dbconn.set("CONFIG_DB", key, "state", "enabled")
else:
ctx.fail("Failed to enable, dhcp interface %s does not exist".format(dhcp_interface))
ctx.fail("Failed to enable, dhcp interface {} does not exist".format(dhcp_interface))
@dhcp_server_ipv4.command(name="disable")
@click.argument("dhcp_interface", required=True)
@clicommon.pass_db
def dhcp_server_ipv4_disable(db, dhcp_interface):
ctx = click.get_current_context()
dbconn = db.db
key = "DHCP_SERVER_IPV4|" + dhcp_interface
if dbconn.exists("CONFIG_DB", key):
dbconn.set("CONFIG_DB", key, "state", "disabled")
else:
ctx.fail("Failed to disable, dhcp interface {} does not exist".format(dhcp_interface))
def register(cli):