-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[dhcp_server] add config dhcp_server add #17489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yxieca
merged 20 commits into
sonic-net:master
from
Xichen96:dev/xichenlin/add_dhcp_server_add
Dec 20, 2023
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8cddb5c
dhcp_server add
Xichen96 dfcf9c6
fix conftest bug
Xichen96 93e40c4
fix bug
Xichen96 d220ad7
Fix bug
Xichen96 ee6e558
fix bug
Xichen96 6f70ad6
fix bug
Xichen96 2950b2f
fix bug
Xichen96 8b74771
fix bug
Xichen96 22edd07
fix bug
Xichen96 29d75e1
add test dup gw nm
Xichen96 17db09b
add 3 more tests
Xichen96 6ef5b89
fix bug
Xichen96 e73e5b7
fix bug
Xichen96 a0c7cff
fix bug
Xichen96 8401b89
add more tests
Xichen96 f478b37
fix bug
Xichen96 7332099
fix bug
Xichen96 d60acf4
fix bug
Xichen96 e845b3e
fix bug
Xichen96 cda722e
fix bug
Xichen96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
dockers/docker-dhcp-server/cli-plugin-tests/test_config_dhcp_server.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import sys | ||
| from unittest import mock | ||
| import pytest | ||
|
|
||
| from click.testing import CliRunner | ||
|
|
||
| import utilities_common.cli as clicommon | ||
|
|
||
| sys.path.append('../cli/config/plugins/') | ||
| import dhcp_server | ||
|
|
||
|
|
||
| class TestConfigDHCPServer(object): | ||
| def test_plugin_registration(self): | ||
| cli = mock.MagicMock() | ||
| dhcp_server.register(cli) | ||
|
|
||
| str_type = [[12, "whatever", False], | ||
| ["text", "whatever", False], | ||
| ["string", "whatever", True], | ||
| ["binary", "12abc", False], | ||
| ["binary", "123abc45", True], | ||
| ["boolean", "True", False], | ||
| ["boolean", "true", True], | ||
| ["ipv4-address", "10.10.1", False], | ||
| ["ipv4-address", "10.10.1.0", True], | ||
| ["uint8", "4500", False], | ||
| ["uint8", "-45", False], | ||
| ["uint8", "45", True], | ||
| ] | ||
|
|
||
| @pytest.mark.parametrize("type, value, result", str_type) | ||
| def test_validate_str_type(self, type, value, result): | ||
| assert dhcp_server.validate_str_type(type, value) == result | ||
|
|
||
| def test_config_dhcp_server_ipv4_add(self, mock_db): | ||
| expected_value = { | ||
| "gateway": "10.10.10.10", | ||
| "lease_time": "1000", | ||
| "mode": "PORT", | ||
| "netmask": "255.255.254.0", | ||
| "state": "disabled" | ||
| } | ||
| runner = CliRunner() | ||
| db = clicommon.Db() | ||
| db.db = mock_db | ||
| result = runner.invoke(dhcp_server.dhcp_server.commands["ipv4"].commands["add"], \ | ||
| ["Vlan200", "--mode=PORT", "--lease_time=1000", "--gateway=10.10.10.10", "--netmask=255.255.254.0"], obj=db) | ||
| assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info) | ||
| assert mock_db.get_all("CONFIG_DB", "DHCP_SERVER_IPV4|Vlan200") == expected_value | ||
|
|
||
| def test_config_dhcp_server_ipv4_add_dup_gw_nm(self, mock_db): | ||
| expected_value = { | ||
| "gateway": "100.1.1.2", | ||
| "lease_time": "1000", | ||
| "mode": "PORT", | ||
| "netmask": "255.255.255.0", | ||
| "state": "disabled" | ||
| } | ||
| runner = CliRunner() | ||
| db = clicommon.Db() | ||
| db.db = mock_db | ||
| result = runner.invoke(dhcp_server.dhcp_server.commands["ipv4"].commands["add"], \ | ||
| ["Vlan200", "--mode=PORT", "--lease_time=1000", "--dup_gw_nm"], obj=db) | ||
| assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info) | ||
| assert mock_db.get_all("CONFIG_DB", "DHCP_SERVER_IPV4|Vlan200") == expected_value | ||
|
|
||
| def test_config_dhcp_server_ipv4_add_illegal_mode(self, mock_db): | ||
| runner = CliRunner() | ||
| db = clicommon.Db() | ||
| db.db = mock_db | ||
| result = runner.invoke(dhcp_server.dhcp_server.commands["ipv4"].commands["add"], \ | ||
| ["Vlan200", "--mode=WHATEVER", "--lease_time=1000", "--gateway=10.10.10.10", "--netmask=255.255.254.0"], 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_add_illegal_lease_time(self, mock_db): | ||
| runner = CliRunner() | ||
| db = clicommon.Db() | ||
| db.db = mock_db | ||
| result = runner.invoke(dhcp_server.dhcp_server.commands["ipv4"].commands["add"], \ | ||
| ["Vlan200", "--mode=PORT", "--lease_time=-1000", "--gateway=10.10.10.10", "--netmask=255.255.254.0"], 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_add_no_vlan(self, mock_db): | ||
| runner = CliRunner() | ||
| db = clicommon.Db() | ||
| db.db = mock_db | ||
| result = runner.invoke(dhcp_server.dhcp_server.commands["ipv4"].commands["add"], \ | ||
| ["Vlan400", "--mode=PORT", "--lease_time=1000", "--gateway=10.10.10.10", "--netmask=255.255.254.0"], 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_add_no_vlan_ip(self, mock_db): | ||
| runner = CliRunner() | ||
| db = clicommon.Db() | ||
| db.db = mock_db | ||
| result = runner.invoke(dhcp_server.dhcp_server.commands["ipv4"].commands["add"], \ | ||
| ["Vlan300", "--mode=PORT", "--lease_time=1000", "--dup_gw_nm"], 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_add_illegal_ip(self, mock_db): | ||
| runner = CliRunner() | ||
| db = clicommon.Db() | ||
| db.db = mock_db | ||
| result = runner.invoke(dhcp_server.dhcp_server.commands["ipv4"].commands["add"], \ | ||
| ["Vlan200", "--mode=PORT", "--lease_time=1000", "--gateway=10000.10.10.10", "--netmask=255.255.254.0"], 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_add_already_exist(self, mock_db): | ||
| runner = CliRunner() | ||
| db = clicommon.Db() | ||
| db.db = mock_db | ||
| result = runner.invoke(dhcp_server.dhcp_server.commands["ipv4"].commands["add"], \ | ||
| ["Vlan100", "--mode=PORT", "--lease_time=1000", "--gateway=10.10.10.10", "--netmask=255.255.254.0"], obj=db) | ||
| assert result.exit_code == 2, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info) | ||
|
|
94 changes: 94 additions & 0 deletions
94
dockers/docker-dhcp-server/cli/config/plugins/dhcp_server.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.