Exemple #1
0
 def test_enable(self):
     mock = MagicMock(return_value=0)
     with patch.dict(debian_service.__salt__, {"cmd.retcode": mock}):
         # Test successful command (0 retcode)
         assert debian_service.enable("foo")
         # Confirm expected command was run
         mock.assert_called_once_with(
             "insserv foo && update-rc.d foo enable", python_shell=True)
         # Test unsuccessful command (nonzero retcode)
         mock.return_value = 1
         assert not debian_service.enable("foo")
Exemple #2
0
    def test_status(self):
        mock = MagicMock(return_value="123")
        with patch.dict(debian_service.__salt__, {"status.pid": mock}):
            assert debian_service.status("foo", "foobar")

        mock = MagicMock(return_value=0)
        with patch.dict(debian_service.__salt__, {"cmd.retcode": mock}):
            # Test successful command (0 retcode)
            assert debian_service.status("foo")
            # Confirm expected command was run
            mock.assert_called_once_with("service foo status",
                                         ignore_retcode=True)
            # Test unsuccessful command (nonzero retcode)
            mock.return_value = 1
            assert not debian_service.enable("foo")

        mock = MagicMock(
            side_effect=lambda x, **y: 0 if x == "service bar status" else 1)
        get_all = MagicMock(return_value=["foo", "bar", "baz"])
        with patch.dict(debian_service.__salt__,
                        {"cmd.retcode": mock}), patch.object(
                            debian_service, "get_all", get_all):
            ret = debian_service.status("b*")
            expected = {"bar": True, "baz": False}
            assert ret == expected, ret
Exemple #3
0
 def test_enable(self):
     '''
     Test for Enable the named service to start at boot
     '''
     mock = MagicMock(return_value='5')
     with patch.object(debian_service, '_osrel', mock):
         mock = MagicMock(return_value='')
         with patch.object(debian_service, '_cmd_quote', mock):
             mock = MagicMock(return_value=True)
             with patch.dict(debian_service.__salt__,
                             {'cmd.retcode': mock}):
                 self.assertFalse(debian_service.enable('name'))
 def test_enable(self):
     """
     Test for Enable the named service to start at boot
     """
     mock = MagicMock(return_value="5")
     with patch.object(debian_service, "_osrel", mock):
         mock = MagicMock(return_value="")
         with patch.object(debian_service, "_cmd_quote", mock):
             mock = MagicMock(return_value=True)
             with patch.dict(debian_service.__salt__,
                             {"cmd.retcode": mock}):
                 self.assertFalse(debian_service.enable("name"))
Exemple #5
0
 def test_enable(self):
     '''
     Test for Enable the named service to start at boot
     '''
     mock = MagicMock(return_value='5')
     with patch.object(debian_service, '_osrel', mock):
         mock = MagicMock(return_value='')
         with patch.object(debian_service, '_cmd_quote', mock):
             mock = MagicMock(return_value=True)
             with patch.dict(debian_service.__salt__,
                             {'cmd.retcode': mock}):
                 self.assertFalse(debian_service.enable('name'))