da0de34bc1e07c6a3883178dd9da5217890450ad
[doctor.git] / tests / lib / installers / fuel
1 #!/bin/bash
2
3 if [[ "congress " == "$INSPECTOR_TYPE" ]]; then
4     die $LINENO "fuel does not support congress yet..."
5 fi
6
7 COMPUTE_USER=${COMPUTE_USER:-root}
8 ssh_opts_cpu="$ssh_opts -i instack_key"
9
10 function get_installer_ip {
11     is_set INSTALLER_IP && return
12     INSTALLER_IP=$(get_first_vnic_ip fuel-master)
13 }
14
15 function get_controller_ips {
16     is_set CONTROLLER_IPS && return
17     CONTROLLER_IPS=$(ssh $ssh_opts_cpu root@$INSTALLER_IP \
18                      "fuel node | grep controller | cut -d '|' -f 5|xargs")
19     die_if_not_set $LINENO CONTROLLER_IPS "No controller IPs"
20 }
21
22 function installer_get_ssh_keys {
23     if [[ -e instack_key ]]; then
24         echo "test existing instack_key..."
25         ssh $ssh_opts_cpu root@${INSTALLER_IP} "hostname" && return
26     fi
27     echo "getting instack_key from fuel node..."
28     sshpass -p r00tme scp $ssh_opts root@${INSTALLER_IP}:.ssh/id_rsa instack_key
29     sudo chown $(whoami):$(whoami) instack_key
30     chmod 400 instack_key
31 }
32
33 function installer_apply_patches {
34     # TODO(r-mibu): fix the followings in upstream (fuel)
35     for node in $CONTROLLER_IPS;do
36         echo "check controller configuration for doctor ($node)"
37         ssh $ssh_opts_cpu "root@$node" '
38             set -x
39             date
40             echo "### apply patches (installer=fuel)"
41
42             ep_conf=/etc/ceilometer/event_pipeline.yaml
43             entry="- notifier://?topic=alarm.all"
44             if ! grep -q -e "$entry" $ep_conf; then
45                 echo "modify the ceilometer config"
46                 echo "          $entry    # added by doctor script" >> $ep_conf
47                 service ceilometer-agent-notification restart
48             fi
49
50             # TODO(r-mibu): enable this section once congress 4.0.0 is available
51             if false; then
52             co_conf=/etc/congress/congress.conf
53             entry="congress.datasources.doctor_driver.DoctorDriver"
54             if ! grep -q -e "^drivers.*$entry" $co_conf; then
55                 echo "modify the congress config"
56                 sed -i -e "/^drivers/s/$/,$entry    # added by doctor script/" \
57                     $co_conf
58                 service congress-server restart
59             fi
60
61             rule="-m multiport -p tcp --dports 1789"
62             rule+=" -m comment --comment doctor-congress"
63             rule+=" -j ACCEPT"
64             if ! iptables -C INPUT $rule; then
65                 iptables -I INPUT $rule
66             fi
67
68             ha_conf=/etc/haproxy/conf.d/180-congress.cfg
69             if [[ ! -e $ha_conf ]]; then
70                 sed -e "1i# generated by doctor script" \
71                     -e "s/9696/1789/" \
72                     -e "s/neutron/congress/" \
73                     /etc/haproxy/conf.d/085-neutron.cfg > $ha_conf
74                 ip netns exec haproxy /usr/lib/ocf/resource.d/fuel/ns_haproxy restart
75             fi
76             fi
77             ' > installer_apply_patches_$node.log 2>&1
78     done
79 }
80
81 function setup_installer {
82     get_installer_ip
83     installer_get_ssh_keys
84     get_controller_ips
85     installer_apply_patches
86     if ! openstack flavor show $VM_FLAVOR ; then
87         openstack flavor create --ram 512 --disk 1 $VM_FLAVOR \
88             && touch created_doctor_flavor
89     fi
90 }
91
92 function get_compute_ip_from_hostname {
93     local compute_host=$1
94
95     compute_host_in_undercloud=${compute_host%%.*}
96     node_id=$(echo $compute_host_in_undercloud | cut -d "-" -f 2)
97     COMPUTE_IP=$(sshpass -p r00tme ssh 2>/dev/null $ssh_opts root@${INSTALLER_IP} \
98          "fuel node|awk -F '|' -v id=$node_id '{if (\$1 == id) print \$5}' |xargs")
99     die_if_not_set $LINENO COMPUTE_IP "Could get IP address of $compute_host."
100 }
101
102 function installer_revert_patches {
103     # TODO(r-mibu): fix the followings in upstream (fuel)
104     get_controller_ips
105     for node in $CONTROLLER_IPS;do
106         echo "restore controller configuration if touched ($node)"
107         ssh $ssh_opts_cpu "root@$node" '
108             set -x
109             echo "### revert patches (installer=fuel)"
110             date
111
112             # TODO(r-mibu): enable this section once congress 4.0.0 is available
113             if false; then
114             ha_conf=/etc/haproxy/conf.d/180-congress.cfg
115             if grep -q "# generated by doctor script" $ha_conf; then
116                 rm -f $ha_conf
117                 ip netns exec haproxy /usr/lib/ocf/resource.d/fuel/ns_haproxy restart
118             fi
119
120             rule="-m multiport -p tcp --dports 1789"
121             rule+=" -m comment --comment doctor-congress"
122             rule+=" -j ACCEPT"
123             if iptables -C INPUT $rule; then
124                 iptables -D INPUT $rule
125             fi
126
127             co_conf=/etc/congress/congress.conf
128             entry="congress.datasources.doctor_driver.DoctorDriver"
129             if grep -q -e "^drivers.*$entry    # added by doctor script" $co_conf; then
130                 echo "modify the congress config"
131                 sed -i -e "/^drivers/s/^\(.*\),$entry/\1/" $co_conf
132                 service congress-server restart
133             fi
134             fi
135
136             ep_conf=/etc/ceilometer/event_pipeline.yaml
137             if grep -q "# added by doctor script" $ep_conf; then
138                 sed -ie "/# added by doctor script/d" $ep_conf
139                 service ceilometer-agent-notification restart
140             fi
141             ' >> installer_apply_patches_$node.log 2>&1
142     done
143 }
144
145 function cleanup_installer {
146     if [[ -e created_doctor_flavor ]] && openstack flavor show $VM_FLAVOR ; then
147         openstack flavor delete $VM_FLAVOR && rm -f created_doctor_flavor
148     fi
149     installer_revert_patches
150 }