From 18791d04c057d87fc1baa42975ea8b3e049e8750 Mon Sep 17 00:00:00 2001 From: Theo Chatzimichos Date: Aug 03 2018 22:38:21 +0000 Subject: test_show_highstate: exclude the non salt-managed VMs In the internal SUSE testsuite there are hypervisors and virtualization clusters managed by salt, that don't have any salt-managed VMs. There is no need to run show_highstate and delay the results for zero benefit, thus excluding them from the show_highstate tests --- diff --git a/bin/get_valid_custom_grains.py b/bin/get_valid_custom_grains.py index d83b160..e71995a 100755 --- a/bin/get_valid_custom_grains.py +++ b/bin/get_valid_custom_grains.py @@ -1,5 +1,8 @@ #!/usr/bin/python3 +# For description and usage, see the argparse options at the end of the file + +import argparse import yaml @@ -18,6 +21,15 @@ def get_all_valid_localized_grains(): return get_valid_custom_grains()['localized'] +def get_virt_cluster_only_physical(): + virt_cluster_only_physical = '' + try: + virt_cluster_only_physical = get_valid_custom_grains()['virt_cluster_only_physical'] + except KeyError: + pass + print('\n'.join(virt_cluster_only_physical)) + + def print_valid_localized_grains(): results = [] all_valid_localized_grains = get_all_valid_localized_grains() @@ -34,4 +46,11 @@ def print_valid_localized_grains(): if __name__ == "__main__": - print_valid_localized_grains() + parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, description='Loads the pillar/valid_custom_grains.py and returns a list of valid custom grains in the form of "country,city,virt_cluster".') + parser.add_argument('-p', action='store_true', help='Returns a list of physical machines that do not host any salt-managed VMs.') + args = parser.parse_args() + + if args.p: + get_virt_cluster_only_physical() + else: + print_valid_localized_grains() diff --git a/bin/test_show_highstate.sh b/bin/test_show_highstate.sh index 5229606..1551dc2 100755 --- a/bin/test_show_highstate.sh +++ b/bin/test_show_highstate.sh @@ -18,6 +18,7 @@ ALL_VIRTUAL=( kvm ) ALL_LOCATIONS=( $(bin/get_valid_custom_grains.py) ) +PHYSICAL_ONLY_VIRT_CLUSTER=( $(bin/get_valid_custom_grains.py -p) ) write_grains() { $SUDO sed -i -e "s/\(city:\).*/\1 $2/" -e "s/\(country:\).*/\1 $1/" -e "s/\(virt_cluster:\).*/\1 $3/" -e "s/\(virtual:\).*/\1 $4/" /etc/salt/grains @@ -26,6 +27,9 @@ write_grains() { for location in ${ALL_LOCATIONS[@]}; do for virtual in ${ALL_VIRTUAL[@]}; do + if [[ $virtual == 'kvm' ]] && [[ ${PHYSICAL_ONLY_VIRT_CLUSTER[@]} =~ ${location##*,} ]]; then + continue + fi write_grains ${location//,/ } ${virtual} $RUN_TEST > /dev/null _STATUS=$(echo $?)