Skip to content

Commit

Permalink
errorss
Browse files Browse the repository at this point in the history
  • Loading branch information
kanza-latif committed Sep 26, 2024
1 parent b899dfd commit a76deb7
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion tests/hostcfgd/hostcfgd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def test_mgmtiface_event(self):
]
mocked_check_output.assert_has_calls(expected)

@patch('hostcfgd.ConfigDBConnector', autospec=True)
@patch('sonic_py_common.ConfigDBConnector', autospec=True)
def test_memory_statistics_event(self, mock_config_db_connector):
# Mock the ConfigDBConnector instance methods
mock_instance = mock_config_db_connector.return_value
Expand Down Expand Up @@ -358,6 +358,39 @@ def test_memory_statistics_event(self, mock_config_db_connector):
# Check if subprocess Popen was called with correct arguments
mocked_popen.assert_has_calls(expected_calls, any_order=True)



# @patch('hostcfgd.ConfigDBConnector'
# def test_memory_statistics_event(self, mock_config_db_connector):
# print("Available keys in HOSTCFG_DAEMON_CFG_DB:", HOSTCFG_DAEMON_CFG_DB.keys())
# # Mock the ConfigDBConnector instance methods
# mock_instance = mock_config_db_connector.return_value
# # Make sure get_table returns the correct nested structure
# mock_instance.get_table.return_value = HOSTCFG_DAEMON_CFG_DB['MEMORY_STATISTICS']['memory_statistics']

# # Mock the subprocess module to avoid real process callswith mock.patch('hostcfgd.subprocess') as mocked_subprocess:
# daemon = hostcfgd.HostConfigDaemon() # Create the daemon instance# Load config using the correct nested dictionary
# daemon.memory_statisticsCfg.load(HOSTCFG_DAEMON_CFG_DB['MEMORY_STATISTICS']['memory_statistics'])

# # Mock the subprocess.Popen and check_call
# popen_mock = mock.Mock()
# attrs = {'communicate.return_value': ('output', 'error')}
# popen_mock.configure_mock(**attrs)
# mocked_subprocess.Popen.return_value = popen_mock
# mocked_subprocess.check_call = mock.Mock()

# # Trigger event handler
# MockConfigDb.event_queue = [('MEMORY_STATISTICS', 'config')]
# daemon.memory_statistics_handler('enabled', 'SET', 'true')

# # Define expected subprocess calls
# expected_calls = [
# mock.call(['/usr/bin/memorystatsd']),
# ]

# # Check if subprocess check_call was made with correct arguments
# mocked_subprocess.Popen.assert_has_calls(expected_calls, any_order=True)

def test_dns_events(self):
MockConfigDb.set_config_db(HOSTCFG_DAEMON_CFG_DB)
MockConfigDb.event_queue = [('DNS_NAMESERVER', '1.1.1.1')]
Expand Down

0 comments on commit a76deb7

Please sign in to comment.