Radosław Piliszek | 2fb8c7a | 2021-06-07 17:44:54 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # |
| 4 | # NOTE(gmann): This script is used in 'devstack-tempest-ipv6' zuul job to verify that |
| 5 | # services are deployed on IPv6 properly or not. This will capture if any devstck or devstack |
| 6 | # plugins are missing the required setting to listen on IPv6 address. This is run as part of |
| 7 | # run phase of zuul job and before test run. Child job of 'devstack-tempest-ipv6' |
| 8 | # can expand the IPv6 verification specific to project by defining the new post-run script which |
| 9 | # will run along with this base script. |
| 10 | # If there are more common verification for IPv6 then we can always extent this script. |
| 11 | |
| 12 | # Keep track of the DevStack directory |
| 13 | TOP_DIR=$(cd $(dirname "$0")/../../devstack && pwd) |
| 14 | source $TOP_DIR/stackrc |
| 15 | source $TOP_DIR/openrc admin admin |
| 16 | |
| 17 | function verify_devstack_ipv6_setting { |
| 18 | local _service_host='' |
| 19 | _service_host=$(echo $SERVICE_HOST | tr -d []) |
| 20 | local _host_ipv6='' |
| 21 | _host_ipv6=$(echo $HOST_IPV6 | tr -d []) |
| 22 | local _service_listen_address='' |
| 23 | _service_listen_address=$(echo $SERVICE_LISTEN_ADDRESS | tr -d []) |
| 24 | local _service_local_host='' |
| 25 | _service_local_host=$(echo $SERVICE_LOCAL_HOST | tr -d []) |
Brian Haley | c869d59 | 2020-02-28 14:55:08 -0500 | [diff] [blame] | 26 | local _tunnel_endpoint_ip='' |
| 27 | _tunnel_endpoint_ip=$(echo $TUNNEL_ENDPOINT_IP | tr -d []) |
Radosław Piliszek | 2fb8c7a | 2021-06-07 17:44:54 +0000 | [diff] [blame] | 28 | if [[ "$SERVICE_IP_VERSION" != 6 ]]; then |
| 29 | echo $SERVICE_IP_VERSION "SERVICE_IP_VERSION is not set to 6 which is must for devstack to deploy services with IPv6 address." |
| 30 | exit 1 |
| 31 | fi |
Brian Haley | c869d59 | 2020-02-28 14:55:08 -0500 | [diff] [blame] | 32 | if [[ "$TUNNEL_IP_VERSION" != 6 ]]; then |
| 33 | echo $TUNNEL_IP_VERSION "TUNNEL_IP_VERSION is not set to 6 so TUNNEL_ENDPOINT_IP cannot be an IPv6 address." |
| 34 | exit 1 |
| 35 | fi |
Radosław Piliszek | 2fb8c7a | 2021-06-07 17:44:54 +0000 | [diff] [blame] | 36 | is_service_host_ipv6=$(python3 -c 'import oslo_utils.netutils as nutils; print(nutils.is_valid_ipv6("'$_service_host'"))') |
| 37 | if [[ "$is_service_host_ipv6" != "True" ]]; then |
Brian Haley | c869d59 | 2020-02-28 14:55:08 -0500 | [diff] [blame] | 38 | echo $SERVICE_HOST "SERVICE_HOST is not IPv6 which means devstack cannot deploy services on IPv6 addresses." |
Radosław Piliszek | 2fb8c7a | 2021-06-07 17:44:54 +0000 | [diff] [blame] | 39 | exit 1 |
| 40 | fi |
| 41 | is_host_ipv6=$(python3 -c 'import oslo_utils.netutils as nutils; print(nutils.is_valid_ipv6("'$_host_ipv6'"))') |
| 42 | if [[ "$is_host_ipv6" != "True" ]]; then |
Brian Haley | c869d59 | 2020-02-28 14:55:08 -0500 | [diff] [blame] | 43 | echo $HOST_IPV6 "HOST_IPV6 is not IPv6 which means devstack cannot deploy services on IPv6 addresses." |
Radosław Piliszek | 2fb8c7a | 2021-06-07 17:44:54 +0000 | [diff] [blame] | 44 | exit 1 |
| 45 | fi |
| 46 | is_service_listen_address=$(python3 -c 'import oslo_utils.netutils as nutils; print(nutils.is_valid_ipv6("'$_service_listen_address'"))') |
| 47 | if [[ "$is_service_listen_address" != "True" ]]; then |
Brian Haley | c869d59 | 2020-02-28 14:55:08 -0500 | [diff] [blame] | 48 | echo $SERVICE_LISTEN_ADDRESS "SERVICE_LISTEN_ADDRESS is not IPv6 which means devstack cannot deploy services on IPv6 addresses." |
Radosław Piliszek | 2fb8c7a | 2021-06-07 17:44:54 +0000 | [diff] [blame] | 49 | exit 1 |
| 50 | fi |
| 51 | is_service_local_host=$(python3 -c 'import oslo_utils.netutils as nutils; print(nutils.is_valid_ipv6("'$_service_local_host'"))') |
| 52 | if [[ "$is_service_local_host" != "True" ]]; then |
Brian Haley | c869d59 | 2020-02-28 14:55:08 -0500 | [diff] [blame] | 53 | echo $SERVICE_LOCAL_HOST "SERVICE_LOCAL_HOST is not IPv6 which means devstack cannot deploy services on IPv6 addresses." |
| 54 | exit 1 |
| 55 | fi |
| 56 | is_tunnel_endpoint_ip=$(python3 -c 'import oslo_utils.netutils as nutils; print(nutils.is_valid_ipv6("'$_tunnel_endpoint_ip'"))') |
| 57 | if [[ "$is_tunnel_endpoint_ip" != "True" ]]; then |
| 58 | echo $TUNNEL_ENDPOINT_IP "TUNNEL_ENDPOINT_IP is not IPv6 which means devstack will not deploy with an IPv6 endpoint address." |
Radosław Piliszek | 2fb8c7a | 2021-06-07 17:44:54 +0000 | [diff] [blame] | 59 | exit 1 |
| 60 | fi |
| 61 | echo "Devstack is properly configured with IPv6" |
Brian Haley | c869d59 | 2020-02-28 14:55:08 -0500 | [diff] [blame] | 62 | echo "SERVICE_IP_VERSION:" $SERVICE_IP_VERSION "HOST_IPV6:" $HOST_IPV6 "SERVICE_HOST:" $SERVICE_HOST "SERVICE_LISTEN_ADDRESS:" $SERVICE_LISTEN_ADDRESS "SERVICE_LOCAL_HOST:" $SERVICE_LOCAL_HOST "TUNNEL_IP_VERSION:" $TUNNEL_IP_VERSION "TUNNEL_ENDPOINT_IP:" $TUNNEL_ENDPOINT_IP |
Radosław Piliszek | 2fb8c7a | 2021-06-07 17:44:54 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | function sanity_check_system_ipv6_enabled { |
| 66 | system_ipv6_enabled=$(python3 -c 'import oslo_utils.netutils as nutils; print(nutils.is_ipv6_enabled())') |
| 67 | if [[ $system_ipv6_enabled != "True" ]]; then |
| 68 | echo "IPv6 is disabled in system" |
| 69 | exit 1 |
| 70 | fi |
| 71 | echo "IPv6 is enabled in system" |
| 72 | } |
| 73 | |
| 74 | function verify_service_listen_address_is_ipv6 { |
| 75 | local endpoints_verified=False |
| 76 | local all_ipv6=True |
| 77 | endpoints=$(openstack endpoint list -f value -c URL) |
| 78 | for endpoint in ${endpoints}; do |
| 79 | local endpoint_address='' |
| 80 | endpoint_address=$(echo "$endpoint" | awk -F/ '{print $3}' | awk -F] '{print $1}') |
| 81 | endpoint_address=$(echo $endpoint_address | tr -d []) |
| 82 | local is_endpoint_ipv6='' |
| 83 | is_endpoint_ipv6=$(python3 -c 'import oslo_utils.netutils as nutils; print(nutils.is_valid_ipv6("'$endpoint_address'"))') |
| 84 | if [[ "$is_endpoint_ipv6" != "True" ]]; then |
| 85 | all_ipv6=False |
Brian Haley | c869d59 | 2020-02-28 14:55:08 -0500 | [diff] [blame] | 86 | echo $endpoint ": This is not an IPv6 endpoint which means corresponding service is not listening on an IPv6 address." |
Radosław Piliszek | 2fb8c7a | 2021-06-07 17:44:54 +0000 | [diff] [blame] | 87 | continue |
| 88 | fi |
| 89 | endpoints_verified=True |
| 90 | done |
| 91 | if [[ "$all_ipv6" == "False" ]] || [[ "$endpoints_verified" == "False" ]]; then |
| 92 | exit 1 |
| 93 | fi |
Brian Haley | c869d59 | 2020-02-28 14:55:08 -0500 | [diff] [blame] | 94 | echo "All services deployed by devstack are on IPv6 endpoints" |
Radosław Piliszek | 2fb8c7a | 2021-06-07 17:44:54 +0000 | [diff] [blame] | 95 | echo $endpoints |
| 96 | } |
| 97 | |
| 98 | #First thing to verify if system has IPv6 enabled or not |
| 99 | sanity_check_system_ipv6_enabled |
| 100 | #Verify whether devstack is configured properly with IPv6 setting |
| 101 | verify_devstack_ipv6_setting |
| 102 | #Get all registrfed endpoints by devstack in keystone and verify that each endpoints address is IPv6. |
| 103 | verify_service_listen_address_is_ipv6 |