mirror of
				https://github.com/Telecominfraproject/ols-nos.git
				synced 2025-11-03 19:47:56 +00:00 
			
		
		
		
	[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.
This commit is contained in:
		@@ -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_PYTHON_WHEELS = $(SONIC_UTILITIES_PY3)
 | 
				
			||||||
$(DOCKER_DHCP_RELAY)_INSTALL_DEBS = $(PYTHON3_SWSSCOMMON)
 | 
					$(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)_VERSION = 1.0.0
 | 
				
			||||||
$(DOCKER_DHCP_RELAY)_PACKAGE_NAME = dhcp-relay
 | 
					$(DOCKER_DHCP_RELAY)_PACKAGE_NAME = dhcp-relay
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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)_LOAD_DOCKERS = $(DOCKER_CONFIG_ENGINE_BULLSEYE)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$(DOCKER_DHCP_SERVER)_INSTALL_DEBS = $(PYTHON3_SWSSCOMMON)
 | 
					$(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)
 | 
					$(DOCKER_DHCP_SERVER)_INSTALL_PYTHON_WHEELS = $(SONIC_UTILITIES_PY3)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SONIC_DOCKER_IMAGES += $(DOCKER_DHCP_SERVER)
 | 
					SONIC_DOCKER_IMAGES += $(DOCKER_DHCP_SERVER)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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)
 | 
					 | 
				
			||||||
@@ -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)
 | 
					 | 
				
			||||||
							
								
								
									
										10
									
								
								rules/sonic-dhcp-utilities.dep
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								rules/sonic-dhcp-utilities.dep
									
									
									
									
									
										Normal file
									
								
							@@ -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
									
								
								rules/sonic-dhcp-utilities.mk
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								rules/sonic-dhcp-utilities.mk
									
									
									
									
									
										Normal file
									
								
							@@ -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
									
								
								src/sonic-dhcp-server/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								src/sonic-dhcp-server/.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,4 +0,0 @@
 | 
				
			|||||||
.eggs/
 | 
					 | 
				
			||||||
build/
 | 
					 | 
				
			||||||
dist/
 | 
					 | 
				
			||||||
sonic_dhcpservd.egg-info/
 | 
					 | 
				
			||||||
							
								
								
									
										4
									
								
								src/sonic-dhcp-utilities/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								src/sonic-dhcp-utilities/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
				
			|||||||
 | 
					.eggs/
 | 
				
			||||||
 | 
					build/
 | 
				
			||||||
 | 
					dist/
 | 
				
			||||||
 | 
					sonic_dhcp_utilities.egg-info/
 | 
				
			||||||
@@ -8,8 +8,8 @@ import sys
 | 
				
			|||||||
import syslog
 | 
					import syslog
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
from swsscommon import swsscommon
 | 
					from swsscommon import swsscommon
 | 
				
			||||||
from dhcp_server.common.utils import DhcpDbConnector, terminate_proc, get_target_process_cmds
 | 
					from dhcp_utilities.common.utils import DhcpDbConnector, terminate_proc, get_target_process_cmds
 | 
				
			||||||
from dhcp_server.common.dhcp_db_monitor import DhcpRelaydDbMonitor, DhcpServerTableIntfEnablementEventChecker, \
 | 
					from dhcp_utilities.common.dhcp_db_monitor import DhcpRelaydDbMonitor, DhcpServerTableIntfEnablementEventChecker, \
 | 
				
			||||||
     VlanTableEventChecker, VlanIntfTableEventChecker, DhcpServerFeatureStateChecker
 | 
					     VlanTableEventChecker, VlanIntfTableEventChecker, DhcpServerFeatureStateChecker
 | 
				
			||||||
 | 
					
 | 
				
			||||||
REDIS_SOCK_PATH = "/var/run/redis/redis.sock"
 | 
					REDIS_SOCK_PATH = "/var/run/redis/redis.sock"
 | 
				
			||||||
@@ -5,7 +5,7 @@ import os
 | 
				
			|||||||
import syslog
 | 
					import syslog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from jinja2 import Environment, FileSystemLoader
 | 
					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"
 | 
					PORT_MAP_PATH = "/tmp/port-name-alias-map.txt"
 | 
				
			||||||
UNICODE_TYPE = str
 | 
					UNICODE_TYPE = str
 | 
				
			||||||
@@ -6,8 +6,8 @@ import sys
 | 
				
			|||||||
import syslog
 | 
					import syslog
 | 
				
			||||||
from .dhcp_cfggen import DhcpServCfgGenerator
 | 
					from .dhcp_cfggen import DhcpServCfgGenerator
 | 
				
			||||||
from .dhcp_lease import LeaseManager
 | 
					from .dhcp_lease import LeaseManager
 | 
				
			||||||
from dhcp_server.common.utils import DhcpDbConnector
 | 
					from dhcp_utilities.common.utils import DhcpDbConnector
 | 
				
			||||||
from dhcp_server.common.dhcp_db_monitor import DhcpServdDbMonitor, DhcpServerTableCfgChangeEventChecker, \
 | 
					from dhcp_utilities.common.dhcp_db_monitor import DhcpServdDbMonitor, DhcpServerTableCfgChangeEventChecker, \
 | 
				
			||||||
    DhcpOptionTableEventChecker, DhcpRangeTableEventChecker, DhcpPortTableEventChecker, VlanIntfTableEventChecker, \
 | 
					    DhcpOptionTableEventChecker, DhcpRangeTableEventChecker, DhcpPortTableEventChecker, VlanIntfTableEventChecker, \
 | 
				
			||||||
    VlanMemberTableEventChecker, VlanTableEventChecker
 | 
					    VlanMemberTableEventChecker, VlanTableEventChecker
 | 
				
			||||||
from swsscommon import swsscommon
 | 
					from swsscommon import swsscommon
 | 
				
			||||||
@@ -7,7 +7,7 @@ testpaths = tests
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
[coverage:run]
 | 
					[coverage:run]
 | 
				
			||||||
branch = True
 | 
					branch = True
 | 
				
			||||||
source = dhcp_server
 | 
					source = dhcp_utilities
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[coverage:report]
 | 
					[coverage:report]
 | 
				
			||||||
exclude_lines =
 | 
					exclude_lines =
 | 
				
			||||||
@@ -10,9 +10,9 @@ test_deps = [
 | 
				
			|||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
setup(
 | 
					setup(
 | 
				
			||||||
    name="sonic-dhcp-server",
 | 
					    name="sonic-dhcp-utilities",
 | 
				
			||||||
    install_requires=dependencies,
 | 
					    install_requires=dependencies,
 | 
				
			||||||
    description="Module of SONiC built-in dhcp_server",
 | 
					    description="Module of SONiC built-in dhcp_utilities",
 | 
				
			||||||
    version="1.0",
 | 
					    version="1.0",
 | 
				
			||||||
    url="https://github.com/Azure/sonic-buildimage",
 | 
					    url="https://github.com/Azure/sonic-buildimage",
 | 
				
			||||||
    tests_require=test_deps,
 | 
					    tests_require=test_deps,
 | 
				
			||||||
@@ -23,14 +23,14 @@ setup(
 | 
				
			|||||||
        "wheel",
 | 
					        "wheel",
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
    packages=[
 | 
					    packages=[
 | 
				
			||||||
        "dhcp_server.common",
 | 
					        "dhcp_utilities.common",
 | 
				
			||||||
        "dhcp_server.dhcpservd",
 | 
					        "dhcp_utilities.dhcpservd",
 | 
				
			||||||
        "dhcp_server.dhcprelayd"
 | 
					        "dhcp_utilities.dhcprelayd"
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
    entry_points={
 | 
					    entry_points={
 | 
				
			||||||
        "console_scripts": [
 | 
					        "console_scripts": [
 | 
				
			||||||
            "dhcprelayd = dhcp_server.dhcprelayd.dhcprelayd:main",
 | 
					            "dhcprelayd = dhcp_utilities.dhcprelayd.dhcprelayd:main",
 | 
				
			||||||
            "dhcpservd = dhcp_server.dhcpservd.dhcpservd:main"
 | 
					            "dhcpservd = dhcp_utilities.dhcpservd.dhcpservd:main"
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    classifiers=[
 | 
					    classifiers=[
 | 
				
			||||||
@@ -43,6 +43,6 @@ setup(
 | 
				
			|||||||
        "Programming Language :: Python :: 3.8"
 | 
					        "Programming Language :: Python :: 3.8"
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
    package_data={
 | 
					    package_data={
 | 
				
			||||||
        "dhcp_server.dhcpservd": ["dhcp_option.csv"]
 | 
					        "dhcp_utilities.dhcpservd": ["dhcp_option.csv"]
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
@@ -1,9 +1,9 @@
 | 
				
			|||||||
import pytest
 | 
					import pytest
 | 
				
			||||||
import dhcp_server.common.utils as utils
 | 
					import dhcp_utilities.common.utils as utils
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
from unittest.mock import patch, PropertyMock
 | 
					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__))
 | 
					test_path = os.path.dirname(os.path.abspath(__file__))
 | 
				
			||||||
@@ -26,14 +26,14 @@ def mock_swsscommon_table_init():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
@pytest.fixture(scope="function")
 | 
					@pytest.fixture(scope="function")
 | 
				
			||||||
def mock_get_render_template():
 | 
					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:
 | 
					               return_value=None) as mock_template:
 | 
				
			||||||
        yield mock_template
 | 
					        yield mock_template
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@pytest.fixture
 | 
					@pytest.fixture
 | 
				
			||||||
def mock_parse_port_map_alias(scope="function"):
 | 
					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, \
 | 
					               return_value=None) as mock_map, \
 | 
				
			||||||
         patch.object(DhcpServCfgGenerator, "port_alias_map", return_value={"Ethernet24": "etp7", "Ethernet28": "etp8"},
 | 
					         patch.object(DhcpServCfgGenerator, "port_alias_map", return_value={"Ethernet24": "etp7", "Ethernet28": "etp8"},
 | 
				
			||||||
                      new_callable=PropertyMock), \
 | 
					                      new_callable=PropertyMock), \
 | 
				
			||||||
@@ -3,8 +3,8 @@ import ipaddress
 | 
				
			|||||||
import json
 | 
					import json
 | 
				
			||||||
import pytest
 | 
					import pytest
 | 
				
			||||||
from common_utils import MockConfigDb, mock_get_config_db_table, PORT_MODE_CHECKER
 | 
					from common_utils import MockConfigDb, mock_get_config_db_table, PORT_MODE_CHECKER
 | 
				
			||||||
from dhcp_server.common.utils import DhcpDbConnector
 | 
					from dhcp_utilities.common.utils import DhcpDbConnector
 | 
				
			||||||
from dhcp_server.dhcpservd.dhcp_cfggen import DhcpServCfgGenerator
 | 
					from dhcp_utilities.dhcpservd.dhcp_cfggen import DhcpServCfgGenerator
 | 
				
			||||||
from unittest.mock import patch
 | 
					from unittest.mock import patch
 | 
				
			||||||
 | 
					
 | 
				
			||||||
expected_dhcp_config = {
 | 
					expected_dhcp_config = {
 | 
				
			||||||
@@ -2,11 +2,11 @@ import pytest
 | 
				
			|||||||
import sys
 | 
					import sys
 | 
				
			||||||
from common_utils import MockSubscribeTable, get_subscribe_table_tested_data, \
 | 
					from common_utils import MockSubscribeTable, get_subscribe_table_tested_data, \
 | 
				
			||||||
    PORT_MODE_CHECKER, mock_exit_func
 | 
					    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, \
 | 
					    DhcpServerTableIntfEnablementEventChecker, DhcpServerTableCfgChangeEventChecker, \
 | 
				
			||||||
    DhcpPortTableEventChecker, DhcpRangeTableEventChecker, DhcpOptionTableEventChecker, \
 | 
					    DhcpPortTableEventChecker, DhcpRangeTableEventChecker, DhcpOptionTableEventChecker, \
 | 
				
			||||||
    VlanTableEventChecker, VlanMemberTableEventChecker, VlanIntfTableEventChecker, DhcpServerFeatureStateChecker
 | 
					    VlanTableEventChecker, VlanMemberTableEventChecker, VlanIntfTableEventChecker, DhcpServerFeatureStateChecker
 | 
				
			||||||
from dhcp_server.common.utils import DhcpDbConnector
 | 
					from dhcp_utilities.common.utils import DhcpDbConnector
 | 
				
			||||||
from swsscommon import swsscommon
 | 
					from swsscommon import swsscommon
 | 
				
			||||||
from unittest.mock import patch, ANY, PropertyMock, MagicMock
 | 
					from unittest.mock import patch, ANY, PropertyMock, MagicMock
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
from dhcp_server.common.utils import DhcpDbConnector
 | 
					from dhcp_utilities.common.utils import DhcpDbConnector
 | 
				
			||||||
from dhcp_server.dhcpservd.dhcp_lease import KeaDhcp4LeaseHandler, LeaseHanlder
 | 
					from dhcp_utilities.dhcpservd.dhcp_lease import KeaDhcp4LeaseHandler, LeaseHanlder
 | 
				
			||||||
from freezegun import freeze_time
 | 
					from freezegun import freeze_time
 | 
				
			||||||
from swsscommon import swsscommon
 | 
					from swsscommon import swsscommon
 | 
				
			||||||
from unittest.mock import patch, call, MagicMock
 | 
					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:17": {"port": "Ethernet33", "type": "dynamic"},
 | 
				
			||||||
        "Vlan1000:10:70:fd:b6:13:18": {"port": "Ethernet34", "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()
 | 
					        db_connector = DhcpDbConnector()
 | 
				
			||||||
        kea_lease_handler = KeaDhcp4LeaseHandler(db_connector, lease_file="tests/test_data/kea-lease.csv")
 | 
					        kea_lease_handler = KeaDhcp4LeaseHandler(db_connector, lease_file="tests/test_data/kea-lease.csv")
 | 
				
			||||||
        # Verify whether lease information read is as expected
 | 
					        # Verify whether lease information read is as expected
 | 
				
			||||||
@@ -4,9 +4,9 @@ import subprocess
 | 
				
			|||||||
import sys
 | 
					import sys
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
from common_utils import mock_get_config_db_table, MockProc, MockPopen, MockSubprocessRes, mock_exit_func
 | 
					from common_utils import mock_get_config_db_table, MockProc, MockPopen, MockSubprocessRes, mock_exit_func
 | 
				
			||||||
from dhcp_server.common.utils import DhcpDbConnector
 | 
					from dhcp_utilities.common.utils import DhcpDbConnector
 | 
				
			||||||
from dhcp_server.common.dhcp_db_monitor import ConfigDbEventChecker, DhcpRelaydDbMonitor
 | 
					from dhcp_utilities.common.dhcp_db_monitor import ConfigDbEventChecker, DhcpRelaydDbMonitor
 | 
				
			||||||
from dhcp_server.dhcprelayd.dhcprelayd import DhcpRelayd, KILLED_OLD, NOT_KILLED, NOT_FOUND_PROC
 | 
					from dhcp_utilities.dhcprelayd.dhcprelayd import DhcpRelayd, KILLED_OLD, NOT_KILLED, NOT_FOUND_PROC
 | 
				
			||||||
from swsscommon import swsscommon
 | 
					from swsscommon import swsscommon
 | 
				
			||||||
from unittest.mock import patch, call, ANY, PropertyMock
 | 
					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), \
 | 
					    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(subprocess, "Popen", return_value=MockPopen(999)) as mock_popen, \
 | 
				
			||||||
         patch.object(time, "sleep"), \
 | 
					         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, "__init__", return_value=None), \
 | 
				
			||||||
         patch.object(psutil.Process, "status", return_value=proc_status), \
 | 
					         patch.object(psutil.Process, "status", return_value=proc_status), \
 | 
				
			||||||
         patch.object(sys, "exit") as mock_exit, \
 | 
					         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), \
 | 
					    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(subprocess, "Popen", return_value=MockPopen(999)) as mock_popen, \
 | 
				
			||||||
         patch.object(time, "sleep"), \
 | 
					         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, "__init__", return_value=None), \
 | 
				
			||||||
         patch.object(psutil.Process, "status", return_value=proc_status), \
 | 
					         patch.object(psutil.Process, "status", return_value=proc_status), \
 | 
				
			||||||
         patch.object(ConfigDbEventChecker, "enable"):
 | 
					         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"]]])
 | 
					@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):
 | 
					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"]}
 | 
					    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",
 | 
					         patch.object(DhcpRelayd, "dhcp_relay_supervisor_config",
 | 
				
			||||||
                      return_value=exp_config, new_callable=PropertyMock), \
 | 
					                      return_value=exp_config, new_callable=PropertyMock), \
 | 
				
			||||||
         patch.object(sys, "exit", mock_exit_func):
 | 
					         patch.object(sys, "exit", mock_exit_func):
 | 
				
			||||||
@@ -4,10 +4,10 @@ import signal
 | 
				
			|||||||
import sys
 | 
					import sys
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
from common_utils import MockProc
 | 
					from common_utils import MockProc
 | 
				
			||||||
from dhcp_server.common.utils import DhcpDbConnector
 | 
					from dhcp_utilities.common.utils import DhcpDbConnector
 | 
				
			||||||
from dhcp_server.common.dhcp_db_monitor import DhcpServdDbMonitor
 | 
					from dhcp_utilities.common.dhcp_db_monitor import DhcpServdDbMonitor
 | 
				
			||||||
from dhcp_server.dhcpservd.dhcp_cfggen import DhcpServCfgGenerator
 | 
					from dhcp_utilities.dhcpservd.dhcp_cfggen import DhcpServCfgGenerator
 | 
				
			||||||
from dhcp_server.dhcpservd.dhcpservd import DhcpServd
 | 
					from dhcp_utilities.dhcpservd.dhcpservd import DhcpServd
 | 
				
			||||||
from swsscommon import swsscommon
 | 
					from swsscommon import swsscommon
 | 
				
			||||||
from unittest.mock import patch, call, MagicMock, PropertyMock
 | 
					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)])
 | 
					@pytest.mark.parametrize("enabled_checker", [None, set(PORT_MODE_CHECKER)])
 | 
				
			||||||
def test_dump_dhcp4_config(mock_swsscommon_dbconnector_init, enabled_checker):
 | 
					def test_dump_dhcp4_config(mock_swsscommon_dbconnector_init, enabled_checker):
 | 
				
			||||||
    new_enabled_checker = set(["VlanTableEventChecker"])
 | 
					    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, \
 | 
					               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, \
 | 
					               MagicMock()) as mock_notify_kea_dhcp4_proc, \
 | 
				
			||||||
         patch.object(DhcpServd, "dhcp_servd_monitor", return_value=DhcpServdDbMonitor,
 | 
					         patch.object(DhcpServd, "dhcp_servd_monitor", return_value=DhcpServdDbMonitor,
 | 
				
			||||||
                      new_callable=PropertyMock), \
 | 
					                      new_callable=PropertyMock), \
 | 
				
			||||||
@@ -1,4 +1,4 @@
 | 
				
			|||||||
import dhcp_server.common.utils as utils
 | 
					import dhcp_utilities.common.utils as utils
 | 
				
			||||||
import ipaddress
 | 
					import ipaddress
 | 
				
			||||||
import psutil
 | 
					import psutil
 | 
				
			||||||
import pytest
 | 
					import pytest
 | 
				
			||||||
		Reference in New Issue
	
	Block a user