Esempio n. 1
0
    def test_disable(self):
        """
        Test for Disable the named service to start at boot
        """
        rc_update_mock = MagicMock(return_value=0)
        with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
            self.assertTrue(gentoo_service.disable('name'))
        rc_update_mock.assert_called_once_with('rc-update delete name', python_shell=False)
        rc_update_mock.reset_mock()

        # disable service
        service_name = 'name'
        runlevels = ['l1']
        level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
            with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
                self.assertTrue(gentoo_service.disable('name', runlevels='l1'))
        rc_update_mock.assert_called_once_with('rc-update delete name l1',
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # same as above with list
        runlevels = ['l1']
        level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
            with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
                self.assertTrue(gentoo_service.disable('name', runlevels=['l1']))
        rc_update_mock.assert_called_once_with('rc-update delete name l1',
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # remove from 'l1', and leave at 'l2'
        runlevels = ['l1', 'l2']
        level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
            with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
                self.assertTrue(gentoo_service.disable('name', runlevels=['l1']))
        rc_update_mock.assert_called_once_with('rc-update delete name l1',
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # remove from non-enabled level
        runlevels = ['l2']
        level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
            with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
                self.assertTrue(gentoo_service.disable('name', runlevels=['l1']))
        rc_update_mock.assert_not_called()
        rc_update_mock.reset_mock()

        # remove from 'l1' and 'l3', leave at 'l2'
        runlevels = ['l1', 'l2', 'l3']
        level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
            with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
                self.assertTrue(gentoo_service.disable('name', runlevels=['l1', 'l3']))
        rc_update_mock.assert_called_once_with('rc-update delete name l1 l3',
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # rc-update failed
        rc_update_mock = MagicMock(return_value=1)
        with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
            self.assertFalse(gentoo_service.disable('name'))
        rc_update_mock.assert_called_once_with('rc-update delete name', python_shell=False)
        rc_update_mock.reset_mock()

        # move service delete failed
        runlevels = ['l1']
        level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
            with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
                self.assertFalse(gentoo_service.disable('name', runlevels='l1'))
        rc_update_mock.assert_called_once_with('rc-update delete name l1', python_shell=False)
        rc_update_mock.reset_mock()

        # move service delete succeeds. add fails
        runlevels = ['l1', 'l2', 'l3']
        level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
            with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
                self.assertFalse(gentoo_service.disable('name', runlevels=['l1', 'l3']))
        rc_update_mock.assert_called_once_with('rc-update delete name l1 l3',
                                               python_shell=False)
        rc_update_mock.reset_mock()
Esempio n. 2
0
    def test_disable(self):
        '''
        Test for Disable the named service to start at boot
        '''
        rc_update_mock = MagicMock(return_value=0)
        with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
            self.assertTrue(gentoo_service.disable('name'))
        rc_update_mock.assert_called_once_with('rc-update delete name',
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # disable service
        service_name = 'name'
        runlevels = ['l1']
        level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
            with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
                self.assertTrue(gentoo_service.disable('name', runlevels='l1'))
        rc_update_mock.assert_called_once_with('rc-update delete name l1',
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # same as above with list
        runlevels = ['l1']
        level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
            with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
                self.assertTrue(gentoo_service.disable('name', runlevels=['l1']))
        rc_update_mock.assert_called_once_with('rc-update delete name l1',
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # remove from 'l1', and leave at 'l2'
        runlevels = ['l1', 'l2']
        level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
            with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
                self.assertTrue(gentoo_service.disable('name', runlevels=['l1']))
        rc_update_mock.assert_called_once_with('rc-update delete name l1',
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # remove from non-enabled level
        runlevels = ['l2']
        level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
            with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
                self.assertTrue(gentoo_service.disable('name', runlevels=['l1']))
        self.assertTrue(rc_update_mock.call_count == 0)
        rc_update_mock.reset_mock()

        # remove from 'l1' and 'l3', leave at 'l2'
        runlevels = ['l1', 'l2', 'l3']
        level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
            with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
                self.assertTrue(gentoo_service.disable('name', runlevels=['l1', 'l3']))
        rc_update_mock.assert_called_once_with('rc-update delete name l1 l3',
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # rc-update failed
        rc_update_mock = MagicMock(return_value=1)
        with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
            self.assertFalse(gentoo_service.disable('name'))
        rc_update_mock.assert_called_once_with('rc-update delete name',
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # move service delete failed
        runlevels = ['l1']
        level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
            with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
                self.assertFalse(gentoo_service.disable('name', runlevels='l1'))
        rc_update_mock.assert_called_once_with('rc-update delete name l1',
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # move service delete succeeds. add fails
        runlevels = ['l1', 'l2', 'l3']
        level_list_mock = MagicMock(return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {'cmd.run': level_list_mock}):
            with patch.dict(gentoo_service.__salt__, {'cmd.retcode': rc_update_mock}):
                self.assertFalse(gentoo_service.disable('name', runlevels=['l1', 'l3']))
        rc_update_mock.assert_called_once_with('rc-update delete name l1 l3',
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()
Esempio n. 3
0
    def test_disable(self):
        """
        Test for Disable the named service to start at boot
        """
        rc_update_mock = MagicMock(return_value=0)
        with patch.dict(gentoo_service.__salt__,
                        {"cmd.retcode": rc_update_mock}):
            self.assertTrue(gentoo_service.disable("name"))
        rc_update_mock.assert_called_once_with("rc-update delete name",
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # disable service
        service_name = "name"
        runlevels = ["l1"]
        level_list_mock = MagicMock(
            return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {"cmd.run": level_list_mock}):
            with patch.dict(gentoo_service.__salt__,
                            {"cmd.retcode": rc_update_mock}):
                self.assertTrue(gentoo_service.disable("name", runlevels="l1"))
        rc_update_mock.assert_called_once_with("rc-update delete name l1",
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # same as above with list
        runlevels = ["l1"]
        level_list_mock = MagicMock(
            return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {"cmd.run": level_list_mock}):
            with patch.dict(gentoo_service.__salt__,
                            {"cmd.retcode": rc_update_mock}):
                self.assertTrue(
                    gentoo_service.disable("name", runlevels=["l1"]))
        rc_update_mock.assert_called_once_with("rc-update delete name l1",
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # remove from 'l1', and leave at 'l2'
        runlevels = ["l1", "l2"]
        level_list_mock = MagicMock(
            return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {"cmd.run": level_list_mock}):
            with patch.dict(gentoo_service.__salt__,
                            {"cmd.retcode": rc_update_mock}):
                self.assertTrue(
                    gentoo_service.disable("name", runlevels=["l1"]))
        rc_update_mock.assert_called_once_with("rc-update delete name l1",
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # remove from non-enabled level
        runlevels = ["l2"]
        level_list_mock = MagicMock(
            return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {"cmd.run": level_list_mock}):
            with patch.dict(gentoo_service.__salt__,
                            {"cmd.retcode": rc_update_mock}):
                self.assertTrue(
                    gentoo_service.disable("name", runlevels=["l1"]))
        self.assertTrue(rc_update_mock.call_count == 0)
        rc_update_mock.reset_mock()

        # remove from 'l1' and 'l3', leave at 'l2'
        runlevels = ["l1", "l2", "l3"]
        level_list_mock = MagicMock(
            return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {"cmd.run": level_list_mock}):
            with patch.dict(gentoo_service.__salt__,
                            {"cmd.retcode": rc_update_mock}):
                self.assertTrue(
                    gentoo_service.disable("name", runlevels=["l1", "l3"]))
        rc_update_mock.assert_called_once_with("rc-update delete name l1 l3",
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # rc-update failed
        rc_update_mock = MagicMock(return_value=1)
        with patch.dict(gentoo_service.__salt__,
                        {"cmd.retcode": rc_update_mock}):
            self.assertFalse(gentoo_service.disable("name"))
        rc_update_mock.assert_called_once_with("rc-update delete name",
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # move service delete failed
        runlevels = ["l1"]
        level_list_mock = MagicMock(
            return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {"cmd.run": level_list_mock}):
            with patch.dict(gentoo_service.__salt__,
                            {"cmd.retcode": rc_update_mock}):
                self.assertFalse(gentoo_service.disable("name",
                                                        runlevels="l1"))
        rc_update_mock.assert_called_once_with("rc-update delete name l1",
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # move service delete succeeds. add fails
        runlevels = ["l1", "l2", "l3"]
        level_list_mock = MagicMock(
            return_value=self.__services({service_name: runlevels}))
        with patch.dict(gentoo_service.__salt__, {"cmd.run": level_list_mock}):
            with patch.dict(gentoo_service.__salt__,
                            {"cmd.retcode": rc_update_mock}):
                self.assertFalse(
                    gentoo_service.disable("name", runlevels=["l1", "l3"]))
        rc_update_mock.assert_called_once_with("rc-update delete name l1 l3",
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()