From 59dddb14d47e73bdfce56e6a2bd4882f49d20f8c Mon Sep 17 00:00:00 2001 From: Yaqiang Zhu Date: Tue, 28 Nov 2023 16:28:16 -0500 Subject: [PATCH] [dhcp_server] Rename sonic_dhcp_server to sonic_dhcp_utilities (#17276) 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. --- rules/docker-dhcp-relay.mk | 2 +- rules/docker-dhcp-server.mk | 2 +- rules/sonic-dhcp-server.dep | 10 ---------- rules/sonic-dhcp-server.mk | 8 -------- rules/sonic-dhcp-utilities.dep | 10 ++++++++++ rules/sonic-dhcp-utilities.mk | 8 ++++++++ src/sonic-dhcp-server/.gitignore | 4 ---- src/sonic-dhcp-utilities/.gitignore | 4 ++++ .../dhcp_utilities}/common/__init__.py | 0 .../dhcp_utilities}/common/dhcp_db_monitor.py | 0 .../dhcp_utilities}/common/utils.py | 0 .../dhcp_utilities}/dhcprelayd/dhcprelayd.py | 4 ++-- .../dhcp_utilities}/dhcpservd/dhcp_cfggen.py | 2 +- .../dhcp_utilities}/dhcpservd/dhcp_lease.py | 0 .../dhcp_utilities}/dhcpservd/dhcp_option.csv | 0 .../dhcp_utilities}/dhcpservd/dhcpservd.py | 4 ++-- .../setup.cfg | 2 +- .../setup.py | 16 ++++++++-------- .../tests/common_utils.py | 0 .../tests/conftest.py | 8 ++++---- .../test_data/dhcp_db_monitor_test_data.json | 0 .../tests/test_data/kea-dhcp4.conf.j2 | 0 .../tests/test_data/kea-lease.csv | 0 .../tests/test_data/mock_config_db.json | 0 .../mock_config_db_without_port_config.json | 0 .../tests/test_data/port-name-alias-map.txt | 0 .../tests/test_data/supervisor.conf | 0 .../tests/test_dhcp_cfggen.py | 4 ++-- .../tests/test_dhcp_db_monitor.py | 4 ++-- .../tests/test_dhcp_lease.py | 6 +++--- .../tests/test_dhcprelayd.py | 12 ++++++------ .../tests/test_dhcpservd.py | 12 ++++++------ .../tests/test_utils.py | 2 +- 33 files changed, 62 insertions(+), 62 deletions(-) delete mode 100644 rules/sonic-dhcp-server.dep delete mode 100644 rules/sonic-dhcp-server.mk create mode 100644 rules/sonic-dhcp-utilities.dep create mode 100644 rules/sonic-dhcp-utilities.mk delete mode 100644 src/sonic-dhcp-server/.gitignore create mode 100644 src/sonic-dhcp-utilities/.gitignore rename src/{sonic-dhcp-server/dhcp_server => sonic-dhcp-utilities/dhcp_utilities}/common/__init__.py (100%) rename src/{sonic-dhcp-server/dhcp_server => sonic-dhcp-utilities/dhcp_utilities}/common/dhcp_db_monitor.py (100%) rename src/{sonic-dhcp-server/dhcp_server => sonic-dhcp-utilities/dhcp_utilities}/common/utils.py (100%) rename src/{sonic-dhcp-server/dhcp_server => sonic-dhcp-utilities/dhcp_utilities}/dhcprelayd/dhcprelayd.py (98%) rename src/{sonic-dhcp-server/dhcp_server => sonic-dhcp-utilities/dhcp_utilities}/dhcpservd/dhcp_cfggen.py (99%) rename src/{sonic-dhcp-server/dhcp_server => sonic-dhcp-utilities/dhcp_utilities}/dhcpservd/dhcp_lease.py (100%) rename src/{sonic-dhcp-server/dhcp_server => sonic-dhcp-utilities/dhcp_utilities}/dhcpservd/dhcp_option.csv (100%) rename src/{sonic-dhcp-server/dhcp_server => sonic-dhcp-utilities/dhcp_utilities}/dhcpservd/dhcpservd.py (96%) rename src/{sonic-dhcp-server => sonic-dhcp-utilities}/setup.cfg (91%) rename src/{sonic-dhcp-server => sonic-dhcp-utilities}/setup.py (69%) rename src/{sonic-dhcp-server => sonic-dhcp-utilities}/tests/common_utils.py (100%) rename src/{sonic-dhcp-server => sonic-dhcp-utilities}/tests/conftest.py (81%) rename src/{sonic-dhcp-server => sonic-dhcp-utilities}/tests/test_data/dhcp_db_monitor_test_data.json (100%) rename src/{sonic-dhcp-server => sonic-dhcp-utilities}/tests/test_data/kea-dhcp4.conf.j2 (100%) rename src/{sonic-dhcp-server => sonic-dhcp-utilities}/tests/test_data/kea-lease.csv (100%) rename src/{sonic-dhcp-server => sonic-dhcp-utilities}/tests/test_data/mock_config_db.json (100%) rename src/{sonic-dhcp-server => sonic-dhcp-utilities}/tests/test_data/mock_config_db_without_port_config.json (100%) rename src/{sonic-dhcp-server => sonic-dhcp-utilities}/tests/test_data/port-name-alias-map.txt (100%) rename src/{sonic-dhcp-server => sonic-dhcp-utilities}/tests/test_data/supervisor.conf (100%) rename src/{sonic-dhcp-server => sonic-dhcp-utilities}/tests/test_dhcp_cfggen.py (99%) rename src/{sonic-dhcp-server => sonic-dhcp-utilities}/tests/test_dhcp_db_monitor.py (99%) rename src/{sonic-dhcp-server => sonic-dhcp-utilities}/tests/test_dhcp_lease.py (94%) rename src/{sonic-dhcp-server => sonic-dhcp-utilities}/tests/test_dhcprelayd.py (95%) rename src/{sonic-dhcp-server => sonic-dhcp-utilities}/tests/test_dhcpservd.py (92%) rename src/{sonic-dhcp-server => sonic-dhcp-utilities}/tests/test_utils.py (98%) diff --git a/rules/docker-dhcp-relay.mk b/rules/docker-dhcp-relay.mk index ad1d0ff3b0..6f1b23ab80 100644 --- a/rules/docker-dhcp-relay.mk +++ b/rules/docker-dhcp-relay.mk @@ -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 diff --git a/rules/docker-dhcp-server.mk b/rules/docker-dhcp-server.mk index d72e49461f..004888b68f 100644 --- a/rules/docker-dhcp-server.mk +++ b/rules/docker-dhcp-server.mk @@ -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) diff --git a/rules/sonic-dhcp-server.dep b/rules/sonic-dhcp-server.dep deleted file mode 100644 index 891fffbe20..0000000000 --- a/rules/sonic-dhcp-server.dep +++ /dev/null @@ -1,10 +0,0 @@ -SPATH := $($(SONIC_DHCPSERVD)_SRC_PATH) -DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/sonic-dhcp-server.mk rules/sonic-dhcp-server.dep -DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST) -SMDEP_FILES := $(addprefix $(SPATH)/,$(shell cd $(SPATH) && git ls-files)) - -$(SONIC_DHCPSERVD)_CACHE_MODE := GIT_CONTENT_SHA -$(SONIC_DHCPSERVD)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) -$(SONIC_DHCPSERVD)_DEP_FILES := $(DEP_FILES) -$(SONIC_DHCPSERVD)_SMDEP_FILES := $(SMDEP_FILES) -$(SONIC_DHCPSERVD)_SMDEP_PATHS := $(SPATH) diff --git a/rules/sonic-dhcp-server.mk b/rules/sonic-dhcp-server.mk deleted file mode 100644 index 1ef05545b9..0000000000 --- a/rules/sonic-dhcp-server.mk +++ /dev/null @@ -1,8 +0,0 @@ -# sonic-dhcp-server package - -SONIC_DHCP_SERVER_PY3 = sonic_dhcp_server-1.0-py3-none-any.whl -$(SONIC_DHCP_SERVER_PY3)_SRC_PATH = $(SRC_PATH)/sonic-dhcp-server -$(SONIC_DHCP_SERVER_PY3)_DEPENDS += $(SONIC_PY_COMMON_PY3) -$(SONIC_DHCP_SERVER_PY3)_DEBS_DEPENDS = $(LIBSWSSCOMMON) $(PYTHON3_SWSSCOMMON) -$(SONIC_DHCP_SERVER_PY3)_PYTHON_VERSION = 3 -SONIC_PYTHON_WHEELS += $(SONIC_DHCP_SERVER_PY3) diff --git a/rules/sonic-dhcp-utilities.dep b/rules/sonic-dhcp-utilities.dep new file mode 100644 index 0000000000..cc257ca6e4 --- /dev/null +++ b/rules/sonic-dhcp-utilities.dep @@ -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) diff --git a/rules/sonic-dhcp-utilities.mk b/rules/sonic-dhcp-utilities.mk new file mode 100644 index 0000000000..dae1fc22b8 --- /dev/null +++ b/rules/sonic-dhcp-utilities.mk @@ -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) diff --git a/src/sonic-dhcp-server/.gitignore b/src/sonic-dhcp-server/.gitignore deleted file mode 100644 index 8f5a21dd76..0000000000 --- a/src/sonic-dhcp-server/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.eggs/ -build/ -dist/ -sonic_dhcpservd.egg-info/ diff --git a/src/sonic-dhcp-utilities/.gitignore b/src/sonic-dhcp-utilities/.gitignore new file mode 100644 index 0000000000..409d322ac7 --- /dev/null +++ b/src/sonic-dhcp-utilities/.gitignore @@ -0,0 +1,4 @@ +.eggs/ +build/ +dist/ +sonic_dhcp_utilities.egg-info/ diff --git a/src/sonic-dhcp-server/dhcp_server/common/__init__.py b/src/sonic-dhcp-utilities/dhcp_utilities/common/__init__.py similarity index 100% rename from src/sonic-dhcp-server/dhcp_server/common/__init__.py rename to src/sonic-dhcp-utilities/dhcp_utilities/common/__init__.py diff --git a/src/sonic-dhcp-server/dhcp_server/common/dhcp_db_monitor.py b/src/sonic-dhcp-utilities/dhcp_utilities/common/dhcp_db_monitor.py similarity index 100% rename from src/sonic-dhcp-server/dhcp_server/common/dhcp_db_monitor.py rename to src/sonic-dhcp-utilities/dhcp_utilities/common/dhcp_db_monitor.py diff --git a/src/sonic-dhcp-server/dhcp_server/common/utils.py b/src/sonic-dhcp-utilities/dhcp_utilities/common/utils.py similarity index 100% rename from src/sonic-dhcp-server/dhcp_server/common/utils.py rename to src/sonic-dhcp-utilities/dhcp_utilities/common/utils.py diff --git a/src/sonic-dhcp-server/dhcp_server/dhcprelayd/dhcprelayd.py b/src/sonic-dhcp-utilities/dhcp_utilities/dhcprelayd/dhcprelayd.py similarity index 98% rename from src/sonic-dhcp-server/dhcp_server/dhcprelayd/dhcprelayd.py rename to src/sonic-dhcp-utilities/dhcp_utilities/dhcprelayd/dhcprelayd.py index 6eded1c350..92249e8b9c 100644 --- a/src/sonic-dhcp-server/dhcp_server/dhcprelayd/dhcprelayd.py +++ b/src/sonic-dhcp-utilities/dhcp_utilities/dhcprelayd/dhcprelayd.py @@ -8,8 +8,8 @@ import sys 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" diff --git a/src/sonic-dhcp-server/dhcp_server/dhcpservd/dhcp_cfggen.py b/src/sonic-dhcp-utilities/dhcp_utilities/dhcpservd/dhcp_cfggen.py similarity index 99% rename from src/sonic-dhcp-server/dhcp_server/dhcpservd/dhcp_cfggen.py rename to src/sonic-dhcp-utilities/dhcp_utilities/dhcpservd/dhcp_cfggen.py index c5017a5d22..438a6e8147 100755 --- a/src/sonic-dhcp-server/dhcp_server/dhcpservd/dhcp_cfggen.py +++ b/src/sonic-dhcp-utilities/dhcp_utilities/dhcpservd/dhcp_cfggen.py @@ -5,7 +5,7 @@ import os 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 diff --git a/src/sonic-dhcp-server/dhcp_server/dhcpservd/dhcp_lease.py b/src/sonic-dhcp-utilities/dhcp_utilities/dhcpservd/dhcp_lease.py similarity index 100% rename from src/sonic-dhcp-server/dhcp_server/dhcpservd/dhcp_lease.py rename to src/sonic-dhcp-utilities/dhcp_utilities/dhcpservd/dhcp_lease.py diff --git a/src/sonic-dhcp-server/dhcp_server/dhcpservd/dhcp_option.csv b/src/sonic-dhcp-utilities/dhcp_utilities/dhcpservd/dhcp_option.csv similarity index 100% rename from src/sonic-dhcp-server/dhcp_server/dhcpservd/dhcp_option.csv rename to src/sonic-dhcp-utilities/dhcp_utilities/dhcpservd/dhcp_option.csv diff --git a/src/sonic-dhcp-server/dhcp_server/dhcpservd/dhcpservd.py b/src/sonic-dhcp-utilities/dhcp_utilities/dhcpservd/dhcpservd.py similarity index 96% rename from src/sonic-dhcp-server/dhcp_server/dhcpservd/dhcpservd.py rename to src/sonic-dhcp-utilities/dhcp_utilities/dhcpservd/dhcpservd.py index 997628276d..8911a33416 100644 --- a/src/sonic-dhcp-server/dhcp_server/dhcpservd/dhcpservd.py +++ b/src/sonic-dhcp-utilities/dhcp_utilities/dhcpservd/dhcpservd.py @@ -6,8 +6,8 @@ import sys 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 diff --git a/src/sonic-dhcp-server/setup.cfg b/src/sonic-dhcp-utilities/setup.cfg similarity index 91% rename from src/sonic-dhcp-server/setup.cfg rename to src/sonic-dhcp-utilities/setup.cfg index a9cd7dd6a1..ea271363ca 100644 --- a/src/sonic-dhcp-server/setup.cfg +++ b/src/sonic-dhcp-utilities/setup.cfg @@ -7,7 +7,7 @@ testpaths = tests [coverage:run] branch = True -source = dhcp_server +source = dhcp_utilities [coverage:report] exclude_lines = diff --git a/src/sonic-dhcp-server/setup.py b/src/sonic-dhcp-utilities/setup.py similarity index 69% rename from src/sonic-dhcp-server/setup.py rename to src/sonic-dhcp-utilities/setup.py index caf69e920d..2429cd1098 100644 --- a/src/sonic-dhcp-server/setup.py +++ b/src/sonic-dhcp-utilities/setup.py @@ -10,9 +10,9 @@ test_deps = [ ] 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, @@ -23,14 +23,14 @@ setup( "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=[ @@ -43,6 +43,6 @@ setup( "Programming Language :: Python :: 3.8" ], package_data={ - "dhcp_server.dhcpservd": ["dhcp_option.csv"] + "dhcp_utilities.dhcpservd": ["dhcp_option.csv"] } ) diff --git a/src/sonic-dhcp-server/tests/common_utils.py b/src/sonic-dhcp-utilities/tests/common_utils.py similarity index 100% rename from src/sonic-dhcp-server/tests/common_utils.py rename to src/sonic-dhcp-utilities/tests/common_utils.py diff --git a/src/sonic-dhcp-server/tests/conftest.py b/src/sonic-dhcp-utilities/tests/conftest.py similarity index 81% rename from src/sonic-dhcp-server/tests/conftest.py rename to src/sonic-dhcp-utilities/tests/conftest.py index 9661a0be43..ae75df4822 100644 --- a/src/sonic-dhcp-server/tests/conftest.py +++ b/src/sonic-dhcp-utilities/tests/conftest.py @@ -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__)) @@ -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), \ diff --git a/src/sonic-dhcp-server/tests/test_data/dhcp_db_monitor_test_data.json b/src/sonic-dhcp-utilities/tests/test_data/dhcp_db_monitor_test_data.json similarity index 100% rename from src/sonic-dhcp-server/tests/test_data/dhcp_db_monitor_test_data.json rename to src/sonic-dhcp-utilities/tests/test_data/dhcp_db_monitor_test_data.json diff --git a/src/sonic-dhcp-server/tests/test_data/kea-dhcp4.conf.j2 b/src/sonic-dhcp-utilities/tests/test_data/kea-dhcp4.conf.j2 similarity index 100% rename from src/sonic-dhcp-server/tests/test_data/kea-dhcp4.conf.j2 rename to src/sonic-dhcp-utilities/tests/test_data/kea-dhcp4.conf.j2 diff --git a/src/sonic-dhcp-server/tests/test_data/kea-lease.csv b/src/sonic-dhcp-utilities/tests/test_data/kea-lease.csv similarity index 100% rename from src/sonic-dhcp-server/tests/test_data/kea-lease.csv rename to src/sonic-dhcp-utilities/tests/test_data/kea-lease.csv diff --git a/src/sonic-dhcp-server/tests/test_data/mock_config_db.json b/src/sonic-dhcp-utilities/tests/test_data/mock_config_db.json similarity index 100% rename from src/sonic-dhcp-server/tests/test_data/mock_config_db.json rename to src/sonic-dhcp-utilities/tests/test_data/mock_config_db.json diff --git a/src/sonic-dhcp-server/tests/test_data/mock_config_db_without_port_config.json b/src/sonic-dhcp-utilities/tests/test_data/mock_config_db_without_port_config.json similarity index 100% rename from src/sonic-dhcp-server/tests/test_data/mock_config_db_without_port_config.json rename to src/sonic-dhcp-utilities/tests/test_data/mock_config_db_without_port_config.json diff --git a/src/sonic-dhcp-server/tests/test_data/port-name-alias-map.txt b/src/sonic-dhcp-utilities/tests/test_data/port-name-alias-map.txt similarity index 100% rename from src/sonic-dhcp-server/tests/test_data/port-name-alias-map.txt rename to src/sonic-dhcp-utilities/tests/test_data/port-name-alias-map.txt diff --git a/src/sonic-dhcp-server/tests/test_data/supervisor.conf b/src/sonic-dhcp-utilities/tests/test_data/supervisor.conf similarity index 100% rename from src/sonic-dhcp-server/tests/test_data/supervisor.conf rename to src/sonic-dhcp-utilities/tests/test_data/supervisor.conf diff --git a/src/sonic-dhcp-server/tests/test_dhcp_cfggen.py b/src/sonic-dhcp-utilities/tests/test_dhcp_cfggen.py similarity index 99% rename from src/sonic-dhcp-server/tests/test_dhcp_cfggen.py rename to src/sonic-dhcp-utilities/tests/test_dhcp_cfggen.py index 64a0e9904e..db76cacb25 100644 --- a/src/sonic-dhcp-server/tests/test_dhcp_cfggen.py +++ b/src/sonic-dhcp-utilities/tests/test_dhcp_cfggen.py @@ -3,8 +3,8 @@ import ipaddress 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 = { diff --git a/src/sonic-dhcp-server/tests/test_dhcp_db_monitor.py b/src/sonic-dhcp-utilities/tests/test_dhcp_db_monitor.py similarity index 99% rename from src/sonic-dhcp-server/tests/test_dhcp_db_monitor.py rename to src/sonic-dhcp-utilities/tests/test_dhcp_db_monitor.py index a51988145e..6cea6868d8 100644 --- a/src/sonic-dhcp-server/tests/test_dhcp_db_monitor.py +++ b/src/sonic-dhcp-utilities/tests/test_dhcp_db_monitor.py @@ -2,11 +2,11 @@ import pytest 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 diff --git a/src/sonic-dhcp-server/tests/test_dhcp_lease.py b/src/sonic-dhcp-utilities/tests/test_dhcp_lease.py similarity index 94% rename from src/sonic-dhcp-server/tests/test_dhcp_lease.py rename to src/sonic-dhcp-utilities/tests/test_dhcp_lease.py index 4ec748749d..892c5f9bcc 100644 --- a/src/sonic-dhcp-server/tests/test_dhcp_lease.py +++ b/src/sonic-dhcp-utilities/tests/test_dhcp_lease.py @@ -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 @@ -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 diff --git a/src/sonic-dhcp-server/tests/test_dhcprelayd.py b/src/sonic-dhcp-utilities/tests/test_dhcprelayd.py similarity index 95% rename from src/sonic-dhcp-server/tests/test_dhcprelayd.py rename to src/sonic-dhcp-utilities/tests/test_dhcprelayd.py index 1ff0d24023..9e519aad4e 100644 --- a/src/sonic-dhcp-server/tests/test_dhcprelayd.py +++ b/src/sonic-dhcp-utilities/tests/test_dhcprelayd.py @@ -4,9 +4,9 @@ import subprocess 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 @@ -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, \ @@ -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"): @@ -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): diff --git a/src/sonic-dhcp-server/tests/test_dhcpservd.py b/src/sonic-dhcp-utilities/tests/test_dhcpservd.py similarity index 92% rename from src/sonic-dhcp-server/tests/test_dhcpservd.py rename to src/sonic-dhcp-utilities/tests/test_dhcpservd.py index 0eb74ca301..5a77999d7f 100644 --- a/src/sonic-dhcp-server/tests/test_dhcpservd.py +++ b/src/sonic-dhcp-utilities/tests/test_dhcpservd.py @@ -4,10 +4,10 @@ import signal 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 @@ -21,9 +21,9 @@ PORT_MODE_CHECKER = ["DhcpServerTableCfgChangeEventChecker", "DhcpPortTableEvent @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), \ diff --git a/src/sonic-dhcp-server/tests/test_utils.py b/src/sonic-dhcp-utilities/tests/test_utils.py similarity index 98% rename from src/sonic-dhcp-server/tests/test_utils.py rename to src/sonic-dhcp-utilities/tests/test_utils.py index 129f2faf7f..8eb018a3c0 100644 --- a/src/sonic-dhcp-server/tests/test_utils.py +++ b/src/sonic-dhcp-utilities/tests/test_utils.py @@ -1,4 +1,4 @@ -import dhcp_server.common.utils as utils +import dhcp_utilities.common.utils as utils import ipaddress import psutil import pytest