11import os
22import sys
33import time
4- import hostcfgd
54import swsscommon as swsscommon_package
65from sonic_py_common import device_info
76from swsscommon import swsscommon
@@ -325,29 +324,21 @@ def test_mgmtiface_event(self):
325324 ]
326325 mocked_check_output .assert_has_calls (expected )
327326
328- class TestHostcfgdDaemon (TestCase ):
329-
330327 @patch ('hostcfgd.ConfigDBConnector' , autospec = True )
331328 def test_memory_statistics_event (self , mock_config_db_connector ):
332329 # Mock the ConfigDBConnector instance methods
333330 mock_instance = mock_config_db_connector .return_value
334-
335- # Ensure get_table returns the correct nested structure
336- # Check if 'MEMORY_STATISTICS' exists in the HOSTCFG_DAEMON_CFG_DB
337- memory_statistics = HOSTCFG_DAEMON_CFG_DB .get ('MEMORY_STATISTICS' , {}).get ('memory_statistics' , {})
338- if not memory_statistics :
339- raise ValueError ("No MEMORY_STATISTICS data found in HOSTCFG_DAEMON_CFG_DB" )
340-
341- mock_instance .get_table .return_value = memory_statistics
331+ # Ensure get_table returns the correct nested structur
332+ mock_instance .get_table .return_value = HOSTCFG_DAEMON_CFG_DB ['MEMORY_STATISTICS' ]['memory_statistics' ]
342333
343334 # Patch subprocess.Popen and check_call
344- with patch ('hostcfgd.subprocess.Popen' ) as mocked_popen , \
345- patch ('hostcfgd.subprocess.check_call' ) as mocked_check_call :
335+ with mock . patch ('hostcfgd.subprocess.Popen' ) as mocked_popen , \
336+ mock . patch ('hostcfgd.subprocess.check_call' ) as mocked_check_call :
346337
347338 # Create the daemon instance
348339 daemon = hostcfgd .HostConfigDaemon ()
349340 # Load config using the correct nested dictionary
350- daemon .memory_statisticsCfg .load (memory_statistics )
341+ daemon .memory_statisticsCfg .load (HOSTCFG_DAEMON_CFG_DB [ 'MEMORY_STATISTICS' ][ ' memory_statistics' ] )
351342
352343 # Mock subprocess.Popen behavior
353344 popen_mock = mock .Mock ()
@@ -367,7 +358,6 @@ def test_memory_statistics_event(self, mock_config_db_connector):
367358 # Check if subprocess Popen was called with correct arguments
368359 mocked_popen .assert_has_calls (expected_calls , any_order = True )
369360
370-
371361 def test_dns_events (self ):
372362 MockConfigDb .set_config_db (HOSTCFG_DAEMON_CFG_DB )
373363 MockConfigDb .event_queue = [('DNS_NAMESERVER' , '1.1.1.1' )]
0 commit comments