55878decb74ea252fd94c504f672602bef064c0c
[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 instack)
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_entry="congress.datasources.doctor_driver.DoctorDriver"
48             if sudo grep -e "^drivers.*$co_entry" $co_conf; then
49                 echo "NOTE: congress is configured as we needed"
50             else
51                 echo "modify the congress config"
52                 sudo sed -i -e "/^drivers/s/$/,$co_entry    # added by doctor script/" \
53                     $co_conf
54                 sudo systemctl restart openstack-congress-server.service
55             fi
56             ' > installer_apply_patches_$node.log 2>&1
57     done
58 }
59
60 function setup_installer {
61     get_installer_ip
62     installer_get_ssh_keys
63     get_controller_ips
64     installer_apply_patches
65
66     # NOTE: while executing command as doctor user,
67     #       'OS_PROJECT_ID' env parameter make openstack clients confused.
68     unset OS_PROJECT_ID
69 }
70
71 function get_compute_ip_from_hostname {
72     local compute_host=$1
73
74     compute_host_in_undercloud=${compute_host%%.*}
75     COMPUTE_IP=$(sudo ssh $ssh_opts $INSTALLER_IP \
76                  "source stackrc;
77                   nova show $compute_host_in_undercloud  | \
78                   awk '/ ctlplane network /{print \$5}'")
79     die_if_not_set $LINENO COMPUTE_IP "Could get IP address of $compute_host."
80 }
81
82 function installer_revert_patches {
83     # TODO(r-mibu): fix the followings in upstream (apex)
84     get_controller_ips
85     for node in $CONTROLLER_IPS;do
86         echo "restore controller configuration if touched ($node)"
87         ssh $ssh_opts_cpu "heat-admin@$node" '
88             set -x
89             echo "### revert patches (installer=apex)"
90             date
91
92             co_conf=/etc/congress/congress.conf
93             co_entry="congress.datasources.doctor_driver.DoctorDriver"
94             if sudo grep -q -e "# added by doctor script" $co_conf; then
95                 echo "modify the congress config"
96                 sudo sed -i -e "/^drivers/s/^\(.*\),$co_entry    # added by doctor script/\1/" $co_conf
97                 sudo systemctl restart openstack-congress-server.service
98             fi
99
100             ep_conf=/etc/ceilometer/event_pipeline.yaml
101             if sudo grep -q -e "# added by doctor script" $ep_conf; then
102                 echo "modify the ceilometer config"
103                 sudo sed -ie "/# added by doctor script/d" $ep_conf
104                 sudo systemctl restart openstack-ceilometer-notification.service
105             fi
106             ' >> installer_apply_patches_$node.log 2>&1
107     done
108 }
109
110 function cleanup_installer {
111     installer_revert_patches
112     return
113 }