From b09a694b0e3955fe9cffbb64a7ca55e7d181b538 Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Dec 26 2023 12:18:12 +0000 Subject: Drop usage of virt_cluster grain We no longer need this for any of our logic, clusters are defined in hosts.yaml and can be referenced from there if needed in the future. Signed-off-by: Georg Pfuetzenreuter --- diff --git a/bin/generate_redmine_page.pl b/bin/generate_redmine_page.pl index 5ab5a2b..b059197 100755 --- a/bin/generate_redmine_page.pl +++ b/bin/generate_redmine_page.pl @@ -29,7 +29,7 @@ use Scalar::Util qw(reftype); use YAML::Tiny; my $pillar_id_path='pillar/id'; -my @wanted=qw(aliases responsible virt_cluster weburls hostusage partners description documentation); +my @wanted=qw(aliases responsible weburls hostusage partners description documentation); my $print_help=''; my $dumpforredmine=''; my $header=''; diff --git a/bin/get_valid_custom_grains.py b/bin/get_valid_custom_grains.py index 70e2ac1..1c396d8 100755 --- a/bin/get_valid_custom_grains.py +++ b/bin/get_valid_custom_grains.py @@ -21,15 +21,6 @@ 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 get_all_valid_domains(country): all_valid_domains = get_all_valid_localized_grains()[country]['domains'] if type(all_valid_domains) == str: @@ -42,44 +33,23 @@ def get_default_domain(country): print(get_all_valid_localized_grains()[country]['default_domain']) -def get_default_virt_cluster(): - results = [] - all_valid_localized_grains = get_all_valid_localized_grains() - for country, items in all_valid_localized_grains.items(): - results.append('%s,%s,%s' % (country, items['city'], items['default_virt_cluster'])) - print('\n'.join(results)) - - def print_valid_localized_grains(): results = [] all_valid_localized_grains = get_all_valid_localized_grains() for country, items in all_valid_localized_grains.items(): - if type(items['virt_cluster']) == str: - # convert to list - items['virt_cluster'] = [ items['virt_cluster'] ] - if type(items['virt_cluster']) == list: - for virt_cluster in items['virt_cluster']: - results.append('%s,%s,%s' % (country, items['city'], virt_cluster)) - else: - raise Exception('virt_cluster "%s" is not a string or a list' % items['virt_cluster']) + results.append('%s,%s' % (country, items['city'])) print('\n'.join(results)) if __name__ == "__main__": - 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.') + 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".') parser.add_argument('-d', nargs=1, help='Returns a list of the valid domains of a location.') parser.add_argument('--default-domain', nargs=1, help='Returns the default domain of a location.') - parser.add_argument('-v', action='store_true', help='Returns the valid custom grains, but only displaying once each country with their default virt_cluster.') args = parser.parse_args() - if args.p: - get_virt_cluster_only_physical() - elif args.d: + if args.d: get_all_valid_domains(args.d[0]) elif args.default_domain: get_default_domain(args.default_domain[0]) - elif args.v: - get_default_virt_cluster() else: print_valid_localized_grains() diff --git a/bin/prepare_test_env.sh b/bin/prepare_test_env.sh index 15ced64..709d7bf 100755 --- a/bin/prepare_test_env.sh +++ b/bin/prepare_test_env.sh @@ -81,7 +81,7 @@ cp "$IDFILE" "$IDFILE_BASE" if [[ -n "$HIGHSTATE" ]]; then ROLES=$(bin/get_roles.py -o yaml) [[ -n "$OS" ]] && OS_GRAINS="osfullname: ${OS[0]}\nosmajorrelease: ${OS[1]}\nosrelease_info: [${OS[1]}, ${OS[2]}]" - printf "city:\ncountry:\ndomain: $DOMAIN\ninclude_secrets: $SECRETS\n$OS_GRAINS\nvirt_cluster:\nvirtual:\n" > /etc/salt/grains + printf "city:\ncountry:\ndomain: $DOMAIN\ninclude_secrets: $SECRETS\n$OS_GRAINS\n" > /etc/salt/grains printf "$ROLES" >> "$IDFILE" if [ ! -d /etc/salt/minion.d ] diff --git a/bin/test_custom_grains.py b/bin/test_custom_grains.py index 582e1a6..182741c 100755 --- a/bin/test_custom_grains.py +++ b/bin/test_custom_grains.py @@ -56,7 +56,7 @@ for sls in all_ids: try: valid_localized_grains = all_valid_localized_grains[mygrains['country']] - for ignored_key in ['domains', 'default_domain', 'default_virt_cluster']: + for ignored_key in ['domains', 'default_domain']: valid_localized_grains.pop(ignored_key, None) for key, valid_values in valid_localized_grains.items(): status = test_custom_grain(mygrains, sls, key, valid_values, status) diff --git a/bin/test_nginx.sh b/bin/test_nginx.sh index 1dc62b7..1048c23 100755 --- a/bin/test_nginx.sh +++ b/bin/test_nginx.sh @@ -15,7 +15,7 @@ rpm -q nginx salt salt-master IDFILE="pillar/id/$(hostname).sls" IDFILE_BASE="$IDFILE.base.sls" -sed -i -e '/virtual/d' -e '/virt_cluster/d' /etc/salt/grains +sed -i -e '/virtual/d' /etc/salt/grains cp "$IDFILE" "$IDFILE_BASE" reset_nginx() { diff --git a/bin/test_show_highstate.sh b/bin/test_show_highstate.sh index ed55209..6e31ab5 100755 --- a/bin/test_show_highstate.sh +++ b/bin/test_show_highstate.sh @@ -17,19 +17,14 @@ RUN_TEST="salt-call --local --retcode-passthrough state.show_highstate" ## in case of problems feel free to temporally enable line 18 and commend out line 16. #RUN_TEST="salt-call --local --retcode-passthrough --log-level=debug state.show_highstate" -ALL_VIRTUAL=( - kvm -) -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/\(domain:\).*/\1 $5/" -e "s/\(virt_cluster:\).*/\1 $3/" -e "s/\(virtual:\).*/\1 $4/" /etc/salt/grains - echo_INFO "Grains: city: $2, country: $1, domain: $5, virt_cluster: $3, virtual: $4" + $SUDO sed -i -e "s/\(city:\).*/\1 $2/" -e "s/\(country:\).*/\1 $1/" -e "s/\(domain:\).*/\1 $5/" -e "s/\(virtual:\).*/\1 $3/" /etc/salt/grains + echo_INFO "Grains: city: $2, country: $1, domain: $5, virtual: $3" } show_highstate() { local outfile="$domain.txt" - write_grains $country $city $virt_cluster $virtual $domain + write_grains $country $city $virtual $domain $RUN_TEST > "$outfile" 2>&1 _STATUS=$? # We ignore exit code 2 as it means that an empty file is produced @@ -54,27 +49,11 @@ for location in ${ALL_LOCATIONS[@]}; do LOCATION=(${location//,/ }) country=${LOCATION[0]} city=${LOCATION[1]} - virt_cluster=${LOCATION[2]} - domain=$(bin/get_valid_custom_grains.py --default-domain $country) - for virtual in ${ALL_VIRTUAL[@]}; do - if [[ $virtual == 'kvm' ]] && [[ ${PHYSICAL_ONLY_VIRT_CLUSTER[@]} =~ $virt_cluster ]]; then - continue - fi - show_highstate - done -done - -ALL_LOCATIONS=( $(bin/get_valid_custom_grains.py -v) ) -for location in ${ALL_LOCATIONS[@]}; do - LOCATION=(${location//,/ }) - country=${LOCATION[0]} - city=${LOCATION[1]} - virt_cluster=${LOCATION[2]} default_domain=$(bin/get_valid_custom_grains.py --default-domain $country) virtual='kvm' DOMAINS=( $(bin/get_valid_custom_grains.py -d $country) ) for domain in ${DOMAINS[@]}; do - [[ $domain == $default_domain ]] || show_highstate + show_highstate done done diff --git a/pillar/id/README.md b/pillar/id/README.md index bd3c772..3f7eb1c 100644 --- a/pillar/id/README.md +++ b/pillar/id/README.md @@ -15,12 +15,6 @@ grains: roles: [] ## This corresponds to pillar/role/$role.sls and salt/role/$role.sls. ## Both files have to exist because Salt will try to include them! reboot_safe: yes ## Could anyone simply reboot the machine and everything comes back as expected? - virt_cluster: falkor ## The virtualization cluster, the machine is running on. - ## Possible values: - ## * bryce - ## * falkor - ## * orbit - ## * squanchy ## Everything below here is primarily ment for humans. aliases: [] ## Mostly used for DNS aliases at the moment. description: you name it ## A short description that gives other admins an idea about the diff --git a/pillar/valid_custom_grains.yaml b/pillar/valid_custom_grains.yaml index e619e21..3dabecd 100644 --- a/pillar/valid_custom_grains.yaml +++ b/pillar/valid_custom_grains.yaml @@ -9,34 +9,16 @@ localized: de-qsc: city: QSC-nuremberg default_domain: infra.opensuse.org - default_virt_cluster: atreju domains: infra.opensuse.org - virt_cluster: - - slimhat - - slimhat-bare - - stonehat - - stonehat-bare de: city: nuremberg default_domain: infra.opensuse.org - default_virt_cluster: atreju domains: infra.opensuse.org - virt_cluster: atreju us: city: provo default_domain: infra.opensuse.org - default_virt_cluster: bryce domains: infra.opensuse.org - virt_cluster: bryce cz: city: prague default_domain: infra.opensuse.org - default_virt_cluster: falkor domains: infra.opensuse.org - virt_cluster: - - falkor - - falkor-bare - - orbit - - orbit-bare - - squanchy - - squanchy-bare