Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,28 @@ def test_show_dhcp_server_ipv4_info_with_customized_options(self, mock_db):
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
assert result.stdout == expected_stdout

def test_show_dhcp_server_ipv4_option_without_name(self, mock_db):
expected_stdout = """\
Option Name Option ID Value Type
------------- ----------- ----------- ------
option60 60 dummy_value string
"""
runner = CliRunner()
db = clicommon.Db()
db.db = mock_db
result = runner.invoke(show_dhcp_server.dhcp_server.commands["ipv4"].commands["option"], [], obj=db)
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
assert result.stdout == expected_stdout

def test_show_dhcp_server_ipv4_option_with_name(self, mock_db):
expected_stdout = """\
Option Name Option ID Value Type
------------- ----------- ----------- ------
option60 60 dummy_value string
"""
runner = CliRunner()
db = clicommon.Db()
db.db = mock_db
result = runner.invoke(show_dhcp_server.dhcp_server.commands["ipv4"].commands["option"], ["option60"], obj=db)
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
assert result.stdout == expected_stdout
16 changes: 16 additions & 0 deletions dockers/docker-dhcp-server/cli/show/plugins/show_dhcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,21 @@ def info(db, dhcp_interface, with_customized_options):
click.echo(tabulate(table, headers=headers))


@ipv4.command()
@click.argument("option_name", required=False)
@clicommon.pass_db
def option(db, option_name):
if not option_name:
option_name = "*"
headers = ["Option Name", "Option ID", "Value", "Type"]
table = []
dbconn = db.db
for key in dbconn.keys("CONFIG_DB", "DHCP_SERVER_IPV4_CUSTOMIZED_OPTIONS|" + option_name):
entry = dbconn.get_all("CONFIG_DB", key)
name = key.split("|")[1]
table.append([name, entry["id"], entry["value"], entry["type"]])
click.echo(tabulate(table, headers=headers))


def register(cli):
cli.add_command(dhcp_server)