|
| 1 | +#!/bin/bash |
| 2 | +## kola: |
| 3 | +## description: Verify that the alternatives config is properly migrated and test the migration |
| 4 | + |
| 5 | +# See |
| 6 | +# - https://github.com/coreos/fedora-coreos-tracker/issues/1818 |
| 7 | + |
| 8 | +set -xeuo pipefail |
| 9 | + |
| 10 | +# shellcheck disable=SC1091 |
| 11 | +. "$KOLA_EXT_DATA/commonlib.sh" |
| 12 | + |
| 13 | +if test -e "/var/lib/alternatives"; then |
| 14 | + ls -al "/var/lib/alternatives" |
| 15 | + fatal "Error: Found '/var/lib/alternatives' which should not exists" |
| 16 | +fi |
| 17 | +if ! test -d "/etc/alternatives"; then |
| 18 | + fatal "Error: '/etc/alternatives' is missing" |
| 19 | +fi |
| 20 | +if ! test -d "/etc/alternatives-admindir"; then |
| 21 | + fatal "Error: '/etc/alternatives-admindir' is missing" |
| 22 | +fi |
| 23 | + |
| 24 | +# To test the migration we will re-create the setup from an older FCOS node |
| 25 | + |
| 26 | +# First, reset iptables to the legacy backend |
| 27 | +alternatives --set iptables /usr/sbin/iptables-legacy |
| 28 | +if [[ $(alternatives --display iptables | grep -c "link currently points to /usr/sbin/iptables-legacy") != "1" ]]; then |
| 29 | + fatal "Could not set iptables to legacy backend for testing" |
| 30 | +fi |
| 31 | +if [[ $(iptables --version | grep -c "legacy") != "1" ]]; then |
| 32 | + fatal "Could not set iptables to legacy backend for testing" |
| 33 | +fi |
| 34 | + |
| 35 | +# Then re-create the broken alternatives folder in /var |
| 36 | +install -dm0755 /var/lib/alternatives |
| 37 | + |
| 38 | +# Do the migration |
| 39 | +/usr/libexec/coreos-alternatives-migration |
| 40 | + |
| 41 | +if [[ $(alternatives --admindir /etc/alternatives-admindir --display iptables | grep -c "link currently points to /usr/sbin/iptables-nft") != "1" ]]; then |
| 42 | + fatal "Error: migration did not set iptables to nft backend" |
| 43 | +fi |
| 44 | +if [[ $(iptables --version | grep -c "nf_tables") != "1" ]]; then |
| 45 | + fatal "Error: iptables not reset to nftables backend" |
| 46 | +fi |
| 47 | +if [[ -d "/var/lib/alternatives" ]]; then |
| 48 | + fatal "Error: /var/lib/alternatives should not exists anymore" |
| 49 | +fi |
| 50 | + |
| 51 | +# Second case, if an admin set some config up for alternatives |
| 52 | + |
| 53 | +# First, reset iptables to the legacy backend |
| 54 | +alternatives --set iptables /usr/sbin/iptables-legacy |
| 55 | +if [[ $(alternatives --display iptables | grep -c "link currently points to /usr/sbin/iptables-legacy") != "1" ]]; then |
| 56 | + fatal "Could not set iptables to legacy backend for testing" |
| 57 | +fi |
| 58 | +if [[ $(iptables --version | grep -c "legacy") != "1" ]]; then |
| 59 | + fatal "Could not set iptables to legacy backend for testing" |
| 60 | +fi |
| 61 | + |
| 62 | +# Then re-create the broken alternatives folder in /var |
| 63 | +install -dm0755 /var/lib/alternatives |
| 64 | + |
| 65 | +# And add some fake config |
| 66 | +touch /var/lib/alternatives/foo |
| 67 | + |
| 68 | +# Do the migration |
| 69 | +/usr/libexec/coreos-alternatives-migration |
| 70 | + |
| 71 | +if [[ $(alternatives --admindir /etc/alternatives-admindir --display iptables | grep -c "link currently points to /usr/sbin/iptables-nft") != "1" ]]; then |
| 72 | + fatal "Error: migration did not set iptables to nft backend" |
| 73 | +fi |
| 74 | +if [[ $(iptables --version | grep -c "nf_tables") != "1" ]]; then |
| 75 | + fatal "Error: iptables not reset to nftables backend" |
| 76 | +fi |
| 77 | +if [[ ! -d "/var/lib/alternatives" ]]; then |
| 78 | + fatal "Error: /var/lib/alternatives should still exists" |
| 79 | +fi |
0 commit comments