Ghanshyam | a0b8ca4 | 2019-07-17 09:46:41 +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 { |
Masayuki Igawa | fdd9644 | 2019-08-02 13:44:49 +0900 | [diff] [blame] | 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 []) |
Ghanshyam | a0b8ca4 | 2019-07-17 09:46:41 +0000 | [diff] [blame] | 26 | if [[ "$SERVICE_IP_VERSION" != 6 ]]; then |
| 27 | echo $SERVICE_IP_VERSION "SERVICE_IP_VERSION is not set to 6 which is must for devstack to deploy services with IPv6 address." |
| 28 | exit 1 |
| 29 | fi |
| 30 | is_service_host_ipv6=$(python3 -c 'import oslo_utils.netutils as nutils; print(nutils.is_valid_ipv6("'$_service_host'"))') |
| 31 | if [[ "$is_service_host_ipv6" != "True" ]]; then |
| 32 | echo $SERVICE_HOST "SERVICE_HOST is not ipv6 which means devstack cannot deploy services on IPv6 address." |
| 33 | exit 1 |
| 34 | fi |
| 35 | is_host_ipv6=$(python3 -c 'import oslo_utils.netutils as nutils; print(nutils.is_valid_ipv6("'$_host_ipv6'"))') |
| 36 | if [[ "$is_host_ipv6" != "True" ]]; then |
| 37 | echo $HOST_IPV6 "HOST_IPV6 is not ipv6 which means devstack cannot deploy services on IPv6 address." |
| 38 | exit 1 |
| 39 | fi |
| 40 | is_service_listen_address=$(python3 -c 'import oslo_utils.netutils as nutils; print(nutils.is_valid_ipv6("'$_service_listen_address'"))') |
| 41 | if [[ "$is_service_listen_address" != "True" ]]; then |
| 42 | echo $SERVICE_LISTEN_ADDRESS "SERVICE_LISTEN_ADDRESS is not ipv6 which means devstack cannot deploy services on IPv6 address." |
| 43 | exit 1 |
| 44 | fi |
| 45 | is_service_local_host=$(python3 -c 'import oslo_utils.netutils as nutils; print(nutils.is_valid_ipv6("'$_service_local_host'"))') |
| 46 | if [[ "$is_service_local_host" != "True" ]]; then |
| 47 | echo $SERVICE_LOCAL_HOST "SERVICE_LOCAL_HOST is not ipv6 which means devstack cannot deploy services on IPv6 address." |
| 48 | exit 1 |
| 49 | fi |
| 50 | echo "Devstack is properly configured with IPv6" |
| 51 | 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 |
| 52 | } |
| 53 | |
| 54 | function sanity_check_system_ipv6_enabled { |
| 55 | system_ipv6_enabled=$(python3 -c 'import oslo_utils.netutils as nutils; print(nutils.is_ipv6_enabled())') |
| 56 | if [[ $system_ipv6_enabled != "True" ]]; then |
| 57 | echo "IPv6 is disabled in system" |
| 58 | exit 1 |
| 59 | fi |
| 60 | echo "IPv6 is enabled in system" |
| 61 | } |
| 62 | |
| 63 | function verify_service_listen_address_is_ipv6 { |
| 64 | local endpoints_verified=False |
| 65 | local all_ipv6=True |
| 66 | endpoints=$(openstack endpoint list -f value -c URL) |
| 67 | for endpoint in ${endpoints}; do |
Masayuki Igawa | fdd9644 | 2019-08-02 13:44:49 +0900 | [diff] [blame] | 68 | local endpoint_address='' |
| 69 | endpoint_address=$(echo "$endpoint" | awk -F/ '{print $3}' | awk -F] '{print $1}') |
Ghanshyam | a0b8ca4 | 2019-07-17 09:46:41 +0000 | [diff] [blame] | 70 | endpoint_address=$(echo $endpoint_address | tr -d []) |
Masayuki Igawa | fdd9644 | 2019-08-02 13:44:49 +0900 | [diff] [blame] | 71 | local is_endpoint_ipv6='' |
| 72 | is_endpoint_ipv6=$(python3 -c 'import oslo_utils.netutils as nutils; print(nutils.is_valid_ipv6("'$endpoint_address'"))') |
Ghanshyam | a0b8ca4 | 2019-07-17 09:46:41 +0000 | [diff] [blame] | 73 | if [[ "$is_endpoint_ipv6" != "True" ]]; then |
| 74 | all_ipv6=False |
| 75 | echo $endpoint ": This is not ipv6 endpoint which means corresponding service is not listening on IPv6 address." |
| 76 | continue |
| 77 | fi |
| 78 | endpoints_verified=True |
| 79 | done |
| 80 | if [[ "$all_ipv6" == "False" ]] || [[ "$endpoints_verified" == "False" ]]; then |
| 81 | exit 1 |
| 82 | fi |
| 83 | echo "All services deployed by devstack is on IPv6 endpoints" |
| 84 | echo $endpoints |
| 85 | } |
| 86 | |
| 87 | #First thing to verify if system has IPv6 enabled or not |
| 88 | sanity_check_system_ipv6_enabled |
| 89 | #Verify whether devstack is configured properly with IPv6 setting |
| 90 | verify_devstack_ipv6_setting |
| 91 | #Get all registrfed endpoints by devstack in keystone and verify that each endpoints address is IPv6. |
| 92 | verify_service_listen_address_is_ipv6 |