fix the bug: congress server can't be started
[doctor.git] / tests / lib / installers / apex
1 #!/bin/bash
2
3 COMPUTE_USER=${COMPUTE_USER:-heat-admin}
4 ssh_opts_cpu="$ssh_opts -i instack_key"
5
6 function get_installer_ip {
7     is_set INSTALLER_IP && return
8     INSTALLER_IP=$(get_first_vnic_ip undercloud)
9 }
10
11 function installer_get_ssh_keys {
12     sudo scp $ssh_opts "root@$INSTALLER_IP:/home/stack/.ssh/id_rsa" instack_key
13     sudo chown $(whoami):$(whoami) instack_key
14     chmod 400 instack_key
15 }
16
17 function get_controller_ips {
18     is_set CONTROLLER_IPS && return
19     get_installer_ip
20     CONTROLLER_IPS=$(sudo ssh $ssh_opts $INSTALLER_IP \
21                      "source stackrc
22                       nova list | grep ' overcloud-controller-[0-9] ' | \
23                       sed -e 's/^.*ctlplane=//' -e 's/ *|\$//'")
24     die_if_not_set $LINENO CONTROLLER_IPS "No controller IPs"
25 }
26
27 function installer_apply_patches {
28     # TODO(r-mibu): fix the followings in upstream (apex)
29     for node in $CONTROLLER_IPS;do
30         echo "check controller configuration for doctor ($node)"
31         ssh $ssh_opts_cpu "heat-admin@$node" '
32             set -x
33             date
34             echo "### apply patches (installer=apex)"
35
36             ep_conf=/etc/ceilometer/event_pipeline.yaml
37             ep_entry="- notifier://?topic=alarm.all"
38             if sudo grep -e "$ep_entry" $ep_conf; then
39                 echo "NOTE: ceilometer is configured as we needed"
40             else
41                 echo "modify the ceilometer config"
42                 sudo sed -i -e "$ a \ \ \ \ \ \ \ \ \ \ $ep_entry    # added by doctor script" $ep_conf
43                 sudo systemctl restart openstack-ceilometer-notification.service
44             fi
45
46             co_conf=/etc/congress/congress.conf
47             co_conf_bak=/etc/congress/congress.conf.bak
48             co_entry="congress.datasources.doctor_driver.DoctorDriver"
49             if sudo grep -e "^drivers.*$co_entry" $co_conf; then
50                 echo "NOTE: congress is configured as we needed"
51             else
52                 echo "modify the congress config"
53                 sudo cp $co_conf $co_conf_bak
54                 sudo sed -i -e "/^drivers/s/$/,$co_entry/"  $co_conf
55                 sudo systemctl restart openstack-congress-server.service
56             fi
57             ' > installer_apply_patches_$node.log 2>&1
58     done
59 }
60
61 function setup_installer {
62     get_installer_ip
63     installer_get_ssh_keys
64     get_controller_ips
65     installer_apply_patches
66
67     # NOTE: while executing command as doctor user,
68     #       'OS_PROJECT_ID' env parameter make openstack clients confused.
69     unset OS_PROJECT_ID
70 }
71
72 function get_compute_ip_from_hostname {
73     local compute_host=$1
74
75     compute_host_in_undercloud=${compute_host%%.*}
76     COMPUTE_IP=$(sudo ssh $ssh_opts $INSTALLER_IP \
77                  "source stackrc;
78                   nova show $compute_host_in_undercloud  | \
79                   awk '/ ctlplane network /{print \$5}'")
80     die_if_not_set $LINENO COMPUTE_IP "Could get IP address of $compute_host."
81 }
82
83 function installer_revert_patches {
84     # TODO(r-mibu): fix the followings in upstream (apex)
85     get_controller_ips
86     for node in $CONTROLLER_IPS;do
87         echo "restore controller configuration if touched ($node)"
88         ssh $ssh_opts_cpu "heat-admin@$node" '
89             set -x
90             echo "### revert patches (installer=apex)"
91             date
92
93             co_conf=/etc/congress/congress.conf
94             co_conf_bak=/etc/congress/congress.conf.bak
95             if [ -e $co_conf_bak ]; then
96                 echo "restore the congress config"
97                 sudo mv $co_conf_bak $co_conf
98                 sudo systemctl restart openstack-congress-server.service
99             fi
100
101             ep_conf=/etc/ceilometer/event_pipeline.yaml
102             if sudo grep -q -e "# added by doctor script" $ep_conf; then
103                 echo "modify the ceilometer config"
104                 sudo sed -ie "/# added by doctor script/d" $ep_conf
105                 sudo systemctl restart openstack-ceilometer-notification.service
106             fi
107             ' >> installer_apply_patches_$node.log 2>&1
108     done
109 }
110
111 function cleanup_installer {
112     installer_revert_patches
113     return
114 }