Ejemplo n.º 1
0
    def test_isProcessRunning_invalidInput(self, open_mocked):
        """
        Tests to make sure the method handles errors properly

        :param open_mocked:

        """
        pid_file = '/tmp/bad_pid_file'

        nixcommon.runExternalProcess = mock.MagicMock(return_value = {'return_code':0,'stdout':'1995 bobbarker',
                                                                      'stderr':''})
        is_running = nixcommon.isProcessRunning(10)
        assert is_running == False

        is_running = nixcommon.isProcessRunning('10')
        assert is_running == False

        with pytest.raises(nixcommon.PIDError):
            nixcommon.isProcessRunning('thereisnofilehere')

        # Have to mock os.path.exist and open for this one
        nixcommon.os.path.exists = mock.MagicMock(return_value=True)
        open_mocked.return_value = mock.MagicMock(spec=file)
        open_mocked.return_value.__enter__ = mock.MagicMock()
        file_mocked = open_mocked.return_value.__enter__.return_value
        file_mocked.read.return_value = '404'
        nixcommon.open = open_mocked

        is_running = nixcommon.isProcessRunning(pid_file)
        assert is_running == False
Ejemplo n.º 2
0
    def test_isProcessRunning(self, open_mocked, exists_mocked):
        """
        Tests to make sure that the method calls pgrep in the proper manner.

        """
        pid_file = '/tmp/pidfile'

        nixcommon.runExternalProcess = mock.MagicMock(return_value = {'return_code':0,'stdout':'1995 bobbarker',
                                                                      'stderr':''})
        is_running = nixcommon.isProcessRunning(1995)
        assert is_running == True

        is_running = nixcommon.isProcessRunning('1995')
        assert is_running == True

        # Have to mock os.path.exist and open for this one
        nixcommon.os.path.exists = exists_mocked
        open_mocked.return_value = mock.MagicMock(spec=file)
        open_mocked.return_value.__enter__ = mock.MagicMock()
        file_mocked = open_mocked.return_value.__enter__.return_value
        file_mocked.read.return_value = '1995'
        nixcommon.open = open_mocked

        is_running = nixcommon.isProcessRunning(pid_file)
        assert is_running == True
        nixcommon.os.path.exists.assert_called_once_with(pid_file)
        nixcommon.open.assert_called_once_with(pid_file, 'r')
Ejemplo n.º 3
0
    def isRunning(self):
        """
        Determines if krb5kdc is running.

        """
        return nixcommon.isProcessRunning(config['Locations']['pid_file'])
Ejemplo n.º 4
0
 def isRunning(self):
     return nixcommon.isProcessRunning(config['Locations']['pid_file'])