|
9 | 9 | sys.path.append('../cli/show/plugins/')
|
10 | 10 | import show_dhcp_server
|
11 | 11 |
|
| 12 | +BRIDGE_FDB_MAC = { |
| 13 | + "10:70:fd:b6:13:03": "dpu0" |
| 14 | +} |
12 | 15 |
|
13 |
| -class TestShowDHCPServer(object): |
| 16 | + |
| 17 | +class TestShowDHCPServerLease(object): |
14 | 18 | def test_plugin_registration(self):
|
15 | 19 | cli = mock.MagicMock()
|
16 | 20 | show_dhcp_server.register(cli)
|
17 | 21 |
|
18 |
| - @pytest.mark.parametrize("state", ["disabled", "enabled"]) |
19 |
| - def test_show_dhcp_server_feature_state_checking(self, mock_db, state): |
20 |
| - runner = CliRunner() |
21 |
| - db = clicommon.Db() |
22 |
| - db.db = mock_db |
23 |
| - mock_db.set("CONFIG_DB", "FEATURE|dhcp_server", "state", state) |
24 |
| - result = runner.invoke(show_dhcp_server.dhcp_server, obj=db) |
25 |
| - if state == "disabled": |
26 |
| - assert result.exit_code == 2, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info) |
27 |
| - assert "Feature dhcp_server is not enabled" in result.output |
28 |
| - elif state == "enabled": |
29 |
| - assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info) |
30 |
| - assert "Usage: dhcp_server [OPTIONS] COMMAND [ARGS]" in result.output |
31 |
| - else: |
32 |
| - assert False |
| 22 | + @pytest.fixture(scope="class", autouse=True) |
| 23 | + def mock_run_cmd_fixture(self): |
| 24 | + def mock_run_command(cmd, return_cmd=False, shell=False): |
| 25 | + splits = cmd.split("sudo bridge fdb show | grep ") |
| 26 | + if len(splits) == 2 and splits[1] in BRIDGE_FDB_MAC: |
| 27 | + return ("{} dev {} master bridge-midplane".format(splits[1], BRIDGE_FDB_MAC[splits[1]]), 0) |
| 28 | + else: |
| 29 | + return ("", 0) |
| 30 | + |
| 31 | + with mock.patch("utilities_common.cli.run_command", side_effect=mock_run_command): |
| 32 | + yield |
33 | 33 |
|
34 | 34 | def test_show_dhcp_server_ipv4_lease_without_dhcpintf(self, mock_db):
|
35 | 35 | expected_stdout = """\
|
36 |
| -+---------------------+-------------------+-------------+---------------------+---------------------+ |
37 |
| -| Interface | MAC Address | IP | Lease Start | Lease End | |
38 |
| -+=====================+===================+=============+=====================+=====================+ |
39 |
| -| Vlan1000|Ethernet10 | 10:70:fd:b6:13:00 | 192.168.0.1 | 2023-03-01 03:16:21 | 2023-03-01 03:31:21 | |
40 |
| -+---------------------+-------------------+-------------+---------------------+---------------------+ |
41 |
| -| Vlan1000|Ethernet11 | 10:70:fd:b6:13:01 | 192.168.0.2 | 2023-03-01 03:16:21 | 2023-03-01 03:31:21 | |
42 |
| -+---------------------+-------------------+-------------+---------------------+---------------------+ |
43 |
| -| Vlan1001|<Unknown> | 10:70:fd:b6:13:02 | 192.168.0.3 | 2023-03-01 03:16:21 | 2023-03-01 03:31:21 | |
44 |
| -+---------------------+-------------------+-------------+---------------------+---------------------+ |
| 36 | ++----------------------+-------------------+-------------+---------------------+---------------------+ |
| 37 | +| Interface | MAC Address | IP | Lease Start | Lease End | |
| 38 | ++======================+===================+=============+=====================+=====================+ |
| 39 | +| Vlan1000|Ethernet10 | 10:70:fd:b6:13:00 | 192.168.0.1 | 2023-03-01 03:16:21 | 2023-03-01 03:31:21 | |
| 40 | ++----------------------+-------------------+-------------+---------------------+---------------------+ |
| 41 | +| Vlan1000|Ethernet11 | 10:70:fd:b6:13:01 | 192.168.0.2 | 2023-03-01 03:16:21 | 2023-03-01 03:31:21 | |
| 42 | ++----------------------+-------------------+-------------+---------------------+---------------------+ |
| 43 | +| Vlan1001|<Unknown> | 10:70:fd:b6:13:02 | 192.168.0.3 | 2023-03-01 03:16:21 | 2023-03-01 03:31:21 | |
| 44 | ++----------------------+-------------------+-------------+---------------------+---------------------+ |
| 45 | +| bridge-midplane|dpu0 | 10:70:fd:b6:13:03 | 192.168.0.4 | 2023-03-01 03:16:21 | 2023-03-01 03:31:21 | |
| 46 | ++----------------------+-------------------+-------------+---------------------+---------------------+ |
45 | 47 | """
|
46 | 48 | runner = CliRunner()
|
47 | 49 | db = clicommon.Db()
|
@@ -82,6 +84,28 @@ def test_show_dhcp_server_ipv4_lease_client_not_in_fdb(self, mock_db):
|
82 | 84 | assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
|
83 | 85 | assert result.stdout == expected_stdout
|
84 | 86 |
|
| 87 | + |
| 88 | +class TestShowDHCPServer(object): |
| 89 | + def test_plugin_registration(self): |
| 90 | + cli = mock.MagicMock() |
| 91 | + show_dhcp_server.register(cli) |
| 92 | + |
| 93 | + @pytest.mark.parametrize("state", ["disabled", "enabled"]) |
| 94 | + def test_show_dhcp_server_feature_state_checking(self, mock_db, state): |
| 95 | + runner = CliRunner() |
| 96 | + db = clicommon.Db() |
| 97 | + db.db = mock_db |
| 98 | + mock_db.set("CONFIG_DB", "FEATURE|dhcp_server", "state", state) |
| 99 | + result = runner.invoke(show_dhcp_server.dhcp_server, obj=db) |
| 100 | + if state == "disabled": |
| 101 | + assert result.exit_code == 2, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info) |
| 102 | + assert "Feature dhcp_server is not enabled" in result.output |
| 103 | + elif state == "enabled": |
| 104 | + assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info) |
| 105 | + assert "Usage: dhcp_server [OPTIONS] COMMAND [ARGS]" in result.output |
| 106 | + else: |
| 107 | + assert False |
| 108 | + |
85 | 109 | def test_show_dhcp_server_ipv4_range_without_name(self, mock_db):
|
86 | 110 | expected_stdout = """\
|
87 | 111 | +---------+------------+------------+------------------------+
|
|
0 commit comments