[dhcp_server] Update dhcp_server container to bookworm (#17647)

This commit is contained in:
Yaqiang Zhu 2024-01-24 00:33:00 +08:00 committed by GitHub
parent b1750b7cee
commit 2c08e90203
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 46 additions and 81 deletions

View File

@ -1,5 +1,5 @@
{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %}
FROM docker-config-engine-bullseye-{{DOCKER_USERNAME}}:{{DOCKER_USERTAG}}
FROM docker-config-engine-bookworm-{{DOCKER_USERNAME}}:{{DOCKER_USERTAG}}
ARG docker_container_name
ARG image_version
@ -15,40 +15,11 @@ RUN apt-get update && \
apt-get install -f -y \
tcpdump \
python3-dev \
# For kea build environment
automake \
libtool \
pkg-config \
build-essential \
ccache \
# For kea dependancies
libboost-dev \
libboost-system-dev \
liblog4cplus-dev \
libssl-dev
kea-dhcp4-server
RUN mkdir -p /var/run/kea
# Install kea from source
RUN apt-get install -f -y devscripts
RUN mkdir kea && cd kea && dget -u http://deb.debian.org/debian/pool/main/i/isc-kea/isc-kea_2.2.0-6.dsc
RUN cd /kea/isc-kea-2.2.0 && autoreconf --install && ./configure --disable-FEATURE \
--enable-static=no --disable-install-configurations --enable-pgsql-ssl=no --with-PACKAGE=no \
&& make -j$(nproc) && make install
# Create run folder for kea
RUN mkdir -p /run/kea
# Create config folder for kea
RUN mkdir -p /etc/kea
# Remove stuff we don't need to reduce image size
RUN cd /usr/local/lib && rm -v *.la && rm -v kea/hooks/*.la
# Strip debug symbols to reduce file size of binaries
Run find /usr/local/sbin/ /usr/local/lib/ -type f -exec strip --strip-unneeded {} \;
# Remove source code
RUN rm -rf /kea
RUN echo "/usr/local/lib/kea/hooks" > /etc/ld.so.conf.d/kea.conf && \
ldconfig
# Remove sbin we don't need
RUN cd /usr/local/sbin && rm -f kea-admin kea-ctrl-agent kea-dhcp-ddns kea-dhcp6 keactrl
# Remove hook lib we don't need
RUN cd /usr/local/lib/kea/hooks && rm -f libdhcp_bootp.so libdhcp_flex_option.so libdhcp_stat_cmds.so
RUN pip3 install psutil
# TODO issue on remote rsyslog server in non-host container
RUN rm -f /etc/supervisor/conf.d/containercfgd.conf
@ -70,13 +41,8 @@ RUN rm -f /etc/supervisor/conf.d/containercfgd.conf
{% endif %}
# Remove build stuff we don't need
RUN apt-get remove -y devscripts \
automake \
libtool \
pkg-config \
build-essential \
python3-dev \
ccache
RUN apt-get remove -y build-essential \
python3-dev
RUN apt-get clean -y && \
apt-get autoclean -y && \

View File

@ -1,14 +1,5 @@
{
"Dhcp4": {
"hooks-libraries": [
{
"library": "/usr/local/lib/kea/hooks/libdhcp_run_script.so",
"parameters": {
"name": "/etc/kea/lease_update.sh",
"sync": false
}
}
],
"interfaces-config": {
"interfaces": ["eth0"]
},

View File

@ -14,7 +14,7 @@
{%- endif %}
"hooks-libraries": [
{
"library": "/usr/local/lib/kea/hooks/libdhcp_run_script.so",
"library": "{{ hook_lib_path }}",
"parameters": {
"name": "{{ lease_update_script_path }}",
"sync": false

View File

@ -53,7 +53,7 @@ dependent_startup=true
dependent_startup_wait_for=start:exited
[program:kea-dhcp4]
command=/usr/local/sbin/kea-dhcp4 -c /etc/kea/kea-dhcp4.conf
command=/usr/sbin/kea-dhcp4 -c /etc/kea/kea-dhcp4.conf
priority=3
autostart=false
autorestart=false

View File

@ -6,21 +6,19 @@ DOCKER_DHCP_SERVER_DBG = $(DOCKER_DHCP_SERVER_STEM)-$(DBG_IMAGE_MARK).gz
$(DOCKER_DHCP_SERVER)_PATH = $(DOCKERS_PATH)/$(DOCKER_DHCP_SERVER_STEM)
$(DOCKER_DHCP_SERVER)_DEPENDS = $(SWSS) $(LIBSWSSCOMMON) $(SONIC_RSYSLOG_PLUGIN)
$(DOCKER_DHCP_SERVER)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_BULLSEYE)_DBG_DEPENDS)
$(DOCKER_DHCP_SERVER)_DEPENDS = $(LIBSWSSCOMMON) $(SONIC_RSYSLOG_PLUGIN)
$(DOCKER_DHCP_SERVER)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_BOOKWORM)_DBG_DEPENDS)
$(DOCKER_DHCP_SERVER)_DBG_IMAGE_PACKAGES = $($(DOCKER_CONFIG_ENGINE_BULLSEYE)_DBG_IMAGE_PACKAGES)
$(DOCKER_DHCP_SERVER)_DBG_IMAGE_PACKAGES = $($(DOCKER_CONFIG_ENGINE_BOOKWORM)_DBG_IMAGE_PACKAGES)
$(DOCKER_DHCP_SERVER)_LOAD_DOCKERS = $(DOCKER_CONFIG_ENGINE_BULLSEYE)
$(DOCKER_DHCP_SERVER)_LOAD_DOCKERS = $(DOCKER_CONFIG_ENGINE_BOOKWORM)
$(DOCKER_DHCP_SERVER)_INSTALL_DEBS = $(PYTHON3_SWSSCOMMON)
$(DOCKER_DHCP_SERVER)_PYTHON_WHEELS += $(SONIC_DHCP_UTILITIES_PY3)
$(DOCKER_DHCP_SERVER)_INSTALL_PYTHON_WHEELS = $(SONIC_UTILITIES_PY3)
SONIC_DOCKER_IMAGES += $(DOCKER_DHCP_SERVER)
SONIC_BULLSEYE_DOCKERS += $(DOCKER_DHCP_SERVER)
SONIC_DOCKER_DBG_IMAGES += $(DOCKER_DHCP_SERVER_DBG)
SONIC_BULLSEYE_DBG_DOCKERS += $(DOCKER_DHCP_SERVER_DBG)
ifeq ($(INCLUDE_KUBERNETES),y)
$(DOCKER_DHCP_SERVER)_DEFAULT_FEATURE_OWNER = kube

View File

@ -33,13 +33,15 @@ class DhcpServCfgGenerator(object):
port_alias_map = {}
lease_update_script_path = ""
lease_path = ""
hook_lib_path = ""
def __init__(self, dhcp_db_connector, lease_path=DEFAULT_LEASE_PATH,
def __init__(self, dhcp_db_connector, hook_lib_path, lease_path=DEFAULT_LEASE_PATH,
lease_update_script_path=LEASE_UPDATE_SCRIPT_PATH, dhcp_option_path=DHCP_OPTION_FILE,
kea_conf_template_path=KEA_DHCP4_CONF_TEMPLATE_PATH):
self.db_connector = dhcp_db_connector
self.lease_path = lease_path
self.lease_update_script_path = lease_update_script_path
self.hook_lib_path = hook_lib_path
# Read port alias map file, this file is render after container start, so it would not change any more
self._parse_port_map_alias()
# Get kea config template
@ -235,7 +237,8 @@ class DhcpServCfgGenerator(object):
"client_classes": client_classes,
"lease_update_script_path": self.lease_update_script_path,
"lease_path": self.lease_path,
"customized_options": customized_options
"customized_options": customized_options,
"hook_lib_path": self.hook_lib_path
}
return render_obj, enabled_dhcp_interfaces, used_options, subscribe_table

View File

@ -2,6 +2,7 @@
import psutil
import signal
import time
import subprocess
import sys
import syslog
from .dhcp_cfggen import DhcpServCfgGenerator
@ -100,7 +101,12 @@ class DhcpServd(object):
def main():
dhcp_db_connector = DhcpDbConnector(redis_sock=REDIS_SOCK_PATH)
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector)
hook_lib_path_res = subprocess.run(["find", "/", "-name", "libdhcp_run_script.so"],
capture_output=True).stdout.decode().strip()
if len(hook_lib_path_res) == 0:
syslog.syslog(syslog.LOG_ERR, "Cannot find hook lib for kea-dhcp-server")
sys.exit(1)
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector, hook_lib_path_res.split("\n")[0])
sel = swsscommon.Select()
checkers = []
checkers.append(DhcpServerTableCfgChangeEventChecker(sel, dhcp_db_connector.config_db))

View File

@ -1,12 +1,12 @@
from setuptools import setup, find_packages
from setuptools import setup
dependencies = [
"psutil"
"psutil",
"freezegun"
]
test_deps = [
"pytest",
"freezegun"
]
setup(
@ -20,7 +20,7 @@ setup(
author_email="yaqiangzhu@microsoft.com",
setup_requires=[
"pytest-runner",
"wheel",
"wheel"
],
packages=[
"dhcp_utilities.common",

View File

@ -14,7 +14,7 @@
{%- endif %}
"hooks-libraries": [
{
"library": "/usr/local/lib/kea/hooks/libdhcp_run_script.so",
"library": "{{ hook_lib_path }}",
"parameters": {
"name": "{{ lease_update_script_path }}",
"sync": false

View File

@ -208,7 +208,8 @@ expected_render_obj = {
"type": "string",
"always_send": "true"
}
}
},
"hook_lib_path": "/usr/local/lib/kea/hooks/libdhcp_run_script.so"
}
tested_options_data = [
{
@ -270,7 +271,7 @@ tested_options_data = [
def test_parse_port_alias(mock_swsscommon_dbconnector_init, mock_get_render_template):
with patch.object(DhcpDbConnector, "get_config_db_table", side_effect=mock_get_config_db_table):
dhcp_db_connector = DhcpDbConnector()
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector)
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector, "/usr/local/lib/kea/hooks/libdhcp_run_script.so")
assert dhcp_cfg_generator.port_alias_map == {"Ethernet0": "etp1", "Ethernet1": "etp2",
"PortChannel101": "PortChannel101"}
@ -280,7 +281,7 @@ def test_parse_hostname(is_success, mock_swsscommon_dbconnector_init, mock_parse
mock_get_render_template):
mock_config_db = MockConfigDb(config_db_path="tests/test_data/mock_config_db.json")
dhcp_db_connector = DhcpDbConnector()
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector)
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector, "/usr/local/lib/kea/hooks/libdhcp_run_script.so")
device_metadata = mock_config_db.config_db.get("DEVICE_METADATA") if is_success else {}
try:
hostname = dhcp_cfg_generator._parse_hostname(device_metadata)
@ -292,7 +293,7 @@ def test_parse_hostname(is_success, mock_swsscommon_dbconnector_init, mock_parse
def test_parse_range(mock_swsscommon_dbconnector_init, mock_parse_port_map_alias, mock_get_render_template):
mock_config_db = MockConfigDb(config_db_path="tests/test_data/mock_config_db.json")
dhcp_db_connector = DhcpDbConnector()
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector)
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector, "/usr/local/lib/kea/hooks/libdhcp_run_script.so")
parse_result = dhcp_cfg_generator._parse_range(mock_config_db.config_db.get("DHCP_SERVER_IPV4_RANGE"))
assert parse_result == expected_parsed_range
@ -300,7 +301,7 @@ def test_parse_range(mock_swsscommon_dbconnector_init, mock_parse_port_map_alias
def test_parse_vlan(mock_swsscommon_dbconnector_init, mock_parse_port_map_alias, mock_get_render_template):
mock_config_db = MockConfigDb(config_db_path="tests/test_data/mock_config_db.json")
dhcp_db_connector = DhcpDbConnector()
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector)
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector, "/usr/local/lib/kea/hooks/libdhcp_run_script.so")
vlan_interfaces, vlan_members = dhcp_cfg_generator._parse_vlan(mock_config_db.config_db.get("VLAN_INTERFACE"),
mock_config_db.config_db.get("VLAN_MEMBER"))
assert vlan_interfaces == expected_vlan_ipv4_interface
@ -313,7 +314,7 @@ def test_parse_port(test_config_db, mock_swsscommon_dbconnector_init, mock_get_r
mock_parse_port_map_alias):
mock_config_db = MockConfigDb(config_db_path="tests/test_data/{}".format(test_config_db))
dhcp_db_connector = DhcpDbConnector()
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector)
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector, "/usr/local/lib/kea/hooks/libdhcp_run_script.so")
tested_vlan_interfaces = expected_vlan_ipv4_interface
tested_ranges = expected_parsed_range
ipv4_port = mock_config_db.config_db.get("DHCP_SERVER_IPV4_PORT")
@ -339,7 +340,7 @@ def test_generate(mock_swsscommon_dbconnector_init, mock_parse_port_map_alias, m
patch.object(DhcpDbConnector, "get_config_db_table", side_effect=mock_get_config_db_table), \
patch("dhcp_utilities.dhcpservd.dhcp_cfggen.is_smart_switch", return_value=False):
dhcp_db_connector = DhcpDbConnector()
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector)
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector, "/usr/local/lib/kea/hooks/libdhcp_run_script.so")
kea_dhcp4_config, used_ranges, enabled_dhcp_interfaces, used_options, subscribe_table = \
dhcp_cfg_generator.generate()
assert kea_dhcp4_config == "dummy_config"
@ -355,7 +356,7 @@ def test_construct_obj_for_template(mock_swsscommon_dbconnector_init, mock_parse
mock_config_db = MockConfigDb(config_db_path="tests/test_data/mock_config_db.json")
dhcp_db_connector = DhcpDbConnector()
customized_options = {"option223": {"id": "223", "value": "dummy_value", "type": "string", "always_send": "true"}}
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector)
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector, "/usr/local/lib/kea/hooks/libdhcp_run_script.so")
tested_hostname = "sonic-host"
port_ips = {
"Vlan1000": {
@ -382,7 +383,7 @@ def test_construct_obj_for_template(mock_swsscommon_dbconnector_init, mock_parse
def test_render_config(mock_swsscommon_dbconnector_init, mock_parse_port_map_alias, with_port_config,
with_option_config):
dhcp_db_connector = DhcpDbConnector()
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector,
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector, "/usr/local/lib/kea/hooks/libdhcp_run_script.so",
kea_conf_template_path="tests/test_data/kea-dhcp4.conf.j2")
render_obj = copy.deepcopy(expected_render_obj)
expected_config = copy.deepcopy(expected_dhcp_config)
@ -405,7 +406,7 @@ def test_render_config(mock_swsscommon_dbconnector_init, mock_parse_port_map_ali
def test_parse_customized_options(mock_swsscommon_dbconnector_init, mock_get_render_template,
mock_parse_port_map_alias, tested_options_data):
dhcp_db_connector = DhcpDbConnector()
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector)
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector, "/usr/local/lib/kea/hooks/libdhcp_run_script.so")
customized_options_ipv4 = tested_options_data["data"]
customized_options = dhcp_cfg_generator._parse_customized_options(customized_options_ipv4)
if tested_options_data["res"]:
@ -423,7 +424,7 @@ def test_parse_customized_options(mock_swsscommon_dbconnector_init, mock_get_ren
def test_parse_dpus(mock_swsscommon_dbconnector_init, mock_get_render_template, mock_parse_port_map_alias):
dhcp_db_connector = DhcpDbConnector()
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector)
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector, "/usr/local/lib/kea/hooks/libdhcp_run_script.so")
dpus_table = {"dpu0": {"midplane_interface": "dpu0"}}
mid_plane_table = {"GLOBAL": {"bridge": "bridge_midplane", "ip_prefix": "169.254.200.254/24"}}
mid_plane, dpus = dhcp_cfg_generator._parse_dpu(dpus_table, mid_plane_table)

View File

@ -32,7 +32,7 @@ def test_dump_dhcp4_config(mock_swsscommon_dbconnector_init, enabled_checker):
patch.object(DhcpServd, "enabled_checker", return_value=enabled_checker, new_callable=PropertyMock), \
patch.object(DhcpServCfgGenerator, "_parse_port_map_alias"):
dhcp_db_connector = DhcpDbConnector()
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector,
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector, "/usr/local/lib/kea/hooks/libdhcp_run_script.so",
kea_conf_template_path="tests/test_data/kea-dhcp4.conf.j2")
dhcpservd = DhcpServd(dhcp_cfg_generator, dhcp_db_connector, None,
kea_dhcp4_config_path="/tmp/kea-dhcp4.conf")
@ -56,7 +56,7 @@ def test_notify_kea_dhcp4_proc(process_list, mock_swsscommon_dbconnector_init, m
with patch.object(psutil, "process_iter", return_value=proc_list), \
patch.object(MockProc, "send_signal", MagicMock()) as mock_send_signal:
dhcp_db_connector = DhcpDbConnector()
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector)
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector, "/usr/local/lib/kea/hooks/libdhcp_run_script.so")
dhcpservd = DhcpServd(dhcp_cfg_generator, dhcp_db_connector, None)
dhcpservd._notify_kea_dhcp4_proc()
if "kea-dhcp4" in process_list:
@ -81,7 +81,7 @@ def test_update_dhcp_server_ip(mock_swsscommon_dbconnector_init, mock_parse_port
patch.object(time, "sleep") as mock_sleep, \
patch.object(sys, "exit") as mock_exit:
dhcp_db_connector = DhcpDbConnector()
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector)
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector, "/usr/local/lib/kea/hooks/libdhcp_run_script.so")
dhcpservd = DhcpServd(dhcp_cfg_generator, dhcp_db_connector, None)
dhcpservd._update_dhcp_server_ip()
if mock_intf:
@ -99,7 +99,7 @@ def test_start(mock_swsscommon_dbconnector_init, mock_parse_port_map_alias, mock
patch.object(DhcpServd, "_update_dhcp_server_ip") as mock_update_dhcp_server_ip, \
patch.object(DhcpServdDbMonitor, "enable_checkers"):
dhcp_db_connector = DhcpDbConnector()
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector)
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector, "/usr/local/lib/kea/hooks/libdhcp_run_script.so")
dhcpservd = DhcpServd(dhcp_cfg_generator, dhcp_db_connector, MagicMock())
dhcpservd.start()
mock_dump.assert_called_once_with()

View File

@ -122,7 +122,7 @@ def test_dhcprelayd_proceed_with_check_res(mock_swsscommon_dbconnector_init, moc
def test_dhcp_dhcp_cfggen_generate(mock_swsscommon_dbconnector_init, mock_parse_port_map_alias):
with patch.object(DhcpDbConnector, "get_config_db_table", side_effect=mock_get_config_db_table):
dhcp_db_connector = DhcpDbConnector()
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector,
dhcp_cfg_generator = DhcpServCfgGenerator(dhcp_db_connector, "/usr/local/lib/kea/hooks/libdhcp_run_script.so",
kea_conf_template_path="tests/test_data/kea-dhcp4.conf.j2")
kea_dhcp4_config, used_ranges, enabled_dhcp_interfaces, used_options, subscribe_table = \
dhcp_cfg_generator.generate()