summaryrefslogtreecommitdiffstats
path: root/tests/lib/installers/fuel
blob: 0c56963ca997efb4e24f8c71135082a0e8305d3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/bin/bash

if [[ "congress " == "$INSPECTOR_TYPE" ]]; then
    die $LINENO "fuel does not support congress yet..."
fi

COMPUTE_USER=${COMPUTE_USER:-root}
ssh_opts_cpu="$ssh_opts -i instack_key"

function get_installer_ip {
    is_set INSTALLER_IP && return
    INSTALLER_IP=$(get_first_vnic_ip fuel-master)
}

function get_controller_ips {
    is_set CONTROLLER_IPS && return
    CONTROLLER_IPS=$(ssh $ssh_opts_cpu root@$INSTALLER_IP \
                     "fuel node | grep controller | cut -d '|' -f 5|xargs")
    die_if_not_set $LINENO CONTROLLER_IPS "No controller IPs"
}

function installer_get_ssh_keys {
    if [[ -e instack_key ]]; then
        echo "test existing instack_key..."
        ssh $ssh_opts_cpu root@${INSTALLER_IP} "hostname" && return
    fi
    echo "getting instack_key from fuel node..."
    sshpass -p r00tme scp $ssh_opts root@${INSTALLER_IP}:.ssh/id_rsa instack_key
    sudo chown $(whoami):$(whoami) instack_key
    chmod 400 instack_key
}

function installer_apply_patches {
    # TODO(r-mibu): fix the followings in upstream (fuel)
    for node in $CONTROLLER_IPS;do
        echo "check controller configuration for doctor ($node)"
        ssh $ssh_opts_cpu "root@$node" '
            set -x
            date
            echo "### apply patches (installer=fuel)"

            ep_conf=/etc/ceilometer/event_pipeline.yaml
            entry="- notifier://?topic=alarm.all"
            if ! grep -q -e "$entry" $ep_conf; then
                echo "modify the ceilometer config"
                echo "          $entry    # added by doctor script" >> $ep_conf
                service ceilometer-agent-notification restart
            fi

            # TODO(r-mibu): enable this section once congress 4.0.0 is available
            if false; then
            co_conf=/etc/congress/congress.conf
            entry="congress.datasources.doctor_driver.DoctorDriver"
            if ! grep -q -e "^drivers.*$entry" $co_conf; then
                echo "modify the congress config"
                sed -i -e "/^drivers/s/$/,$entry    # added by doctor script/" \
                    $co_conf
                service congress-server restart
            fi

            rule="-m multiport -p tcp --dports 1789"
            rule+=" -m comment --comment doctor-congress"
            rule+=" -j ACCEPT"
            if ! iptables -C INPUT $rule; then
                iptables -I INPUT $rule
            fi

            ha_conf=/etc/haproxy/conf.d/180-congress.cfg
            if [[ ! -e $ha_conf ]]; then
                sed -e "1i# generated by doctor script" \
                    -e "s/9696/1789/" \
                    -e "s/neutron/congress/" \
                    /etc/haproxy/conf.d/085-neutron.cfg > $ha_conf
                ip netns exec haproxy /usr/lib/ocf/resource.d/fuel/ns_haproxy restart
            fi
            fi

            np_conf=/etc/nova/policy.json
            if [ -e $np_conf ]; then
                entry="os_compute_api:servers:show:host_status"
                new="rule:admin_or_owner"
                np_backup="${np_conf}-doctor-saved"
                if grep -q "${entry}.*${new}" $np_conf; then
                    echo "Not modifying nova policy"
                elif grep -q "${entry}" $np_conf; then
                    echo "modify nova policy"
                    cp $np_conf $np_backup
                    oldline=$(grep "$entry" $np_conf)
                    newline=$(echo "$oldline" | sed "s/rule.*\"/$new\"/")
                    sed -i "s/$oldline/$newline/" $np_conf
                    service nova-api restart
                else
                    echo "add nova policy"
                    cp $np_conf $np_backup
                    sed -i "/{/a \    \"${entry}\": \"$new\"" $np_conf
                    service nova-api restart
                fi
            else
                # TODO(tojuvone) policy.json might not exists in Ocata.
                echo "$np_conf does not exist!!!"
            fi
            ' > installer_apply_patches_$node.log 2>&1
    done
}

function setup_installer {
    get_installer_ip
    installer_get_ssh_keys
    get_controller_ips
    installer_apply_patches
    #Might take a moment for nova-api to restart
    sleep 20
    if ! openstack flavor show $VM_FLAVOR ; then
        openstack flavor create --ram 512 --disk 1 $VM_FLAVOR \
            && touch created_doctor_flavor
    fi
}

function get_compute_ip_from_hostname {
    local compute_host=$1

    compute_host_in_undercloud=${compute_host%%.*}
    node_id=$(echo $compute_host_in_undercloud | cut -d "-" -f 2)
    COMPUTE_IP=$(sshpass -p r00tme ssh 2>/dev/null $ssh_opts root@${INSTALLER_IP} \
         "fuel node|awk -F '|' -v id=$node_id '{if (\$1 == id) print \$5}' |xargs")
    die_if_not_set $LINENO COMPUTE_IP "Could get IP address of $compute_host."
}

function installer_revert_patches {
    # TODO(r-mibu): fix the followings in upstream (fuel)
    get_controller_ips
    for node in $CONTROLLER_IPS;do
        echo "restore controller configuration if touched ($node)"
        ssh $ssh_opts_cpu "root@$node" '
            set -x
            echo "### revert patches (installer=fuel)"
            date

            # TODO(r-mibu): enable this section once congress 4.0.0 is available
            if false; then
            ha_conf=/etc/haproxy/conf.d/180-congress.cfg
            if grep -q "# generated by doctor script" $ha_conf; then
                rm -f $ha_conf
                ip netns exec haproxy /usr/lib/ocf/resource.d/fuel/ns_haproxy restart
            fi

            rule="-m multiport -p tcp --dports 1789"
            rule+=" -m comment --comment doctor-congress"
            rule+=" -j ACCEPT"
            if iptables -C INPUT $rule; then
                iptables -D INPUT $rule
            fi

            co_conf=/etc/congress/congress.conf
            entry="congress.datasources.doctor_driver.DoctorDriver"
            if grep -q -e "^drivers.*$entry    # added by doctor script" $co_conf; then
                echo "modify the congress config"
                sed -i -e "/^drivers/s/^\(.*\),$entry/\1/" $co_conf
                service congress-server restart
            fi
            fi

            ep_conf=/etc/ceilometer/event_pipeline.yaml
            if grep -q "# added by doctor script" $ep_conf; then
                sed -ie "/# added by doctor script/d" $ep_conf
                service ceilometer-agent-notification restart
            fi

            np_conf=/etc/nova/policy.json
            entry="os_compute_api:servers:show:host_status"
            if [ -e $np_conf ]; then
                np_backup="${np_conf}-doctor-saved"
                if [ -e $np_backup ]; then
                    cp -f $np_backup $np_conf
                    rm $np_backup
                    service nova-api restart
                fi
            fi
            ' >> installer_apply_patches_$node.log 2>&1
    done
}

function cleanup_installer {
    if [[ -e created_doctor_flavor ]] && openstack flavor show $VM_FLAVOR ; then
        openstack flavor delete $VM_FLAVOR && rm -f created_doctor_flavor
    fi
    installer_revert_patches
}