aa384d
#!/usr/bin/python3
aa384d
Theo Chatzimichos e8dbf6
# Various roles related tests:
Theo Chatzimichos e8dbf6
# - Checks if the declared {salt,pillar}/role/*.sls files actually match an
Theo Chatzimichos e8dbf6
#   assigned role to a minion
Theo Chatzimichos e8dbf6
# - Checks if the assigned roles to minions have equivalent
Theo Chatzimichos e8dbf6
#   {salt,pillar}/role/*.sls files
Theo Chatzimichos 2883e0
# - Checks that the special roles are not included in any pillar/id/*.sls
aa384d
aa384d
import os
aa384d
import sys
Theo Chatzimichos 4f2316
from get_roles import get_roles, get_roles_of_one_minion
aa384d
b49512
status = 0
Theo Chatzimichos eb3a47
special_roles = ['base']
Theo Chatzimichos 2883e0
roles = get_roles(append=special_roles)
aa384d
aa384d
for directory in ['salt', 'pillar']:
aa384d
    for sls in os.listdir('%s/role' % directory):
aa384d
        if sls.endswith('.sls'):
Theo Chatzimichos f1d227
            if sls.split('.sls')[0] not in roles:
Theo Chatzimichos f1d227
                print('%s/role/%s not in roles' % (directory, sls))
Theo Chatzimichos f1d227
                status = 1
aa384d
Theo Chatzimichos 043122
for role in roles:
Theo Chatzimichos 043122
    if not os.path.isfile('salt/role/%s.sls' % role):
Theo Chatzimichos 2883e0
        print('%s role is missing the salt/role/%s.sls file' % (role, role))
Theo Chatzimichos 043122
        status = 1
Theo Chatzimichos 043122
Theo Chatzimichos 2883e0
roles = get_roles()
Theo Chatzimichos 2883e0
Theo Chatzimichos 2883e0
for special_role in special_roles:
Theo Chatzimichos 2883e0
    if special_role in roles:
Theo Chatzimichos 2883e0
        for sls in os.listdir('pillar/id/'):
Theo Chatzimichos 4f2316
            _roles = get_roles_of_one_minion(sls)
Theo Chatzimichos 2883e0
            if special_role in _roles:
Theo Chatzimichos 2883e0
                print('%s role should not be included in pillar/id/%s file' % (special_role, sls))
Theo Chatzimichos 2883e0
                status = 1
Theo Chatzimichos 2883e0
aa384d
sys.exit(status)