当前位置: 首页>>代码示例>>Python>>正文


Python Schedule.delete_job方法代码示例

本文整理汇总了Python中salt.utils.schedule.Schedule.delete_job方法的典型用法代码示例。如果您正苦于以下问题:Python Schedule.delete_job方法的具体用法?Python Schedule.delete_job怎么用?Python Schedule.delete_job使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在salt.utils.schedule.Schedule的用法示例。


在下文中一共展示了Schedule.delete_job方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ScheduleTestCase

# 需要导入模块: from salt.utils.schedule import Schedule [as 别名]
# 或者: from salt.utils.schedule.Schedule import delete_job [as 别名]
class ScheduleTestCase(TestCase):
    '''
    Unit tests for salt.utils.schedule module
    '''

    def setUp(self):
        with patch('salt.utils.schedule.clean_proc_dir', MagicMock(return_value=None)):
            self.schedule = Schedule({}, {}, returners={})

    # delete_job tests

    def test_delete_job_exists(self):
        '''
        Tests ensuring the job exists and deleting it
        '''
        self.schedule.opts = {'schedule': {'foo': 'bar'}, 'pillar': '',
                              'sock_dir': SOCK_DIR}
        self.schedule.delete_job('foo')
        self.assertNotIn('foo', self.schedule.opts)

    def test_delete_job_in_pillar(self):
        '''
        Tests deleting job in pillar
        '''
        self.schedule.opts = {'pillar': {'schedule': {'foo': 'bar'}}, 'schedule': '',
                              'sock_dir': SOCK_DIR}
        self.schedule.delete_job('foo')
        self.assertNotIn('foo', self.schedule.opts)

    def test_delete_job_intervals(self):
        '''
        Tests removing job from intervals
        '''
        self.schedule.opts = {'pillar': '', 'schedule': '',
                              'sock_dir': SOCK_DIR}
        self.schedule.intervals = {'foo': 'bar'}
        self.schedule.delete_job('foo')
        self.assertNotIn('foo', self.schedule.intervals)

    # add_job tests

    def test_add_job_data_not_dict(self):
        '''
        Tests if data is a dictionary
        '''
        data = 'foo'
        self.assertRaises(ValueError, Schedule.add_job, self.schedule, data)

    def test_add_job_multiple_jobs(self):
        '''
        Tests if more than one job is scheduled at a time
        '''
        data = {'key1': 'value1', 'key2': 'value2'}
        self.assertRaises(ValueError, Schedule.add_job, self.schedule, data)

    def test_add_job(self):
        '''
        Tests adding a job to the schedule
        '''
        data = {'foo': {'bar': 'baz'}}
        ret = {'schedule': {'foo': {'bar': 'baz', 'enabled': True},
                            'hello': {'world': 'peace', 'enabled': True}}}
        self.schedule.opts = {'schedule': {'hello': {'world': 'peace', 'enabled': True}},
                              'sock_dir': SOCK_DIR}
        Schedule.add_job(self.schedule, data)
        del self.schedule.opts['sock_dir']
        self.assertEqual(self.schedule.opts, ret)

    # enable_job tests

    def test_enable_job(self):
        '''
        Tests enabling a job
        '''
        self.schedule.opts = {'schedule': {'name': {'enabled': 'foo'}},
                              'sock_dir': SOCK_DIR}
        Schedule.enable_job(self.schedule, 'name')
        del self.schedule.opts['sock_dir']
        self.assertTrue(self.schedule.opts['schedule']['name']['enabled'])

    def test_enable_job_pillar(self):
        '''
        Tests enabling a job in pillar
        '''
        self.schedule.opts = {'pillar': {'schedule': {'name': {'enabled': 'foo'}}},
                              'sock_dir': SOCK_DIR}
        Schedule.enable_job(self.schedule, 'name', persist=False, where='pillar')
        del self.schedule.opts['sock_dir']
        self.assertTrue(self.schedule.opts['pillar']['schedule']['name']['enabled'])

    # disable_job tests

    def test_disable_job(self):
        '''
        Tests disabling a job
        '''
        self.schedule.opts = {'schedule': {'name': {'enabled': 'foo'}},
                              'sock_dir': SOCK_DIR}
        Schedule.disable_job(self.schedule, 'name')
        del self.schedule.opts['sock_dir']
#.........这里部分代码省略.........
开发者ID:HowardMei,项目名称:saltstack,代码行数:103,代码来源:schedule_test.py


注:本文中的salt.utils.schedule.Schedule.delete_job方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。