[dhcp_server] improve show dhcp server output (#17734)

* fix show dhcp_server semantics
* show dhcp_server table format
This commit is contained in:
Xichen96
2024-01-11 02:34:22 +08:00
committed by GitHub
parent 0ecab6cfbc
commit 24e995024b
2 changed files with 124 additions and 90 deletions

View File

@@ -16,11 +16,15 @@ class TestShowDHCPServer(object):
def test_show_dhcp_server_ipv4_lease_without_dhcpintf(self, mock_db):
expected_stdout = """\
Interface MAC Address IP Lease Start Lease End
------------------- ----------------- ----------- ------------------- -------------------
Vlan1000|Ethernet10 10:70:fd:b6:13:00 192.168.0.1 2023-03-01 03:16:21 2023-03-01 03:31:21
Vlan1000|Ethernet11 10:70:fd:b6:13:01 192.168.0.2 2023-03-01 03:16:21 2023-03-01 03:31:21
Vlan1001|<Unknown> 10:70:fd:b6:13:02 192.168.0.3 2023-03-01 03:16:21 2023-03-01 03:31:21
+---------------------+-------------------+-------------+---------------------+---------------------+
| Interface | MAC Address | IP | Lease Start | Lease End |
+=====================+===================+=============+=====================+=====================+
| Vlan1000|Ethernet10 | 10:70:fd:b6:13:00 | 192.168.0.1 | 2023-03-01 03:16:21 | 2023-03-01 03:31:21 |
+---------------------+-------------------+-------------+---------------------+---------------------+
| Vlan1000|Ethernet11 | 10:70:fd:b6:13:01 | 192.168.0.2 | 2023-03-01 03:16:21 | 2023-03-01 03:31:21 |
+---------------------+-------------------+-------------+---------------------+---------------------+
| Vlan1001|<Unknown> | 10:70:fd:b6:13:02 | 192.168.0.3 | 2023-03-01 03:16:21 | 2023-03-01 03:31:21 |
+---------------------+-------------------+-------------+---------------------+---------------------+
"""
runner = CliRunner()
db = clicommon.Db()
@@ -31,10 +35,13 @@ Vlan1001|<Unknown> 10:70:fd:b6:13:02 192.168.0.3 2023-03-01 03:16:21 2023-0
def test_show_dhcp_server_ipv4_lease_with_dhcpintf(self, mock_db):
expected_stdout = """\
Interface MAC Address IP Lease Start Lease End
------------------- ----------------- ----------- ------------------- -------------------
Vlan1000|Ethernet10 10:70:fd:b6:13:00 192.168.0.1 2023-03-01 03:16:21 2023-03-01 03:31:21
Vlan1000|Ethernet11 10:70:fd:b6:13:01 192.168.0.2 2023-03-01 03:16:21 2023-03-01 03:31:21
+---------------------+-------------------+-------------+---------------------+---------------------+
| Interface | MAC Address | IP | Lease Start | Lease End |
+=====================+===================+=============+=====================+=====================+
| Vlan1000|Ethernet10 | 10:70:fd:b6:13:00 | 192.168.0.1 | 2023-03-01 03:16:21 | 2023-03-01 03:31:21 |
+---------------------+-------------------+-------------+---------------------+---------------------+
| Vlan1000|Ethernet11 | 10:70:fd:b6:13:01 | 192.168.0.2 | 2023-03-01 03:16:21 | 2023-03-01 03:31:21 |
+---------------------+-------------------+-------------+---------------------+---------------------+
"""
runner = CliRunner()
db = clicommon.Db()
@@ -45,9 +52,11 @@ Vlan1000|Ethernet11 10:70:fd:b6:13:01 192.168.0.2 2023-03-01 03:16:21 2023-0
def test_show_dhcp_server_ipv4_lease_client_not_in_fdb(self, mock_db):
expected_stdout = """\
Interface MAC Address IP Lease Start Lease End
------------------ ----------------- ----------- ------------------- -------------------
Vlan1001|<Unknown> 10:70:fd:b6:13:02 192.168.0.3 2023-03-01 03:16:21 2023-03-01 03:31:21
+--------------------+-------------------+-------------+---------------------+---------------------+
| Interface | MAC Address | IP | Lease Start | Lease End |
+====================+===================+=============+=====================+=====================+
| Vlan1001|<Unknown> | 10:70:fd:b6:13:02 | 192.168.0.3 | 2023-03-01 03:16:21 | 2023-03-01 03:31:21 |
+--------------------+-------------------+-------------+---------------------+---------------------+
"""
runner = CliRunner()
db = clicommon.Db()
@@ -58,11 +67,15 @@ Vlan1001|<Unknown> 10:70:fd:b6:13:02 192.168.0.3 2023-03-01 03:16:21 2023-03
def test_show_dhcp_server_ipv4_range_without_name(self, mock_db):
expected_stdout = """\
Range IP Start IP End IP Count
------- ---------- ---------- ----------------------
range1 100.1.1.3 100.1.1.5 3
range2 100.1.1.9 100.1.1.8 range value is illegal
range3 100.1.1.10 100.1.1.10 1
+---------+------------+------------+------------------------+
| Range | IP Start | IP End | IP Count |
+=========+============+============+========================+
| range1 | 100.1.1.3 | 100.1.1.5 | 3 |
+---------+------------+------------+------------------------+
| range2 | 100.1.1.9 | 100.1.1.8 | range value is illegal |
+---------+------------+------------+------------------------+
| range3 | 100.1.1.10 | 100.1.1.10 | 1 |
+---------+------------+------------+------------------------+
"""
runner = CliRunner()
db = clicommon.Db()
@@ -73,9 +86,11 @@ range3 100.1.1.10 100.1.1.10 1
def test_show_dhcp_server_ipv4_range_with_name(self, mock_db):
expected_stdout = """\
Range IP Start IP End IP Count
------- ---------- --------- ----------
range1 100.1.1.3 100.1.1.5 3
+---------+------------+-----------+------------+
| Range | IP Start | IP End | IP Count |
+=========+============+===========+============+
| range1 | 100.1.1.3 | 100.1.1.5 | 3 |
+---------+------------+-----------+------------+
"""
runner = CliRunner()
db = clicommon.Db()
@@ -86,9 +101,11 @@ range1 100.1.1.3 100.1.1.5 3
def test_show_dhcp_server_ipv4_range_wrong_data(self, mock_db):
expected_stdout = """\
Range IP Start IP End IP Count
------- ---------- --------- ----------------------
range2 100.1.1.9 100.1.1.8 range value is illegal
+---------+------------+-----------+------------------------+
| Range | IP Start | IP End | IP Count |
+=========+============+===========+========================+
| range2 | 100.1.1.9 | 100.1.1.8 | range value is illegal |
+---------+------------+-----------+------------------------+
"""
runner = CliRunner()
db = clicommon.Db()
@@ -99,9 +116,11 @@ range2 100.1.1.9 100.1.1.8 range value is illegal
def test_show_dhcp_server_ipv4_range_single_ip(self, mock_db):
expected_stdout = """\
Range IP Start IP End IP Count
------- ---------- ---------- ----------
range3 100.1.1.10 100.1.1.10 1
+---------+------------+------------+------------+
| Range | IP Start | IP End | IP Count |
+=========+============+============+============+
| range3 | 100.1.1.10 | 100.1.1.10 | 1 |
+---------+------------+------------+------------+
"""
runner = CliRunner()
db = clicommon.Db()
@@ -112,10 +131,13 @@ range3 100.1.1.10 100.1.1.10 1
def test_show_dhcp_server_ipv4_info_without_intf(self, mock_db):
expected_stdout = """\
Interface Mode Gateway Netmask Lease Time(s) State
----------- ------ --------- ------------- --------------- --------
Vlan100 PORT 100.1.1.1 255.255.255.0 3600 enabled
Vlan300 PORT 100.1.1.1 255.255.255.0 3600 disabled
+-------------+--------+-----------+---------------+-----------------+----------+
| Interface | Mode | Gateway | Netmask | Lease Time(s) | State |
+=============+========+===========+===============+=================+==========+
| Vlan100 | PORT | 100.1.1.1 | 255.255.255.0 | 3600 | enabled |
+-------------+--------+-----------+---------------+-----------------+----------+
| Vlan300 | PORT | 100.1.1.1 | 255.255.255.0 | 3600 | disabled |
+-------------+--------+-----------+---------------+-----------------+----------+
"""
runner = CliRunner()
db = clicommon.Db()
@@ -126,9 +148,11 @@ Vlan300 PORT 100.1.1.1 255.255.255.0 3600 disabled
def test_show_dhcp_server_ipv4_info_with_intf(self, mock_db):
expected_stdout = """\
Interface Mode Gateway Netmask Lease Time(s) State
----------- ------ --------- ------------- --------------- -------
Vlan100 PORT 100.1.1.1 255.255.255.0 3600 enabled
+-------------+--------+-----------+---------------+-----------------+---------+
| Interface | Mode | Gateway | Netmask | Lease Time(s) | State |
+=============+========+===========+===============+=================+=========+
| Vlan100 | PORT | 100.1.1.1 | 255.255.255.0 | 3600 | enabled |
+-------------+--------+-----------+---------------+-----------------+---------+
"""
runner = CliRunner()
db = clicommon.Db()
@@ -139,9 +163,11 @@ Vlan100 PORT 100.1.1.1 255.255.255.0 3600 enabled
def test_show_dhcp_server_ipv4_info_with_customized_options(self, mock_db):
expected_stdout = """\
Interface Mode Gateway Netmask Lease Time(s) State Customized Options
----------- ------ --------- ------------- --------------- ------- --------------------
Vlan100 PORT 100.1.1.1 255.255.255.0 3600 enabled option60
+-------------+--------+-----------+---------------+-----------------+---------+----------------------+
| Interface | Mode | Gateway | Netmask | Lease Time(s) | State | Customized Options |
+=============+========+===========+===============+=================+=========+======================+
| Vlan100 | PORT | 100.1.1.1 | 255.255.255.0 | 3600 | enabled | option60 |
+-------------+--------+-----------+---------------+-----------------+---------+----------------------+
"""
runner = CliRunner()
db = clicommon.Db()
@@ -152,9 +178,11 @@ Vlan100 PORT 100.1.1.1 255.255.255.0 3600 enabled option6
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
+---------------+-------------+-------------+--------+
| Option Name | Option ID | Value | Type |
+===============+=============+=============+========+
| option60 | 60 | dummy_value | string |
+---------------+-------------+-------------+--------+
"""
runner = CliRunner()
db = clicommon.Db()
@@ -165,9 +193,11 @@ option60 60 dummy_value string
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
+---------------+-------------+-------------+--------+
| Option Name | Option ID | Value | Type |
+===============+=============+=============+========+
| option60 | 60 | dummy_value | string |
+---------------+-------------+-------------+--------+
"""
runner = CliRunner()
db = clicommon.Db()
@@ -178,16 +208,21 @@ option60 60 dummy_value string
def test_show_dhcp_server_ipv4_port_without_intf(self, mock_db):
expected_stdout = """\
Interface Bind
----------------- ----------
Vlan100|Ethernet4 100.1.1.10
10.1.1.11
Vlan100|Ethernet7 range1
range2
Vlan200|Ethernet8 range3
range4
Ethernet9 range5
range6
+-------------------+------------+
| Interface | Bind |
+===================+============+
| Vlan100|Ethernet4 | 100.1.1.10 |
| | 10.1.1.11 |
+-------------------+------------+
| Vlan100|Ethernet7 | range1 |
| | range2 |
+-------------------+------------+
| Vlan200|Ethernet8 | range3 |
| | range4 |
+-------------------+------------+
| Ethernet9 | range5 |
| | range6 |
+-------------------+------------+
"""
runner = CliRunner()
db = clicommon.Db()
@@ -198,10 +233,12 @@ Ethernet9 range5
def test_show_dhcp_server_ipv4_port_with_port(self, mock_db):
expected_stdout = """\
Interface Bind
----------------- ------
Vlan100|Ethernet7 range1
range2
+-------------------+--------+
| Interface | Bind |
+===================+========+
| Vlan100|Ethernet7 | range1 |
| | range2 |
+-------------------+--------+
"""
runner = CliRunner()
db = clicommon.Db()
@@ -212,12 +249,15 @@ Vlan100|Ethernet7 range1
def test_show_dhcp_server_ipv4_port_with_vlan(self, mock_db):
expected_stdout = """\
Interface Bind
----------------- ----------
Vlan100|Ethernet4 100.1.1.10
10.1.1.11
Vlan100|Ethernet7 range1
range2
+-------------------+------------+
| Interface | Bind |
+===================+============+
| Vlan100|Ethernet4 | 100.1.1.10 |
| | 10.1.1.11 |
+-------------------+------------+
| Vlan100|Ethernet7 | range1 |
| | range2 |
+-------------------+------------+
"""
runner = CliRunner()
db = clicommon.Db()
@@ -228,10 +268,12 @@ Vlan100|Ethernet7 range1
def test_show_dhcp_server_ipv4_port_with_port_and_vlan(self, mock_db):
expected_stdout = """\
Interface Bind
----------------- ------
Vlan200|Ethernet8 range3
range4
+-------------------+--------+
| Interface | Bind |
+===================+========+
| Vlan200|Ethernet8 | range3 |
| | range4 |
+-------------------+--------+
"""
runner = CliRunner()
db = clicommon.Db()
@@ -242,10 +284,12 @@ Vlan200|Ethernet8 range3
def test_show_dhcp_server_ipv4_port_with_single_port(self, mock_db):
expected_stdout = """\
Interface Bind
----------- ------
Ethernet9 range5
range6
+-------------+--------+
| Interface | Bind |
+=============+========+
| Ethernet9 | range5 |
| | range6 |
+-------------+--------+
"""
runner = CliRunner()
db = clicommon.Db()