Skip to content

Commit

Permalink
refactor(config): minimise and standardise between .sls & .tst
Browse files Browse the repository at this point in the history
  • Loading branch information
myii committed Oct 23, 2019
1 parent cce5e67 commit 18585bd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 98 deletions.
28 changes: 13 additions & 15 deletions cron/config/file.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@
{%- set tplroot = tpldir.split('/')[0] %}
{%- from tplroot ~ "/map.jinja" import cron with context %}
{%- if 'tasks' in cron %}
{%- for task, task_options in cron.tasks.items() %}
{%- for task, task_options in cron.get('tasks', {}).items() %}
{%- set cron_type = task_options.type|d('present') %}
cron.{{ task }}:
cron.{{ task_options.type|d('present') }}:
cron.{{ cron_type }}:
- name: {{ task_options.name }}
- identifier: '{{ task }}'
{%- if 'user' in task_options %}
- user: {{ task_options.user|d('root') }}
- identifier: '{{ task }}'
{%- if cron_type == 'present' %}
- commented: {{ task_options.commented|d(False) }}
{%- for section in ['minute', 'hour', 'daymonth', 'month', 'dayweek', 'comment', 'special'] %}
{%- if section in task_options %}
- {{ section }}: '{{ task_options[section] }}'
{%- endif %}
{%- endfor %}
{%- endif %}
{%- for section in ['minute', 'hour', 'daymonth', 'month', 'dayweek', 'comment', 'special'] %}
{%- if section in task_options %}
- {{ section }}: '{{ task_options.get(section) }}'
{%- endif %}
{%- endfor %}
{%- if task_options.commented|d(False) %}
- commented: True
{%- endif %}
{%- endfor %}
{%- endif %}
{%- endfor %}
58 changes: 22 additions & 36 deletions cron/saltcheck-tests/config.tst
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,45 @@

{%- set cron = salt['pillar.get']('cron', {}) %}

{%- if 'tasks' in cron %}
{%- for task, task_options in cron.tasks.items() %}
{%- for task, task_options in cron.get('tasks', {}).items() %}
{%- set cron_type = task_options.type|d('present') %}

{%- if task_options.type == 'absent' %}
validate_cron.{{ task }}_absent:
validate_cron.{{ task }}_{{ cron_type }}:
module_and_function: cron.get_entry
args:
- {{ task_options.user|d('root') }}
- {{ task }}
{%- if cron_type == 'absent' %}
assertion: assertFalse

{%- elif task_options.type == 'present' %}
validate_cron.{{ task }}_exists:
module_and_function: cron.get_entry
args:
- {{ task_options.user|d('root') }}
- {{ task }}
{%- else %}
assertion: assertEqual
assertion_section: identifier
expected-return: {{ task }}
{%- endif %}

{#- Note: `special` is `spec` in the module #}
{%- for section in ['minute', 'hour', 'daymonth', 'month', 'dayweek', 'comment', 'spec'] %}
{%- if section in task_options %}
{%- set assertion = 'assertEqual' %}
{%- set expected = task_options.get(section) %}
{%- if expected == 'random' %}
{%- set assertion = 'assertLessEqual' %}
{%- set expected = 0 %}
{%- endif %}
validate_cron.{{ task }}_{{ section }}:
{%- if cron_type == 'present' %}
validate_cron.{{ task }}_commented:
module_and_function: cron.get_entry
args:
- {{ task_options.user|d('root') }}
- {{ task }}
assertion: {{ assertion }}
assertion_section: {{ section }}
expected-return: '{{ expected }}'
{%- endif %}
{%- endfor %}
assertion: {{ 'assertTrue' if task_options.commented|d(False) else 'assertFalse' }}
assertion_section: commented

{%- set assertion = 'assertFalse' %}
{%- if task_options.commented|d(False) %}
{%- set assertion = 'assertTrue' %}
{%- endif %}
validate_cron.{{ task }}_commented:
{#- Note: `special` is `spec` in the module #}
{%- for section in ['minute', 'hour', 'daymonth', 'month', 'dayweek', 'comment', 'spec'] %}
{%- if section in task_options %}
{%- set expected = task_options[section] %}
validate_cron.{{ task }}_{{ section }}:
module_and_function: cron.get_entry
args:
- {{ task_options.user|d('root') }}
- {{ task }}
assertion: {{ assertion }}
assertion_section: commented
{%- endif %}
assertion: {{ 'assertLessEqual' if expected == 'random' else 'assertEqual' }}
assertion_section: {{ section }}
expected-return: '{{ 0 if expected == 'random' else expected }}'
{%- endif %}
{%- endfor %}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- endfor %}
47 changes: 0 additions & 47 deletions cron/saltcheck-tests/map.jinja

This file was deleted.

0 comments on commit 18585bd

Please sign in to comment.