示例#1
0
    def test_enable(self):
        """
        Test for Enable 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.enable('name'))
        rc_update_mock.assert_called_once_with('rc-update add name', python_shell=False)
        rc_update_mock.reset_mock()

        # move service from 'l1' to 'l2' runlevel
        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.enable('name', runlevels='l2'))
        rc_update_mock.assert_has_calls([call('rc-update delete name l1', python_shell=False),
                                         call('rc-update add name l2', python_shell=False)])
        rc_update_mock.reset_mock()

        # requested levels are the same as the current ones
        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.enable('name', runlevels='l1'))
        rc_update_mock.assert_not_called()
        rc_update_mock.reset_mock()

        # same as above with the list instead of the string
        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.enable('name', runlevels=['l1']))
        rc_update_mock.assert_not_called()
        rc_update_mock.reset_mock()

        # add service to 'l2' runlevel
        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.enable('name', runlevels=['l2', 'l1']))
        rc_update_mock.assert_called_once_with('rc-update add name l2', python_shell=False)
        rc_update_mock.reset_mock()

        # remove service from 'l1' runlevel
        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.enable('name', runlevels=['l2']))
        rc_update_mock.assert_called_once_with('rc-update delete name l1', python_shell=False)
        rc_update_mock.reset_mock()

        # move service from 'l2' add to 'l3', leaving at l1
        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.enable('name', runlevels=['l1', 'l3']))
        rc_update_mock.assert_has_calls([call('rc-update delete name l2', python_shell=False),
                                         call('rc-update add name l3', python_shell=False)])
        rc_update_mock.reset_mock()

        # remove from l1, l3, and add to l2, l4, and leave at l5
        runlevels = ['l1', 'l3', 'l5']
        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.enable('name', runlevels=['l2', 'l4', 'l5']))
        rc_update_mock.assert_has_calls([call('rc-update delete name l1 l3', python_shell=False),
                                         call('rc-update add name l2 l4', 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.enable('name'))
        rc_update_mock.assert_called_once_with('rc-update add 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.enable('name', runlevels='l2'))
        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
        rc_update_mock = MagicMock()
        rc_update_mock.side_effect = [0, 1]
        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.enable('name', runlevels='l2'))
        rc_update_mock.assert_has_calls([call('rc-update delete name l1', python_shell=False),
                                         call('rc-update add name l2', python_shell=False)])
        rc_update_mock.reset_mock()
示例#2
0
    def test_enable(self):
        '''
        Test for Enable 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.enable('name'))
        rc_update_mock.assert_called_once_with('rc-update add name',
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # move service from 'l1' to 'l2' runlevel
        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.enable('name', runlevels='l2'))
        rc_update_mock.assert_has_calls([call('rc-update delete name l1',
                                              ignore_retcode=False,
                                              python_shell=False),
                                         call('rc-update add name l2',
                                              ignore_retcode=False,
                                              python_shell=False)])
        rc_update_mock.reset_mock()

        # requested levels are the same as the current ones
        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.enable('name', runlevels='l1'))
        self.assertTrue(rc_update_mock.call_count == 0)
        rc_update_mock.reset_mock()

        # same as above with the list instead of the string
        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.enable('name', runlevels=['l1']))
        self.assertTrue(rc_update_mock.call_count == 0)
        rc_update_mock.reset_mock()

        # add service to 'l2' runlevel
        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.enable('name', runlevels=['l2', 'l1']))
        rc_update_mock.assert_called_once_with('rc-update add name l2',
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # remove service from 'l1' runlevel
        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.enable('name', runlevels=['l2']))
        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 from 'l2' add to 'l3', leaving at l1
        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.enable('name', runlevels=['l1', 'l3']))
        rc_update_mock.assert_has_calls([call('rc-update delete name l2',
                                              ignore_retcode=False,
                                              python_shell=False),
                                         call('rc-update add name l3',
                                              ignore_retcode=False,
                                              python_shell=False)])
        rc_update_mock.reset_mock()

        # remove from l1, l3, and add to l2, l4, and leave at l5
        runlevels = ['l1', 'l3', 'l5']
        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.enable('name', runlevels=['l2', 'l4', 'l5']))
        rc_update_mock.assert_has_calls([call('rc-update delete name l1 l3',
                                              ignore_retcode=False,
                                              python_shell=False),
                                         call('rc-update add name l2 l4',
                                              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.enable('name'))
        rc_update_mock.assert_called_once_with('rc-update add 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.enable('name', runlevels='l2'))
        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
        rc_update_mock = MagicMock()
        rc_update_mock.side_effect = [0, 1]
        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.enable('name', runlevels='l2'))
        rc_update_mock.assert_has_calls([call('rc-update delete name l1',
                                              ignore_retcode=False,
                                              python_shell=False),
                                         call('rc-update add name l2',
                                              ignore_retcode=False,
                                              python_shell=False)])
        rc_update_mock.reset_mock()
示例#3
0
    def test_enable(self):
        """
        Test for Enable 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.enable("name"))
        rc_update_mock.assert_called_once_with("rc-update add name",
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # move service from 'l1' to 'l2' runlevel
        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.enable("name", runlevels="l2"))
        rc_update_mock.assert_has_calls([
            call("rc-update delete name l1",
                 ignore_retcode=False,
                 python_shell=False),
            call("rc-update add name l2",
                 ignore_retcode=False,
                 python_shell=False),
        ])
        rc_update_mock.reset_mock()

        # requested levels are the same as the current ones
        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.enable("name", runlevels="l1"))
        self.assertTrue(rc_update_mock.call_count == 0)
        rc_update_mock.reset_mock()

        # same as above with the list instead of the string
        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.enable("name",
                                                      runlevels=["l1"]))
        self.assertTrue(rc_update_mock.call_count == 0)
        rc_update_mock.reset_mock()

        # add service to 'l2' runlevel
        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.enable("name", runlevels=["l2", "l1"]))
        rc_update_mock.assert_called_once_with("rc-update add name l2",
                                               ignore_retcode=False,
                                               python_shell=False)
        rc_update_mock.reset_mock()

        # remove service from 'l1' runlevel
        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.enable("name",
                                                      runlevels=["l2"]))
        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 from 'l2' add to 'l3', leaving at l1
        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.enable("name", runlevels=["l1", "l3"]))
        rc_update_mock.assert_has_calls([
            call("rc-update delete name l2",
                 ignore_retcode=False,
                 python_shell=False),
            call("rc-update add name l3",
                 ignore_retcode=False,
                 python_shell=False),
        ])
        rc_update_mock.reset_mock()

        # remove from l1, l3, and add to l2, l4, and leave at l5
        runlevels = ["l1", "l3", "l5"]
        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.enable("name", runlevels=["l2", "l4",
                                                             "l5"]))
        rc_update_mock.assert_has_calls([
            call(
                "rc-update delete name l1 l3",
                ignore_retcode=False,
                python_shell=False,
            ),
            call("rc-update add name l2 l4",
                 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.enable("name"))
        rc_update_mock.assert_called_once_with("rc-update add 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.enable("name", runlevels="l2"))
        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
        rc_update_mock = MagicMock()
        rc_update_mock.side_effect = [0, 1]
        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.enable("name", runlevels="l2"))
        rc_update_mock.assert_has_calls([
            call("rc-update delete name l1",
                 ignore_retcode=False,
                 python_shell=False),
            call("rc-update add name l2",
                 ignore_retcode=False,
                 python_shell=False),
        ])
        rc_update_mock.reset_mock()