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