Пример #1
0
    def test_status(self):
        """
        Test for Return the status for a service
        """
        mock = MagicMock(return_value=True)
        with patch.dict(gentoo_service.__salt__, {'status.pid': mock}):
            self.assertTrue(gentoo_service.status('name', 1))

        # service is running
        mock = MagicMock(return_value=0)
        with patch.dict(gentoo_service.__salt__, {'cmd.retcode': mock}):
            self.assertTrue(gentoo_service.status('name'))
        mock.assert_called_once_with('/etc/init.d/name status',
                                     python_shell=False)

        # service is not running
        mock = MagicMock(return_value=1)
        with patch.dict(gentoo_service.__salt__, {'cmd.retcode': mock}):
            self.assertFalse(gentoo_service.status('name'))
        mock.assert_called_once_with('/etc/init.d/name status',
                                     python_shell=False)

        # service is stopped
        mock = MagicMock(return_value=3)
        with patch.dict(gentoo_service.__salt__, {'cmd.retcode': mock}):
            self.assertFalse(gentoo_service.status('name'))
        mock.assert_called_once_with('/etc/init.d/name status',
                                     python_shell=False)

        # service has crashed
        mock = MagicMock(return_value=32)
        with patch.dict(gentoo_service.__salt__, {'cmd.retcode': mock}):
            self.assertFalse(gentoo_service.status('name'))
        mock.assert_called_once_with('/etc/init.d/name status',
                                     python_shell=False)
Пример #2
0
    def test_status(self):
        """
        Test for Return the status for a service
        """
        mock = MagicMock(return_value=True)
        with patch.dict(gentoo_service.__salt__, {'status.pid': mock}):
            self.assertTrue(gentoo_service.status('name', 1))

        # service is running
        mock = MagicMock(return_value=0)
        with patch.dict(gentoo_service.__salt__, {'cmd.retcode': mock}):
            self.assertTrue(gentoo_service.status('name'))
        mock.assert_called_once_with('/etc/init.d/name status', python_shell=False)

        # service is not running
        mock = MagicMock(return_value=1)
        with patch.dict(gentoo_service.__salt__, {'cmd.retcode': mock}):
            self.assertFalse(gentoo_service.status('name'))
        mock.assert_called_once_with('/etc/init.d/name status', python_shell=False)

        # service is stopped
        mock = MagicMock(return_value=3)
        with patch.dict(gentoo_service.__salt__, {'cmd.retcode': mock}):
            self.assertFalse(gentoo_service.status('name'))
        mock.assert_called_once_with('/etc/init.d/name status', python_shell=False)

        # service has crashed
        mock = MagicMock(return_value=32)
        with patch.dict(gentoo_service.__salt__, {'cmd.retcode': mock}):
            self.assertFalse(gentoo_service.status('name'))
        mock.assert_called_once_with('/etc/init.d/name status', python_shell=False)