[dhcp_server] Add support for only configures 1 ip in dhcp_server range (#17280)
How I did it Add support for only configures 1 ip in dhcp_server range. Treat range with value out of order as invalid range.
This commit is contained in:
parent
90ff72c885
commit
be95d49db6
@ -251,15 +251,17 @@ class DhcpServCfgGenerator(object):
|
|||||||
ranges = {}
|
ranges = {}
|
||||||
for range in list(range_ipv4.keys()):
|
for range in list(range_ipv4.keys()):
|
||||||
curr_range = range_ipv4.get(range, {}).get("range", {})
|
curr_range = range_ipv4.get(range, {}).get("range", {})
|
||||||
if len(curr_range) != 2:
|
list_length = len(curr_range)
|
||||||
syslog.syslog(syslog.LOG_WARNING, f"Length of {curr_range} != 2")
|
if list_length == 0 or list_length > 2:
|
||||||
|
syslog.syslog(syslog.LOG_WARNING, f"Length of {curr_range} is {list_length}, which is invalid!")
|
||||||
continue
|
continue
|
||||||
address_1 = ipaddress.ip_address(curr_range[0])
|
address_start = ipaddress.ip_address(curr_range[0])
|
||||||
address_2 = ipaddress.ip_address(curr_range[1])
|
address_end = ipaddress.ip_address(curr_range[1] if list_length == 2 else curr_range[0])
|
||||||
# To make sure order of range is correct
|
# To make sure order of range is correct
|
||||||
range_start = address_1 if address_1 < address_2 else address_2
|
if address_start > address_end:
|
||||||
range_end = address_2 if address_1 < address_2 else address_1
|
syslog.syslog(syslog.LOG_WARNING, f"Start of {curr_range} is greater than end, skip it")
|
||||||
ranges[range] = [range_start, range_end]
|
continue
|
||||||
|
ranges[range] = [address_start, address_end]
|
||||||
|
|
||||||
return ranges
|
return ranges
|
||||||
|
|
||||||
|
@ -123,6 +123,9 @@
|
|||||||
"192.168.8.2",
|
"192.168.8.2",
|
||||||
"192.168.8.3"
|
"192.168.8.3"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"range5": {
|
||||||
|
"range": []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"DHCP_SERVER_IPV4_PORT": {
|
"DHCP_SERVER_IPV4_PORT": {
|
||||||
|
@ -140,7 +140,7 @@ expected_dhcp_config_without_port_config = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expected_parsed_range = {
|
expected_parsed_range = {
|
||||||
"range2": [ipaddress.IPv4Address("192.168.0.3"), ipaddress.IPv4Address("192.168.0.6")],
|
"range4": [ipaddress.IPv4Address("192.168.0.1"), ipaddress.IPv4Address("192.168.0.1")],
|
||||||
"range3": [ipaddress.IPv4Address("192.168.0.10"), ipaddress.IPv4Address("192.168.0.10")],
|
"range3": [ipaddress.IPv4Address("192.168.0.10"), ipaddress.IPv4Address("192.168.0.10")],
|
||||||
"range1": [ipaddress.IPv4Address("192.168.0.2"), ipaddress.IPv4Address("192.168.0.5")],
|
"range1": [ipaddress.IPv4Address("192.168.0.2"), ipaddress.IPv4Address("192.168.0.5")],
|
||||||
"range0": [ipaddress.IPv4Address("192.168.8.2"), ipaddress.IPv4Address("192.168.8.3")]
|
"range0": [ipaddress.IPv4Address("192.168.8.2"), ipaddress.IPv4Address("192.168.8.3")]
|
||||||
@ -164,7 +164,7 @@ expected_vlan_ipv4_interface = {
|
|||||||
expected_parsed_port = {
|
expected_parsed_port = {
|
||||||
"Vlan1000": {
|
"Vlan1000": {
|
||||||
"192.168.0.1/21": {
|
"192.168.0.1/21": {
|
||||||
"etp8": [["192.168.0.2", "192.168.0.6"], ["192.168.0.10", "192.168.0.10"]],
|
"etp8": [["192.168.0.2", "192.168.0.5"], ["192.168.0.10", "192.168.0.10"]],
|
||||||
"etp7": [["192.168.0.7", "192.168.0.7"]]
|
"etp7": [["192.168.0.7", "192.168.0.7"]]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -318,7 +318,7 @@ def test_parse_port(test_config_db, mock_swsscommon_dbconnector_init, mock_get_r
|
|||||||
parsed_port, used_ranges = dhcp_cfg_generator._parse_port(ipv4_port, tested_vlan_interfaces, vlan_members,
|
parsed_port, used_ranges = dhcp_cfg_generator._parse_port(ipv4_port, tested_vlan_interfaces, vlan_members,
|
||||||
tested_ranges)
|
tested_ranges)
|
||||||
assert parsed_port == (expected_parsed_port if test_config_db == "mock_config_db.json" else {})
|
assert parsed_port == (expected_parsed_port if test_config_db == "mock_config_db.json" else {})
|
||||||
assert used_ranges == ({"range2", "range1", "range0", "range3"}
|
assert used_ranges == ({"range1", "range0", "range3"}
|
||||||
if test_config_db == "mock_config_db.json" else set())
|
if test_config_db == "mock_config_db.json" else set())
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user