Beispiel #1
0
 def test_delete(self):
     '''
     Test if it delete a job from the minion's schedule.
     '''
     with patch.dict(schedule.__opts__, {'schedule': {}}):
         self.assertDictEqual(schedule.delete('job1'), {
             'comment': 'Job job1 does not exist.',
             'result': False
         })
Beispiel #2
0
 def test_delete(self):
     '''
     Test if it delete a job from the minion's schedule.
     '''
     with patch.dict(schedule.__opts__, {'schedule': {}, 'sock_dir': self.sock_dir}):
         mock = MagicMock(return_value=True)
         with patch.dict(schedule.__salt__, {'event.fire': mock}):
             _ret_value = {'complete': True, 'schedule': {}}
             with patch.object(SaltEvent, 'get_event', return_value=_ret_value):
                 self.assertDictEqual(schedule.delete('job1'),
                                      {'comment': 'Job job1 does not exist.',
                                       'result': False})
Beispiel #3
0
 def test_delete(self):
     '''
     Test if it delete a job from the minion's schedule.
     '''
     with patch.dict(schedule.__opts__, {'schedule': {}, 'sock_dir': SOCK_DIR}):
         mock = MagicMock(return_value=True)
         with patch.dict(schedule.__salt__, {'event.fire': mock}):
             _ret_value = {'complete': True, 'schedule': {}}
             with patch.object(SaltEvent, 'get_event', return_value=_ret_value):
                 self.assertDictEqual(schedule.delete('job1'),
                                      {'comment': 'Job job1 does not exist.',
                                       'result': False})
Beispiel #4
0
 def test_delete(self):
     """
     Test if it delete a job from the minion's schedule.
     """
     with patch.dict(schedule.__opts__, {"schedule": {}, "sock_dir": self.sock_dir}):
         mock = MagicMock(return_value=True)
         with patch.dict(schedule.__salt__, {"event.fire": mock}):
             _ret_value = {"complete": True, "schedule": {}}
             with patch.object(SaltEvent, "get_event", return_value=_ret_value):
                 self.assertDictEqual(
                     schedule.delete("job1"),
                     {"comment": "Job job1 does not exist.", "result": False},
                 )
Beispiel #5
0
def test_delete(sock_dir, job1):
    """
    Test if it delete a job from the minion's schedule.
    """
    with patch.dict(schedule.__opts__, {"schedule": {}, "sock_dir": sock_dir}):
        mock = MagicMock(return_value=True)
        with patch.dict(schedule.__salt__, {"event.fire": mock}):
            _ret_value = {"complete": True, "schedule": {}}
            with patch.object(SaltEvent, "get_event", return_value=_ret_value):
                assert schedule.delete("job1") == {
                    "comment": "Job job1 does not exist.",
                    "changes": {},
                    "result": False,
                }

    _schedule_data = {"job1": job1}
    comm = "Deleted Job job1 from schedule."
    changes = {"job1": "removed"}
    schedule_config_file = schedule._get_schedule_config_file()
    with patch.dict(schedule.__opts__, {
            "schedule": {
                "job1": "salt"
            },
            "sock_dir": sock_dir
    }):
        with patch("salt.utils.files.fopen",
                   mock_open(read_data="")) as fopen_mock:
            with patch.object(schedule, "list_",
                              MagicMock(return_value=_schedule_data)):
                assert schedule.delete("job1", offline="True") == {
                    "comment": comm,
                    "changes": changes,
                    "result": True,
                }

                _call = call(b"schedule: {}\n")
                write_calls = fopen_mock.filehandles[schedule_config_file][
                    0].write._mock_mock_calls
                assert _call in write_calls
Beispiel #6
0
class ScheduleTestCase(TestCase, LoaderModuleMockMixin):
    """
    Test cases for salt.modules.schedule
    '''

    @classmethod
    def setUpClass(cls):
        cls.sock_dir = os.path.join(RUNTIME_VARS.TMP, 'test-socks')

    def setup_loader_modules(self):
        return {schedule: {}}

    # 'purge' function tests: 1

    @skipIf(True, "SLOWTEST skip")
    def test_purge(self):
        """
        Test if it purge all the jobs currently scheduled on the minion.
        '''
        with patch.dict(schedule.__opts__, {'schedule': {}, 'sock_dir': self.sock_dir}):
            mock = MagicMock(return_value=True)
            with patch.dict(schedule.__salt__, {"event.fire": mock}):
                _ret_value = {"complete": True, "schedule": {}}
                with patch.object(SaltEvent, "get_event", return_value=_ret_value):
                    self.assertDictEqual(
                        schedule.purge(),
                        {
                            "comment": ["Deleted job: schedule from schedule."],
                            "result": True,
                        },
                    )

    # 'delete' function tests: 1

    @skipIf(True, "SLOWTEST skip")
    def test_delete(self):
        """
        Test if it delete a job from the minion's schedule.
        '''
        with patch.dict(schedule.__opts__, {'schedule': {}, 'sock_dir': self.sock_dir}):
            mock = MagicMock(return_value=True)
            with patch.dict(schedule.__salt__, {"event.fire": mock}):
                _ret_value = {"complete": True, "schedule": {}}
                with patch.object(SaltEvent, "get_event", return_value=_ret_value):
                    self.assertDictEqual(
                        schedule.delete("job1"),
                        {"comment": "Job job1 does not exist.", "result": False},
                    )