def _check_cron(user, cmd, minute=None, hour=None, daymonth=None, month=None, dayweek=None): ''' Return the changes ''' if minute is not None: minute = str(minute).lower() if hour is not None: hour = str(hour).lower() if daymonth is not None: daymonth = str(daymonth).lower() if month is not None: month = str(month).lower() if dayweek is not None: dayweek = str(dayweek).lower() lst = __salt__['cron.list_tab'](user) for cron in lst['crons']: if cmd == cron['cmd']: if any([ _needs_change(x, y) for x, y in ((cron['minute'], minute), (cron['hour'], hour), (cron['daymonth'], daymonth), (cron['month'], month), (cron['dayweek'], dayweek)) ]): return 'update' return 'present' return 'absent'
def _check_cron(user, cmd, minute=None, hour=None, daymonth=None, month=None, dayweek=None, comment=None, identifier=None): ''' Return the changes ''' if minute is not None: minute = str(minute).lower() if hour is not None: hour = str(hour).lower() if daymonth is not None: daymonth = str(daymonth).lower() if month is not None: month = str(month).lower() if dayweek is not None: dayweek = str(dayweek).lower() lst = __salt__['cron.list_tab'](user) for cron in lst['crons']: if _cron_matched(cron, cmd, identifier): if any([_needs_change(x, y) for x, y in ((cron['minute'], minute), (cron['hour'], hour), (cron['daymonth'], daymonth), (cron['month'], month), (cron['dayweek'], dayweek), (cron['comment'], comment))]): return 'update' return 'present' return 'absent'
def _check_cron(user, cmd, minute=None, hour=None, daymonth=None, month=None, dayweek=None, comment=None, commented=None, identifier=None, special=None): ''' Return the changes ''' if minute is not None: minute = str(minute).lower() if hour is not None: hour = str(hour).lower() if daymonth is not None: daymonth = str(daymonth).lower() if month is not None: month = str(month).lower() if dayweek is not None: dayweek = str(dayweek).lower() if identifier is not None: identifier = str(identifier) if commented is not None: commented = commented is True if cmd is not None: cmd = str(cmd) lst = __salt__['cron.list_tab'](user) if special is None: for cron in lst['crons']: if _cron_matched(cron, cmd, identifier): if any([ _needs_change(x, y) for x, y in ((cron['minute'], minute), (cron['hour'], hour), (cron['daymonth'], daymonth), (cron['month'], month), (cron['dayweek'], dayweek), (cron['identifier'], identifier), (cron['cmd'], cmd), (cron['comment'], comment), (cron['commented'], commented)) ]): return 'update' return 'present' else: for cron in lst['special']: if special == cron['spec'] and cmd == cron['cmd']: return 'present' return 'absent'
def _check_cron( user, cmd, minute=None, hour=None, daymonth=None, month=None, dayweek=None, comment=None, commented=None, identifier=None, ): """ Return the changes """ if minute is not None: minute = str(minute).lower() if hour is not None: hour = str(hour).lower() if daymonth is not None: daymonth = str(daymonth).lower() if month is not None: month = str(month).lower() if dayweek is not None: dayweek = str(dayweek).lower() if identifier is not None: identifier = str(identifier) if commented is not None: commented = commented is True if cmd is not None: cmd = str(cmd) lst = __salt__["cron.list_tab"](user) for cron in lst["crons"]: if _cron_matched(cron, cmd, identifier): if any( [ _needs_change(x, y) for x, y in ( (cron["minute"], minute), (cron["hour"], hour), (cron["daymonth"], daymonth), (cron["month"], month), (cron["dayweek"], dayweek), (cron["identifier"], identifier), (cron["cmd"], cmd), (cron["comment"], comment), (cron["commented"], commented), ) ] ): return "update" return "present" return "absent"
def test__needs_change_random(self): ''' Assert that if the new var is 'random' and old is '* that we return True ''' self.assertTrue(cron._needs_change('*', 'random'))
def test__needs_change(self): self.assertTrue(cron._needs_change(True, False))
def _check_cron( user, cmd, minute=None, hour=None, daymonth=None, month=None, dayweek=None, comment=None, commented=None, identifier=None, special=None, ): """ Return the changes """ if minute is not None: minute = six.text_type(minute).lower() if hour is not None: hour = six.text_type(hour).lower() if daymonth is not None: daymonth = six.text_type(daymonth).lower() if month is not None: month = six.text_type(month).lower() if dayweek is not None: dayweek = six.text_type(dayweek).lower() if identifier is not None: identifier = six.text_type(identifier) if commented is not None: commented = commented is True if cmd is not None: cmd = six.text_type(cmd) lst = __salt__["cron.list_tab"](user) if special is None: for cron in lst["crons"]: if _cron_matched(cron, cmd, identifier): if any([ _needs_change(x, y) for x, y in ( (cron["minute"], minute), (cron["hour"], hour), (cron["daymonth"], daymonth), (cron["month"], month), (cron["dayweek"], dayweek), (cron["identifier"], identifier), (cron["cmd"], cmd), (cron["comment"], comment), (cron["commented"], commented), ) ]): return "update" return "present" else: for cron in lst["special"]: if _cron_matched(cron, cmd, identifier): if any([ _needs_change(x, y) for x, y in ( (cron["spec"], special), (cron["identifier"], identifier), (cron["cmd"], cmd), (cron["comment"], comment), (cron["commented"], commented), ) ]): return "update" return "present" return "absent"