From 7cceb80eb141244869f2ba2e6c18f146829c1778 Mon Sep 17 00:00:00 2001 From: Theo Chatzimichos Date: Feb 01 2018 16:56:02 +0000 Subject: tests: generate the ALL_LOCATION array from the valid_custom_grains.yaml --- diff --git a/bin/get_valid_custom_grains.py b/bin/get_valid_custom_grains.py new file mode 100755 index 0000000..64aedb3 --- /dev/null +++ b/bin/get_valid_custom_grains.py @@ -0,0 +1,30 @@ +#!/usr/bin/python3 + +import yaml + + +def get_valid_custom_grains(): + with open('pillar/valid_custom_grains.yaml', 'r') as f: + VALID_CUSTOM_GRAINS = yaml.load(f) + + return VALID_CUSTOM_GRAINS + + +def get_valid_global_grains(): + return get_valid_custom_grains()['global'] + + +def get_all_valid_localized_grains(): + return get_valid_custom_grains()['localized'] + + +def print_valid_localized_grains(): + results = [] + all_valid_localized_grains = get_all_valid_localized_grains() + for country, items in all_valid_localized_grains.items(): + results.append('%s,%s' % (country, ','.join(items.values()))) + print('\n'.join(results)) + + +if __name__ == "__main__": + print_valid_localized_grains() diff --git a/bin/test_custom_grains.py b/bin/test_custom_grains.py index 5e33d91..ecf0270 100755 --- a/bin/test_custom_grains.py +++ b/bin/test_custom_grains.py @@ -7,6 +7,8 @@ import os import sys from get_roles import read_file_skip_jinja +from get_valid_custom_grains import get_valid_global_grains, get_all_valid_localized_grains + def error_msg(sls, key, valid_values): if type(valid_values) == str: @@ -38,11 +40,8 @@ def test_custom_grain(mygrains, sls, key, valid_values, status): status = 0 -with open('pillar/valid_custom_grains.yaml', 'r') as f: - VALID_CUSTOM_GRAINS = yaml.load(f) - -valid_global_grains = VALID_CUSTOM_GRAINS['global'] -all_localized_grains = VALID_CUSTOM_GRAINS['localized'] +valid_global_grains = get_valid_global_grains() +all_valid_localized_grains = get_all_valid_localized_grains() all_ids = sorted(os.listdir('pillar/id')) for sls in all_ids: @@ -53,10 +52,10 @@ for sls in all_ids: status = test_custom_grain(mygrains, sls, key, valid_values, status) try: - valid_localized_grains = all_localized_grains[mygrains['country']] + valid_localized_grains = all_valid_localized_grains[mygrains['country']] for key, valid_values in valid_localized_grains.items(): status = test_custom_grain(mygrains, sls, key, valid_values, status) except KeyError: - status = error_msg(sls, 'country', all_localized_grains.keys()) + status = error_msg(sls, 'country', all_valid_localized_grains.keys()) sys.exit(status) diff --git a/bin/test_show_highstate.sh b/bin/test_show_highstate.sh index eda5396..3cfa81a 100755 --- a/bin/test_show_highstate.sh +++ b/bin/test_show_highstate.sh @@ -20,10 +20,7 @@ ALL_OS=( SLES,11,4 SLES,12,3 ) -ALL_LOCATIONS=( - de,nuremberg,atreju - us,provo,bryce -) +ALL_LOCATIONS=( $(bin/get_valid_custom_grains.py) ) write_grains() { $SUDO sed -i -e "s/\(city:\).*/\1 $2/" -e "s/\(country:\).*/\1 $1/" -e "s/\(osfullname:\).*/\1 $4/" -e "s/\(osmajorrelease:\).*/\1 $5/" \