Merge "Update cloud image CentOS7 builder x86_64"
[releng/builder.git] / jjb / integration / integration-get-slave-addresses.sh
1 #!/bin/bash -l
2 # Get the Controller and Tools VM slave addresses
3
4 set -x
5
6 ODL_SYSTEM=()
7 TOOLS_SYSTEM=()
8 OPENSTACK_SYSTEM=()
9 OPENSTACK_CONTROLLERS=()
10
11 mapfile -t ADDR <<< "$(openstack stack show -f json -c outputs "$STACK_NAME" | jq -r '.outputs[] | select(.output_key | match("^vm_[0-9]+_ips$")) | .output_value | .[]')"
12
13 # The next two blocks of code will parse the list of vm IP's hostnames to determine which type of node
14 # the vm is: odl, devstack controller or compute, ha_proxy or tools. For the odl node's the hsotname will contain
15 # java in the name. The tools nodes are anything left after odl and devstack nodes have been found.
16 #
17 # The devstack nodes are identified with devstack in the hostname but require more checks to determine the controller
18 # node. Heat names the vms as devstack-<index> with index starting at 0. The vms are created in groups of which
19 # the openstack jobs create a vm_1_group for the controller and vm_2_group for the other vms such as the compute
20 # and ha_proxy nodes. The list of IP addresses for all the created vms is returned in reverse order of the group
21 # creation, but ordered within the group. I.E vm_1_group will be created first and named devstack-0, followed by
22 # vm_2_group and named devstack-0, devstack-1 and devstack-2. The list of IPs will be: devstack-0 (vm_2_group, compute),
23 # devstack-1, devstack-2, devstack-0 (vm_1_group, controller). Notice both the compute and first control node are both
24 # named devstack-0. We know the controller because it would be last in the list of IPs. This first block of code will
25 # produce two lists: one for the list of potential controllers and the second is a list of all devstack nodes.
26
27 for i in "${ADDR[@]}"
28 do
29     REMHOST=$(ssh "${i}" hostname -s)
30     case ${REMHOST} in
31     *builder*)
32        ODL_SYSTEM=( "${ODL_SYSTEM[@]}" "${i}" )
33        ;;
34     *devstack*)
35        # track potential controllers which would have -0 at the end of the hostname
36        if [[ ${REMHOST: -2} == "-0" ]]; then
37           OPENSTACK_CONTROLLERS=( "${OPENSTACK_CONTROLLERS[@]}" "${i}" )
38        fi
39
40        OPENSTACK_SYSTEM=( "${OPENSTACK_SYSTEM[@]}" "${i}" )
41        ;;
42     *)
43        TOOLS_SYSTEM=( "${TOOLS_SYSTEM[@]}" "${i}" )
44        ;;
45     esac
46 done
47
48 echo "NUM_ODL_SYSTEM=${#ODL_SYSTEM[@]}" >> slave_addresses.txt
49 echo "NUM_TOOLS_SYSTEM=${#TOOLS_SYSTEM[@]}" >> slave_addresses.txt
50 #if HA Proxy is requested the last devstack node will be configured as haproxy
51 if [ "${ENABLE_HAPROXY_FOR_NEUTRON}" == "yes" ]; then
52    # HA Proxy is installed on one OPENSTACK_SYSTEM VM on each site
53    NUM_OPENSTACK_SYSTEM=$(( ${#OPENSTACK_SYSTEM[@]} - 1 ))
54 else
55    NUM_OPENSTACK_SYSTEM=${#OPENSTACK_SYSTEM[@]}
56 fi
57 echo "NUM_OPENSTACK_SYSTEM=${NUM_OPENSTACK_SYSTEM}" >> slave_addresses.txt
58
59 # Rearrange the devstack node list to place the controller at the beginning of the list. The later code expects
60 # the list to be ordered with controller first followed by other types.
61 #
62 # At this point there is a list of potential devstack controllers as: devstack-0 (vm_2_group, compute),
63 # devstack-0 (vm_1_group, controller) and there is the full list with other compute or ha_proxy nodes in the middle.
64 # We know the controller is at the end of the devstack nodes list based on the ordering described above. Swap that entry
65 # with the first entry.
66 if [ ${#OPENSTACK_CONTROLLERS[@]} -eq 2 ]; then
67     ctrl_index=${#OPENSTACK_SYSTEM[@]}
68     ctrl_index=$((ctrl_index -1))
69     tmp_addr=${OPENSTACK_SYSTEM[0]}
70     OPENSTACK_SYSTEM[0]=${OPENSTACK_SYSTEM[$ctrl_index]}
71     OPENSTACK_SYSTEM[$ctrl_index]=$tmp_addr
72 fi
73
74 # Add alias for ODL_SYSTEM_1_IP as ODL_SYSTEM_IP
75 echo "ODL_SYSTEM_IP=${ODL_SYSTEM[0]}" >> slave_addresses.txt
76 for i in $(seq 0 $(( ${#ODL_SYSTEM[@]} - 1 )))
77 do
78     echo "ODL_SYSTEM_$((i+1))_IP=${ODL_SYSTEM[${i}]}" >> slave_addresses.txt
79 done
80
81 # Add alias for TOOLS_SYSTEM_1_IP as TOOLS_SYSTEM_IP
82 echo "TOOLS_SYSTEM_IP=${TOOLS_SYSTEM[0]}" >> slave_addresses.txt
83 for i in $(seq 0 $(( ${#TOOLS_SYSTEM[@]} - 1 )))
84 do
85     echo "TOOLS_SYSTEM_$((i+1))_IP=${TOOLS_SYSTEM[${i}]}" >> slave_addresses.txt
86 done
87
88 openstack_index=0
89 # Assuming number of openstack control nodes equals number of openstack sites
90 NUM_OPENSTACK_CONTROL_NODES=1
91 echo "NUM_OPENSTACK_CONTROL_NODES=${NUM_OPENSTACK_CONTROL_NODES}" >> slave_addresses.txt
92 for i in $(seq 0 $((NUM_OPENSTACK_CONTROL_NODES - 1)))
93 do
94     echo "OPENSTACK_CONTROL_NODE_$((i+1))_IP=${OPENSTACK_SYSTEM[$((openstack_index++))]}" >> slave_addresses.txt
95 done
96
97 # The rest of the openstack nodes until NUM_OPENSTACK_SYSTEM are computes
98 NUM_OPENSTACK_COMPUTE_NODES=$(( NUM_OPENSTACK_SYSTEM - NUM_OPENSTACK_CONTROL_NODES ))
99 echo "NUM_OPENSTACK_COMPUTE_NODES=${NUM_OPENSTACK_COMPUTE_NODES}" >> slave_addresses.txt
100
101 # Order the computes in the list so that the devstack-0 is index 1 and devstack-1 is index 2. Currently they are
102 # backwards because of the controller swap earlier.
103 if [ ${NUM_OPENSTACK_COMPUTE_NODES} -ge 2 ]; then
104     tmp_addr=${OPENSTACK_SYSTEM[1]}
105     OPENSTACK_SYSTEM[1]=${OPENSTACK_SYSTEM[2]}
106     OPENSTACK_SYSTEM[2]=${tmp_addr}
107 fi
108
109 for i in $(seq 0 $((NUM_OPENSTACK_COMPUTE_NODES - 1)))
110 do
111     echo "OPENSTACK_COMPUTE_NODE_$((i+1))_IP=${OPENSTACK_SYSTEM[$((openstack_index++))]}" >> slave_addresses.txt
112 done
113
114 # The remaining openstack nodes are haproxy nodes (for ODL cluster)
115 NUM_OPENSTACK_HAPROXY_NODES=$(( ${#OPENSTACK_SYSTEM[@]} - NUM_OPENSTACK_SYSTEM ))
116 echo "NUM_OPENSTACK_HAPROXY_NODES=${NUM_OPENSTACK_HAPROXY_NODES}" >> slave_addresses.txt
117 for i in $(seq 0 $((NUM_OPENSTACK_HAPROXY_NODES - 1)))
118 do
119     echo "OPENSTACK_HAPROXY_$((i+1))_IP=${OPENSTACK_SYSTEM[$((openstack_index++))]}" >> slave_addresses.txt
120 done
121 echo "Contents of slave_addresses.txt:"
122 cat slave_addresses.txt
123 # vim: sw=4 ts=4 sts=4 et ft=sh :