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