Refactor installers support code
[doctor.git] / tests / lib / installers / fuel
1 #!/bin/bash
2
3 function get_installer_ip {
4     local instack_mac=$(sudo virsh domiflist fuel-opnfv | awk '/pxebr/{print $5}')
5     INSTALLER_IP=$(/usr/sbin/arp -e | grep ${instack_mac} | awk '{print $1}')
6     die_if_not_set $LINENO $INSTALLER_IP "No installer IP"
7 }
8
9 function installer_get_ssh_keys {
10     sshpass -p r00tme scp $ssh_opts root@${INSTALLER_IP}:.ssh/id_rsa instack_key
11     sudo chown $(whoami):$(whoami) instack_key
12     chmod 400 instack_key
13     ssh_opts_cpu+=" -i instack_key"
14 }
15
16 function installer_apply_patches {
17     cat > set_conf.sh << 'END_TXT'
18 #!/bin/bash
19 if [ -e /etc/ceilometer/event_pipeline.yaml ]; then
20     if ! grep -q '^ *- notifier://?topic=alarm.all$' /etc/ceilometer/event_pipeline.yaml; then
21         sed -i 's|- notifier://|- notifier://?topic=alarm.all|' /etc/ceilometer/event_pipeline.yaml
22         echo "modify the ceilometer config"
23         service ceilometer-agent-notification restart
24     fi
25 else
26     echo "ceilometer event_pipeline.yaml file does not exist"
27     exit 1
28 fi
29 if [ -e /etc/nova/nova.conf ]; then
30     if ! grep -q '^notification_driver=messaging$' /etc/nova/nova.conf; then
31         sed -i -r 's/notification_driver=/notification_driver=messaging/g' /etc/nova/nova.conf
32         echo "modify nova config"
33         service nova-api restart
34     fi
35 else
36     echo "nova.conf file does not exist"
37     exit 1
38 fi
39 exit 0
40 END_TXT
41
42     chmod +x set_conf.sh
43     CONTROLLER_IP=$(sshpass -p r00tme ssh 2>/dev/null $ssh_opts root@${INSTALLER_IP} \
44          "fuel node | grep controller | cut -d '|' -f 5|xargs")
45     for node in $CONTROLLER_IP;do
46         scp $ssh_opts_cpu set_conf.sh "root@$node:"
47         ssh $ssh_opts_cpu "root@$node" './set_conf.sh > set_conf.log 2>&1 &'
48         sleep 1
49         scp $ssh_opts_cpu "root@$node:set_conf.log" set_conf_$node.log
50     done
51
52     if grep -q "modify the ceilometer config" set_conf_*.log ; then
53         NEED_TO_RESTORE_CEILOMETER=true
54     fi
55     if grep -q "modify nova config" set_conf_*.log ; then
56         NEED_TO_RESTORE_NOVA=true
57     fi
58
59     echo "waiting service restart..."
60     sleep 60
61
62 }
63
64 function cleanup_installer_fuel {
65    if ! ($NEED_TO_RESTORE_CEILOMETER || $NEED_TO_RESTORE_NOVA) ; then
66        echo "Don't need to restore config"
67        exit 0
68    fi
69
70    echo "restore the configuration..."
71    cat > restore_conf.sh << 'END_TXT'
72 #!/bin/bash
73 if @NEED_TO_RESTORE_CEILOMETER@ ; then
74     if [ -e /etc/ceilometer/event_pipeline.yaml ]; then
75         if grep -q '^ *- notifier://?topic=alarm.all$' /etc/ceilometer/event_pipeline.yaml; then
76             sed -i 's|- notifier://?topic=alarm.all|- notifier://|' /etc/ceilometer/event_pipeline.yaml
77             service ceilometer-agent-notification restart
78         fi
79     else
80         echo "ceilometer event_pipeline.yaml file does not exist"
81         exit 1
82     fi
83 fi
84 if @NEED_TO_RESTORE_NOVA@ ; then
85     if [ -e /etc/nova/nova.conf ]; then
86         if grep -q '^notification_driver=messaging$' /etc/nova/nova.conf; then
87             sed -i -r 's/notification_driver=messaging/notification_driver=/g' /etc/nova/nova.conf
88             service nova-api restart
89         fi
90     else
91         echo "nova.conf file does not exist"
92         exit 1
93     fi
94 fi
95 exit 0
96 END_TXT
97    sed -i -e "s/@NEED_TO_RESTORE_CEILOMETER@/$NEED_TO_RESTORE_CEILOMETER/" restore_conf.sh
98    sed -i -e "s/@NEED_TO_RESTORE_NOVA@/$NEED_TO_RESTORE_NOVA/" restore_conf.sh
99    chmod +x restore_conf.sh
100    for node in $CONTROLLER_IP;do
101        scp $ssh_opts_cpu restore_conf.sh "root@$node:"
102        ssh $ssh_opts_cpu "root@$node" './restore_conf.sh > restore_conf.log 2>&1 &'
103    done
104
105    echo "waiting service restart..."
106    sleep 60
107 }