def test_kill_pids_in_file(self): with contextlib.nested( mock.patch('os.path.exists'), mock.patch('__builtin__.open'), mock.patch('neutron.agent.linux.utils.execute'), mock.patch.object(namespace_driver.LOG, 'exception'), ) as (path_exists, mock_open, mock_execute, mock_log): file_mock = mock.MagicMock() mock_open.return_value = file_mock file_mock.__enter__.return_value = file_mock file_mock.__iter__.return_value = iter(['123']) path_exists.return_value = False namespace_driver.kill_pids_in_file('test_path') path_exists.assert_called_once_with('test_path') self.assertFalse(mock_open.called) self.assertFalse(mock_execute.called) path_exists.return_value = True mock_execute.side_effect = RuntimeError namespace_driver.kill_pids_in_file('test_path') self.assertTrue(mock_log.called) mock_execute.assert_called_once_with(['kill', '-9', '123'], run_as_root=True)
def test_kill_pids_in_file(self): with contextlib.nested( mock.patch('os.path.exists'), mock.patch.object(six.moves.builtins, 'open'), mock.patch('neutron.agent.linux.utils.execute'), mock.patch.object(namespace_driver.LOG, 'exception'), ) as (path_exists, mock_open, mock_execute, mock_log): file_mock = mock.MagicMock() mock_open.return_value = file_mock file_mock.__enter__.return_value = file_mock file_mock.__iter__.return_value = iter(['123']) path_exists.return_value = False namespace_driver.kill_pids_in_file('test_path') path_exists.assert_called_once_with('test_path') self.assertFalse(mock_open.called) self.assertFalse(mock_execute.called) path_exists.return_value = True mock_execute.side_effect = RuntimeError namespace_driver.kill_pids_in_file('test_path') self.assertTrue(mock_log.called) mock_execute.assert_called_once_with( ['kill', '-9', '123'], run_as_root=True)
def _kill_processes(self, loadbalancer_id): pid_path = self._get_state_file_path(loadbalancer_id, 'haproxy.pid') # kill the process namespace_driver.kill_pids_in_file(pid_path)
def _kill_processes(self, loadbalancer_id): pid_path = self._get_state_file_path(loadbalancer_id, 'haproxy.pid') # kill the process namespace_driver.kill_pids_in_file(pid_path)