|
3 | 3 |
|
4 | 4 | {%- set cron = salt['pillar.get']('cron', {}) %}
|
5 | 5 |
|
6 |
| -{%- if 'tasks' in cron %} |
7 |
| -{%- for task, task_options in cron.tasks.items() %} |
| 6 | +{%- for task, task_options in cron.get('tasks', {}).items() %} |
| 7 | +{%- set cron_type = task_options.type|d('present') %} |
8 | 8 |
|
9 |
| -{%- if task_options.type == 'absent' %} |
10 |
| -validate_cron.{{ task }}_absent: |
| 9 | +validate_cron.{{ task }}_{{ cron_type }}: |
11 | 10 | module_and_function: cron.get_entry
|
12 | 11 | args:
|
13 | 12 | - {{ task_options.user|d('root') }}
|
14 | 13 | - {{ task }}
|
| 14 | + {%- if cron_type == 'absent' %} |
15 | 15 | assertion: assertFalse
|
| 16 | + {%- else %} |
| 17 | + assertion: assertEqual |
| 18 | + assertion_section: identifier |
| 19 | + expected-return: {{ task }} |
| 20 | + {%- endif %} |
16 | 21 |
|
17 |
| -{%- elif task_options.type == 'present' %} |
18 |
| -validate_cron.{{ task }}_exists: |
| 22 | +{%- if cron_type == 'present' %} |
| 23 | +validate_cron.{{ task }}_commented: |
19 | 24 | module_and_function: cron.get_entry
|
20 | 25 | args:
|
21 | 26 | - {{ task_options.user|d('root') }}
|
22 | 27 | - {{ task }}
|
23 |
| - assertion: assertEqual |
24 |
| - assertion_section: identifier |
25 |
| - expected-return: {{ task }} |
| 28 | + assertion: {{ 'assertTrue' if task_options.commented|d(False) else 'assertFalse' }} |
| 29 | + assertion_section: commented |
26 | 30 |
|
27 | 31 | {#- Note: `special` is `spec` in the module #}
|
28 |
| -{%- for section in ['minute', 'hour', 'daymonth', 'month', 'dayweek', 'comment', 'spec'] %} |
29 |
| -{%- if section in task_options %} |
30 |
| -{%- set assertion = 'assertEqual' %} |
31 |
| -{%- set expected = task_options.get(section) %} |
32 |
| -{%- if expected == 'random' %} |
33 |
| -{%- set assertion = 'assertLessEqual' %} |
34 |
| -{%- set expected = 0 %} |
35 |
| -{%- endif %} |
| 32 | +{%- for section in ['minute', 'hour', 'daymonth', 'month', 'dayweek', 'comment', 'spec'] %} |
| 33 | +{%- if section in task_options %} |
| 34 | +{%- set expected = task_options[section] %} |
36 | 35 | validate_cron.{{ task }}_{{ section }}:
|
37 | 36 | module_and_function: cron.get_entry
|
38 | 37 | args:
|
39 | 38 | - {{ task_options.user|d('root') }}
|
40 | 39 | - {{ task }}
|
41 |
| - assertion: {{ assertion }} |
| 40 | + assertion: {{ 'assertLessEqual' if expected == 'random' else 'assertEqual' }} |
42 | 41 | assertion_section: {{ section }}
|
43 |
| - expected-return: '{{ expected }}' |
44 |
| -{%- endif %} |
45 |
| -{%- endfor %} |
46 |
| - |
47 |
| -{%- set assertion = 'assertFalse' %} |
48 |
| -{%- if task_options.commented|d(False) %} |
49 |
| -{%- set assertion = 'assertTrue' %} |
| 42 | + expected-return: '{{ 0 if expected == 'random' else expected }}' |
50 | 43 | {%- endif %}
|
51 |
| -validate_cron.{{ task }}_commented: |
52 |
| - module_and_function: cron.get_entry |
53 |
| - args: |
54 |
| - - {{ task_options.user|d('root') }} |
55 |
| - - {{ task }} |
56 |
| - assertion: {{ assertion }} |
57 |
| - assertion_section: commented |
58 |
| -{%- endif %} |
| 44 | +{%- endfor %} |
| 45 | +{%- endif %} |
59 | 46 |
|
60 |
| -{%- endfor %} |
61 |
| -{%- endif %} |
| 47 | +{%- endfor %} |
0 commit comments