Beispiel #1
0
    def test_stop(self):
        '''
            Test to stop the specified service
        '''
        mock_true = MagicMock(return_value=True)
        mock_false = MagicMock(return_value=False)
        mock_info = MagicMock(side_effect=[{'Status': 'Stopped'}])

        with patch.object(win32serviceutil, 'StopService', mock_true), \
                patch.object(win_service, '_status_wait', mock_info):
            self.assertTrue(win_service.stop('spongebob'))

        mock_info = MagicMock(side_effect=[{
            'Status': 'Running',
            'Status_WaitHint': 0
        }, {
            'Status': 'Stop Pending',
            'Status_WaitHint': 0
        }, {
            'Status': 'Stopped'
        }])

        with patch.object(win32serviceutil, 'StopService', mock_true), \
                patch.object(win_service, 'info', mock_info), \
                patch.object(win_service, 'status', mock_false):
            self.assertTrue(win_service.stop('spongebob'))
Beispiel #2
0
    def test_stop(self):
        """
            Test to stop the specified service
        """
        mock_true = MagicMock(return_value=True)
        mock_false = MagicMock(return_value=False)
        mock_info = MagicMock(side_effect=[{"Status": "Stopped"}])

        with patch.object(win32serviceutil, "StopService",
                          mock_true), patch.object(win_service, "_status_wait",
                                                   mock_info):
            self.assertTrue(win_service.stop("spongebob"))

        mock_info = MagicMock(side_effect=[
            {
                "Status": "Running",
                "Status_WaitHint": 0
            },
            {
                "Status": "Stop Pending",
                "Status_WaitHint": 0
            },
            {
                "Status": "Stopped"
            },
        ])

        with patch.object(win32serviceutil, "StopService",
                          mock_true), patch.object(win_service, "info",
                                                   mock_info), patch.object(
                                                       win_service, "status",
                                                       mock_false):
            self.assertTrue(win_service.stop("spongebob"))
Beispiel #3
0
    def test_stop(self):
        '''
            Test to stop the specified service
        '''
        win_service.SERVICE_STOP_POLL_MAX_ATTEMPTS = 1
        win_service.SERVICE_STOP_DELAY_SECONDS = 1
        mock = MagicMock(
            side_effect=[['service was stopped'], ["salt"], ["salt"]])
        with patch.dict(win_service.__salt__, {'cmd.run': mock}):
            self.assertTrue(win_service.stop("salt"))

            mock = MagicMock(side_effect=[False, True])
            with patch.object(win_service, 'status', mock):
                self.assertTrue(win_service.stop("salt"))

                self.assertFalse(win_service.stop("salt"))
Beispiel #4
0
    def test_stop(self):
        '''
            Test to stop the specified service
        '''
        win_service.SERVICE_STOP_POLL_MAX_ATTEMPTS = 1
        win_service.SERVICE_STOP_DELAY_SECONDS = 1
        mock = MagicMock(side_effect=[['service was stopped'], ["salt"],
                                      ["salt"]])
        with patch.dict(win_service.__salt__, {'cmd.run': mock}):
            self.assertTrue(win_service.stop("salt"))

            mock = MagicMock(side_effect=[False, True])
            with patch.object(win_service, 'status', mock):
                self.assertTrue(win_service.stop("salt"))

                self.assertFalse(win_service.stop("salt"))
Beispiel #5
0
    def test_stop(self):
        '''
            Test to stop the specified service
        '''
        mock_true = MagicMock(return_value=True)
        mock_false = MagicMock(return_value=False)
        mock_info = MagicMock(side_effect=[{'Status': 'Running'},
                                           {'Status': 'Stop Pending'},
                                           {'Status': 'Stopped'}])

        with patch.dict(win_service.__salt__, {'cmd.run': MagicMock(return_value="service was stopped")}):
            self.assertTrue(win_service.stop('spongebob'))

        with patch.dict(win_service.__salt__, {'cmd.run': MagicMock(return_value="service was stopped")}), \
                patch.object(win32serviceutil, 'StopService', mock_true), \
                patch.object(win_service, 'info', mock_info), \
                patch.object(win_service, 'status', mock_false):
            self.assertTrue(win_service.stop('spongebob'))
Beispiel #6
0
    def test_stop(self):
        '''
            Test to stop the specified service
        '''
        mock_true = MagicMock(return_value=True)
        mock_false = MagicMock(return_value=False)
        mock_info = MagicMock(side_effect=[{'Status': 'Running'},
                                           {'Status': 'Stop Pending'},
                                           {'Status': 'Stopped'}])

        with patch.object(win_service, 'status', mock_false):
            self.assertTrue(win_service.stop('spongebob'))

        with patch.object(win_service, 'status', mock_true):
            with patch.object(win32serviceutil, 'StopService', mock_true):
                with patch.object(win_service, 'info', mock_info):
                    with patch.object(win_service, 'status', mock_false):
                        self.assertTrue(win_service.stop('spongebob'))
Beispiel #7
0
 def test_stop_not_running(self):
     '''
     Test stopping a service that is already stopped
     '''
     mock_error = MagicMock(side_effect=pywintypes.error(
         1062, 'StopService', 'Service is not running'))
     mock_info = MagicMock(side_effect=[{'Status': 'Stopped'}])
     with patch.object(win32serviceutil, 'StopService', mock_error), \
             patch.object(win_service, '_status_wait', mock_info):
         self.assertTrue(win_service.stop('spongebob'))
Beispiel #8
0
 def test_stop_not_running(self):
     """
     Test stopping a service that is already stopped
     """
     mock_error = MagicMock(side_effect=pywintypes.error(
         1062, "StopService", "Service is not running"))
     mock_info = MagicMock(side_effect=[{"Status": "Stopped"}])
     with patch.object(win32serviceutil, "StopService",
                       mock_error), patch.object(win_service,
                                                 "_status_wait", mock_info):
         self.assertTrue(win_service.stop("spongebob"))