Skip to content
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

[dhcp_server] Fix the issue with "kea-dhcp4.conf" file generation for Smart Switch. #28

Closed
wants to merge 1 commit into from
Closed
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 @@ -90,7 +90,7 @@ def generate(self):
port_ips, used_ranges = self._parse_port(port_ipv4, dhcp_interfaces, dhcp_members, ranges)
customized_options = self._parse_customized_options(customized_options_ipv4)
render_obj, enabled_dhcp_interfaces, used_options, subscribe_table = \
self._construct_obj_for_template(dhcp_server_ipv4, port_ips, hostname, customized_options)
self._construct_obj_for_template(dhcp_server_ipv4, port_ips, hostname, customized_options, smart_switch)

if smart_switch:
subscribe_table |= set(SMART_SWITCH_CHECKER)
Expand Down Expand Up @@ -175,7 +175,7 @@ def _parse_port_map_alias(self):
for pc_name in pc_table.keys():
self.port_alias_map[pc_name] = pc_name

def _construct_obj_for_template(self, dhcp_server_ipv4, port_ips, hostname, customized_options):
def _construct_obj_for_template(self, dhcp_server_ipv4, port_ips, hostname, customized_options, smart_switch=False):
subnets = []
client_classes = []
enabled_dhcp_interfaces = set()
Expand Down Expand Up @@ -223,8 +223,9 @@ def _construct_obj_for_template(self, dhcp_server_ipv4, port_ips, hostname, cust
"condition": "substring(relay4[1].hex, -{}, {}) == '{}'".format(class_len, class_len,
client_class)
})

subnet_obj = {
"id": dhcp_interface_name.replace("Vlan", ""),
"id": 0 if smart_switch else dhcp_interface_name.replace("Vlan", ""),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide a description on why this change is needed?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated PR description

"subnet": str(ipaddress.ip_network(dhcp_interface_ip, strict=False)),
"pools": pools,
"gateway": dhcp_config["gateway"],
Expand Down
1 change: 1 addition & 0 deletions src/sonic-dhcp-utilities/tests/test_data/kea-dhcp4.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
{%- if add_subnet_preceding_comma.flag -%},{%- endif -%}
{%- set _dummy = add_subnet_preceding_comma.update({'flag': True}) %}
{
"id": {{ subnet_info["id"] }},
"subnet": "{{ subnet_info["subnet"] }}",
"pools": [
{%- set add_pool_preceding_comma = { 'flag': False } %}
Expand Down
1 change: 1 addition & 0 deletions src/sonic-dhcp-utilities/tests/test_dhcp_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
},
"subnet4": [
{
"id": 1000,
"subnet": "192.168.0.0/21",
"pools": [
{
Expand Down
1 change: 1 addition & 0 deletions src/sonic-dhcp-utilities/tests/test_smart_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"subnet4": [
{
"id": 0,
"subnet": "169.254.200.0/24",
"pools": [
{
Expand Down