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