Last active
August 29, 2015 14:23
-
-
Save jpic/51e1545aff67d5f451e3 to your computer and use it in GitHub Desktop.
SaltStack state TDD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!py | |
# Named groups.py for github syntax coloration, but works as groups.sls | |
def update_groups(available, active): | |
for group, params in available.iteritems(): | |
name = params.get('name', group) | |
f = 'absent' if group not in active else 'present' | |
args = {} | |
if f == 'present' and 'gid' in params: | |
args = [{'gid': params['gid']}] | |
elif f == 'absent': | |
args = [{'purge': True}] | |
calls = {'group.%s' % f: args} | |
yield name, calls | |
def run(): | |
available = __salt__['pillar.get']('available_groups', {}) | |
active = __salt__['pillar.get']('active_groups', []) | |
config = {} | |
for name, calls in update_groups(available, active): | |
config[name] = calls | |
return config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import imp | |
groups = imp.load_source('groups', os.path.join(os.path.dirname(__file__), 'groups.sls')) | |
def test_update_groups(): | |
available = dict(present_group=dict(gid=1), absent_group=dict(gid=2)) | |
active = ['present_group'] | |
expected = { | |
'present_group': {'group.present': [{'gid': 1}]}, | |
'absent_group': {'group.absent': [{'purge': True}]} | |
} | |
results = {k: v for k, v in groups.update_groups(available, active)} | |
assert results == expected |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment