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