Skip to content

Commit

Permalink
[dhcp_server] Rename sonic_dhcp_server to sonic_dhcp_utilities (#17276)
Browse files Browse the repository at this point in the history
Why I did it
sonic_dhcp_server.whl contains not only dhcp_server functionality but also part of dhcp_relay functionality, the existing naming is not appropriate.
  • Loading branch information
yaqiangz authored and yxieca committed Dec 4, 2023
1 parent a40daff commit 82cebcd
Show file tree
Hide file tree
Showing 33 changed files with 62 additions and 62 deletions.
2 changes: 1 addition & 1 deletion rules/docker-dhcp-relay.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $(DOCKER_DHCP_RELAY)_LOAD_DOCKERS = $(DOCKER_CONFIG_ENGINE_BULLSEYE)

$(DOCKER_DHCP_RELAY)_INSTALL_PYTHON_WHEELS = $(SONIC_UTILITIES_PY3)
$(DOCKER_DHCP_RELAY)_INSTALL_DEBS = $(PYTHON3_SWSSCOMMON)
$(DOCKER_DHCP_RELAY)_PYTHON_WHEELS += $(SONIC_DHCP_SERVER_PY3)
$(DOCKER_DHCP_RELAY)_PYTHON_WHEELS += $(SONIC_DHCP_UTILITIES_PY3)

$(DOCKER_DHCP_RELAY)_VERSION = 1.0.0
$(DOCKER_DHCP_RELAY)_PACKAGE_NAME = dhcp-relay
Expand Down
2 changes: 1 addition & 1 deletion rules/docker-dhcp-server.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $(DOCKER_DHCP_SERVER)_DBG_IMAGE_PACKAGES = $($(DOCKER_CONFIG_ENGINE_BULLSEYE)_DB
$(DOCKER_DHCP_SERVER)_LOAD_DOCKERS = $(DOCKER_CONFIG_ENGINE_BULLSEYE)

$(DOCKER_DHCP_SERVER)_INSTALL_DEBS = $(PYTHON3_SWSSCOMMON)
$(DOCKER_DHCP_SERVER)_PYTHON_WHEELS += $(SONIC_DHCP_SERVER_PY3)
$(DOCKER_DHCP_SERVER)_PYTHON_WHEELS += $(SONIC_DHCP_UTILITIES_PY3)
$(DOCKER_DHCP_SERVER)_INSTALL_PYTHON_WHEELS = $(SONIC_UTILITIES_PY3)

SONIC_DOCKER_IMAGES += $(DOCKER_DHCP_SERVER)
Expand Down
10 changes: 0 additions & 10 deletions rules/sonic-dhcp-server.dep

This file was deleted.

8 changes: 0 additions & 8 deletions rules/sonic-dhcp-server.mk

This file was deleted.

10 changes: 10 additions & 0 deletions rules/sonic-dhcp-utilities.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SPATH := $($(SONIC_DHCP_UTILITIES_PY3)_SRC_PATH)
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/sonic-dhcp-utilities.mk rules/sonic-dhcp-utilities.dep
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST)
SMDEP_FILES := $(addprefix $(SPATH)/,$(shell cd $(SPATH) && git ls-files))

$(SONIC_DHCP_UTILITIES_PY3)_CACHE_MODE := GIT_CONTENT_SHA
$(SONIC_DHCP_UTILITIES_PY3)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
$(SONIC_DHCP_UTILITIES_PY3)_DEP_FILES := $(DEP_FILES)
$(SONIC_DHCP_UTILITIES_PY3)_SMDEP_FILES := $(SMDEP_FILES)
$(SONIC_DHCP_UTILITIES_PY3)_SMDEP_PATHS := $(SPATH)
8 changes: 8 additions & 0 deletions rules/sonic-dhcp-utilities.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# sonic-dhcp-utilities package

SONIC_DHCP_UTILITIES_PY3 = sonic_dhcp_utilities-1.0-py3-none-any.whl
$(SONIC_DHCP_UTILITIES_PY3)_SRC_PATH = $(SRC_PATH)/sonic-dhcp-utilities
$(SONIC_DHCP_UTILITIES_PY3)_DEPENDS += $(SONIC_PY_COMMON_PY3)
$(SONIC_DHCP_UTILITIES_PY3)_DEBS_DEPENDS = $(LIBSWSSCOMMON) $(PYTHON3_SWSSCOMMON)
$(SONIC_DHCP_UTILITIES_PY3)_PYTHON_VERSION = 3
SONIC_PYTHON_WHEELS += $(SONIC_DHCP_UTILITIES_PY3)
4 changes: 0 additions & 4 deletions src/sonic-dhcp-server/.gitignore

This file was deleted.

4 changes: 4 additions & 0 deletions src/sonic-dhcp-utilities/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.eggs/
build/
dist/
sonic_dhcp_utilities.egg-info/
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import syslog
import time
from swsscommon import swsscommon
from dhcp_server.common.utils import DhcpDbConnector, terminate_proc, get_target_process_cmds
from dhcp_server.common.dhcp_db_monitor import DhcpRelaydDbMonitor, DhcpServerTableIntfEnablementEventChecker, \
from dhcp_utilities.common.utils import DhcpDbConnector, terminate_proc, get_target_process_cmds
from dhcp_utilities.common.dhcp_db_monitor import DhcpRelaydDbMonitor, DhcpServerTableIntfEnablementEventChecker, \
VlanTableEventChecker, VlanIntfTableEventChecker, DhcpServerFeatureStateChecker

REDIS_SOCK_PATH = "/var/run/redis/redis.sock"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import syslog

from jinja2 import Environment, FileSystemLoader
from dhcp_server.common.utils import merge_intervals, validate_str_type
from dhcp_utilities.common.utils import merge_intervals, validate_str_type

PORT_MAP_PATH = "/tmp/port-name-alias-map.txt"
UNICODE_TYPE = str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import syslog
from .dhcp_cfggen import DhcpServCfgGenerator
from .dhcp_lease import LeaseManager
from dhcp_server.common.utils import DhcpDbConnector
from dhcp_server.common.dhcp_db_monitor import DhcpServdDbMonitor, DhcpServerTableCfgChangeEventChecker, \
from dhcp_utilities.common.utils import DhcpDbConnector
from dhcp_utilities.common.dhcp_db_monitor import DhcpServdDbMonitor, DhcpServerTableCfgChangeEventChecker, \
DhcpOptionTableEventChecker, DhcpRangeTableEventChecker, DhcpPortTableEventChecker, VlanIntfTableEventChecker, \
VlanMemberTableEventChecker, VlanTableEventChecker
from swsscommon import swsscommon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ testpaths = tests

[coverage:run]
branch = True
source = dhcp_server
source = dhcp_utilities

[coverage:report]
exclude_lines =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
]

setup(
name="sonic-dhcp-server",
name="sonic-dhcp-utilities",
install_requires=dependencies,
description="Module of SONiC built-in dhcp_server",
description="Module of SONiC built-in dhcp_utilities",
version="1.0",
url="https://github.com/Azure/sonic-buildimage",
tests_require=test_deps,
Expand All @@ -23,14 +23,14 @@
"wheel",
],
packages=[
"dhcp_server.common",
"dhcp_server.dhcpservd",
"dhcp_server.dhcprelayd"
"dhcp_utilities.common",
"dhcp_utilities.dhcpservd",
"dhcp_utilities.dhcprelayd"
],
entry_points={
"console_scripts": [
"dhcprelayd = dhcp_server.dhcprelayd.dhcprelayd:main",
"dhcpservd = dhcp_server.dhcpservd.dhcpservd:main"
"dhcprelayd = dhcp_utilities.dhcprelayd.dhcprelayd:main",
"dhcpservd = dhcp_utilities.dhcpservd.dhcpservd:main"
]
},
classifiers=[
Expand All @@ -43,6 +43,6 @@
"Programming Language :: Python :: 3.8"
],
package_data={
"dhcp_server.dhcpservd": ["dhcp_option.csv"]
"dhcp_utilities.dhcpservd": ["dhcp_option.csv"]
}
)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest
import dhcp_server.common.utils as utils
import dhcp_utilities.common.utils as utils
import os
import sys
from unittest.mock import patch, PropertyMock
from dhcp_server.dhcpservd.dhcp_cfggen import DhcpServCfgGenerator
from dhcp_utilities.dhcpservd.dhcp_cfggen import DhcpServCfgGenerator


test_path = os.path.dirname(os.path.abspath(__file__))
Expand All @@ -26,14 +26,14 @@ def mock_swsscommon_table_init():

@pytest.fixture(scope="function")
def mock_get_render_template():
with patch("dhcp_server.dhcpservd.dhcp_cfggen.DhcpServCfgGenerator._get_render_template",
with patch("dhcp_utilities.dhcpservd.dhcp_cfggen.DhcpServCfgGenerator._get_render_template",
return_value=None) as mock_template:
yield mock_template


@pytest.fixture
def mock_parse_port_map_alias(scope="function"):
with patch("dhcp_server.dhcpservd.dhcp_cfggen.DhcpServCfgGenerator._parse_port_map_alias",
with patch("dhcp_utilities.dhcpservd.dhcp_cfggen.DhcpServCfgGenerator._parse_port_map_alias",
return_value=None) as mock_map, \
patch.object(DhcpServCfgGenerator, "port_alias_map", return_value={"Ethernet24": "etp7", "Ethernet28": "etp8"},
new_callable=PropertyMock), \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import json
import pytest
from common_utils import MockConfigDb, mock_get_config_db_table, PORT_MODE_CHECKER
from dhcp_server.common.utils import DhcpDbConnector
from dhcp_server.dhcpservd.dhcp_cfggen import DhcpServCfgGenerator
from dhcp_utilities.common.utils import DhcpDbConnector
from dhcp_utilities.dhcpservd.dhcp_cfggen import DhcpServCfgGenerator
from unittest.mock import patch

expected_dhcp_config = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import sys
from common_utils import MockSubscribeTable, get_subscribe_table_tested_data, \
PORT_MODE_CHECKER, mock_exit_func
from dhcp_server.common.dhcp_db_monitor import DhcpRelaydDbMonitor, DhcpServdDbMonitor, ConfigDbEventChecker, \
from dhcp_utilities.common.dhcp_db_monitor import DhcpRelaydDbMonitor, DhcpServdDbMonitor, ConfigDbEventChecker, \
DhcpServerTableIntfEnablementEventChecker, DhcpServerTableCfgChangeEventChecker, \
DhcpPortTableEventChecker, DhcpRangeTableEventChecker, DhcpOptionTableEventChecker, \
VlanTableEventChecker, VlanMemberTableEventChecker, VlanIntfTableEventChecker, DhcpServerFeatureStateChecker
from dhcp_server.common.utils import DhcpDbConnector
from dhcp_utilities.common.utils import DhcpDbConnector
from swsscommon import swsscommon
from unittest.mock import patch, ANY, PropertyMock, MagicMock

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dhcp_server.common.utils import DhcpDbConnector
from dhcp_server.dhcpservd.dhcp_lease import KeaDhcp4LeaseHandler, LeaseHanlder
from dhcp_utilities.common.utils import DhcpDbConnector
from dhcp_utilities.dhcpservd.dhcp_lease import KeaDhcp4LeaseHandler, LeaseHanlder
from freezegun import freeze_time
from swsscommon import swsscommon
from unittest.mock import patch, call, MagicMock
Expand Down Expand Up @@ -60,7 +60,7 @@ def test_get_fdb_info(mock_swsscommon_dbconnector_init):
"Vlan1000:10:70:fd:b6:13:17": {"port": "Ethernet33", "type": "dynamic"},
"Vlan1000:10:70:fd:b6:13:18": {"port": "Ethernet34", "type": "dynamic"}
}
with patch("dhcp_server.common.utils.DhcpDbConnector.get_state_db_table", return_value=mock_fdb_table):
with patch("dhcp_utilities.common.utils.DhcpDbConnector.get_state_db_table", return_value=mock_fdb_table):
db_connector = DhcpDbConnector()
kea_lease_handler = KeaDhcp4LeaseHandler(db_connector, lease_file="tests/test_data/kea-lease.csv")
# Verify whether lease information read is as expected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import sys
import time
from common_utils import mock_get_config_db_table, MockProc, MockPopen, MockSubprocessRes, mock_exit_func
from dhcp_server.common.utils import DhcpDbConnector
from dhcp_server.common.dhcp_db_monitor import ConfigDbEventChecker, DhcpRelaydDbMonitor
from dhcp_server.dhcprelayd.dhcprelayd import DhcpRelayd, KILLED_OLD, NOT_KILLED, NOT_FOUND_PROC
from dhcp_utilities.common.utils import DhcpDbConnector
from dhcp_utilities.common.dhcp_db_monitor import ConfigDbEventChecker, DhcpRelaydDbMonitor
from dhcp_utilities.dhcprelayd.dhcprelayd import DhcpRelayd, KILLED_OLD, NOT_KILLED, NOT_FOUND_PROC
from swsscommon import swsscommon
from unittest.mock import patch, call, ANY, PropertyMock

Expand Down Expand Up @@ -49,7 +49,7 @@ def test_start_dhcrelay_process(mock_swsscommon_dbconnector_init, new_dhcp_inter
with patch.object(DhcpRelayd, "_kill_exist_relay_releated_process", return_value=kill_res), \
patch.object(subprocess, "Popen", return_value=MockPopen(999)) as mock_popen, \
patch.object(time, "sleep"), \
patch("dhcp_server.dhcprelayd.dhcprelayd.terminate_proc", return_value=None) as mock_terminate, \
patch("dhcp_utilities.dhcprelayd.dhcprelayd.terminate_proc", return_value=None) as mock_terminate, \
patch.object(psutil.Process, "__init__", return_value=None), \
patch.object(psutil.Process, "status", return_value=proc_status), \
patch.object(sys, "exit") as mock_exit, \
Expand Down Expand Up @@ -82,7 +82,7 @@ def test_start_dhcpmon_process(mock_swsscommon_dbconnector_init, new_dhcp_interf
with patch.object(DhcpRelayd, "_kill_exist_relay_releated_process", return_value=kill_res), \
patch.object(subprocess, "Popen", return_value=MockPopen(999)) as mock_popen, \
patch.object(time, "sleep"), \
patch("dhcp_server.dhcprelayd.dhcprelayd.terminate_proc", return_value=None) as mock_terminate, \
patch("dhcp_utilities.dhcprelayd.dhcprelayd.terminate_proc", return_value=None) as mock_terminate, \
patch.object(psutil.Process, "__init__", return_value=None), \
patch.object(psutil.Process, "status", return_value=proc_status), \
patch.object(ConfigDbEventChecker, "enable"):
Expand Down Expand Up @@ -199,7 +199,7 @@ def test_execute_supervisor_dhcp_relay_process(mock_swsscommon_dbconnector_init,
@pytest.mark.parametrize("target_cmds", [[["/usr/bin/dhcrelay"]], [["/usr/bin/dhcpmon"]]])
def test_check_dhcp_relay_process(mock_swsscommon_dbconnector_init, mock_swsscommon_table_init, target_cmds):
exp_config = {"isc-dhcpv4-relay-Vlan1000": ["/usr/bin/dhcrelay"]}
with patch("dhcp_server.dhcprelayd.dhcprelayd.get_target_process_cmds", return_value=target_cmds), \
with patch("dhcp_utilities.dhcprelayd.dhcprelayd.get_target_process_cmds", return_value=target_cmds), \
patch.object(DhcpRelayd, "dhcp_relay_supervisor_config",
return_value=exp_config, new_callable=PropertyMock), \
patch.object(sys, "exit", mock_exit_func):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import sys
import time
from common_utils import MockProc
from dhcp_server.common.utils import DhcpDbConnector
from dhcp_server.common.dhcp_db_monitor import DhcpServdDbMonitor
from dhcp_server.dhcpservd.dhcp_cfggen import DhcpServCfgGenerator
from dhcp_server.dhcpservd.dhcpservd import DhcpServd
from dhcp_utilities.common.utils import DhcpDbConnector
from dhcp_utilities.common.dhcp_db_monitor import DhcpServdDbMonitor
from dhcp_utilities.dhcpservd.dhcp_cfggen import DhcpServCfgGenerator
from dhcp_utilities.dhcpservd.dhcpservd import DhcpServd
from swsscommon import swsscommon
from unittest.mock import patch, call, MagicMock, PropertyMock

Expand All @@ -21,9 +21,9 @@
@pytest.mark.parametrize("enabled_checker", [None, set(PORT_MODE_CHECKER)])
def test_dump_dhcp4_config(mock_swsscommon_dbconnector_init, enabled_checker):
new_enabled_checker = set(["VlanTableEventChecker"])
with patch("dhcp_server.dhcpservd.dhcp_cfggen.DhcpServCfgGenerator.generate",
with patch("dhcp_utilities.dhcpservd.dhcp_cfggen.DhcpServCfgGenerator.generate",
return_value=("dummy_config", set(), set(), set(), new_enabled_checker)) as mock_generate, \
patch("dhcp_server.dhcpservd.dhcpservd.DhcpServd._notify_kea_dhcp4_proc",
patch("dhcp_utilities.dhcpservd.dhcpservd.DhcpServd._notify_kea_dhcp4_proc",
MagicMock()) as mock_notify_kea_dhcp4_proc, \
patch.object(DhcpServd, "dhcp_servd_monitor", return_value=DhcpServdDbMonitor,
new_callable=PropertyMock), \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dhcp_server.common.utils as utils
import dhcp_utilities.common.utils as utils
import ipaddress
import psutil
import pytest
Expand Down

0 comments on commit 82cebcd

Please sign in to comment.