Explicitly set nova and neutron host on controllers
[apex-tripleo-heat-templates.git] / extraconfig / tasks / major_upgrade_pacemaker_migrations.sh
1 #!/bin/bash
2
3 # Special pieces of upgrade migration logic go into this
4 # file. E.g. Pacemaker cluster transitions for existing deployments,
5 # matching changes to overcloud_controller_pacemaker.pp (Puppet
6 # handles deployment, this file handles migrations).
7 #
8 # This file shouldn't execute any action on its own, all logic should
9 # be wrapped into bash functions. Upgrade scripts will source this
10 # file and call the functions defined in this file where appropriate.
11 #
12 # The migration functions should be idempotent. If the migration has
13 # been already applied, it should be possible to call the function
14 # again without damaging the deployment or failing the upgrade.
15
16 # If the major version of mysql is going to change after the major
17 # upgrade, the database must be upgraded on disk to avoid failures
18 # due to internal incompatibilities between major mysql versions
19 # https://bugs.launchpad.net/tripleo/+bug/1587449
20 # This function detects whether a database upgrade is required
21 # after a mysql package upgrade. It returns 0 when no major upgrade
22 # has to take place, 1 otherwise.
23 function is_mysql_upgrade_needed {
24     # The name of the package which provides mysql might differ
25     # after the upgrade. Consider the generic package name, which
26     # should capture the major version change (e.g. 5.5 -> 10.1)
27     local name="mariadb"
28     local output
29     local ret
30     set +e
31     output=$(yum -q check-update $name)
32     ret=$?
33     set -e
34     if [ $ret -ne 100 ]; then
35         # no updates so we exit
36         echo "0"
37         return
38     fi
39
40     local currentepoch=$(rpm -q --qf "%{epoch}" $name)
41     local currentversion=$(rpm -q --qf "%{version}" $name)
42     local currentrelease=$(rpm -q --qf "%{release}" $name)
43     local newoutput=$(repoquery -a --pkgnarrow=updates --qf "%{epoch} %{version} %{release}\n" $name)
44     local newepoch=$(echo "$newoutput" | awk '{ print $1 }')
45     local newversion=$(echo "$newoutput" | awk '{ print $2 }')
46     local newrelease=$(echo "$newoutput" | awk '{ print $3 }')
47
48     # With this we trigger the dump restore/path if we change either epoch or
49     # version in the package If only the release tag changes we do not do it
50     # FIXME: we could refine this by trying to parse the mariadb version
51     # into X.Y.Z and trigger the update only if X and/or Y change.
52     output=$(python -c "import rpm; rc = rpm.labelCompare((\"$currentepoch\", \"$currentversion\", None), (\"$newepoch\", \"$newversion\", None)); print rc")
53     if [ "$output" != "-1" ]; then
54         echo "0"
55         return
56     fi
57     echo "1"
58 }
59
60 function add_missing_openstack_core_constraints {
61     # The CIBs are saved under /root as they might contain sensitive data
62     CIB="/root/migration.cib"
63     CIB_BACKUP="/root/backup.cib"
64     CIB_PUSH_NEEDED=n
65
66     rm -f "$CIB" "$CIB_BACKUP" || /bin/true
67     pcs cluster cib "$CIB"
68     cp "$CIB" "$CIB_BACKUP"
69
70     if ! pcs -f "$CIB" constraint --full | grep 'start openstack-sahara-api-clone then start openstack-sahara-engine-clone'; then
71         pcs -f "$CIB" constraint order start openstack-sahara-api-clone then start openstack-sahara-engine-clone
72         CIB_PUSH_NEEDED=y
73     fi
74
75     if ! pcs -f "$CIB" constraint --full | grep 'start openstack-core-clone then start openstack-ceilometer-notification-clone'; then
76         pcs -f "$CIB" constraint order start openstack-core-clone then start openstack-ceilometer-notification-clone
77         CIB_PUSH_NEEDED=y
78     fi
79
80     if ! pcs -f "$CIB" constraint --full | grep 'start openstack-aodh-evaluator-clone then start openstack-aodh-listener-clone'; then
81         pcs -f "$CIB" constraint order start openstack-aodh-evaluator-clone then start openstack-aodh-listener-clone
82         CIB_PUSH_NEEDED=y
83     fi
84
85     if pcs -f "$CIB" constraint --full | grep 'start openstack-core-clone then start openstack-heat-api-clone'; then
86         CID=$(pcs -f "$CIB" constraint --full | grep 'start openstack-core-clone then start openstack-heat-api-clone' | sed -e 's/.*id\://g' -e 's/)//g')
87         pcs -f "$CIB" constraint remove $CID
88         CIB_PUSH_NEEDED=y
89     fi
90
91     if [ "$CIB_PUSH_NEEDED" = 'y' ]; then
92         pcs cluster cib-push "$CIB"
93     fi
94 }
95
96 function remove_ceilometer_alarm {
97     if pcs status | grep openstack-ceilometer-alarm; then
98         # Disable pacemaker resources for ceilometer-alarms
99         pcs resource disable openstack-ceilometer-alarm-evaluator
100         check_resource openstack-ceilometer-alarm-evaluator stopped 600
101         pcs resource delete openstack-ceilometer-alarm-evaluator
102         pcs resource disable openstack-ceilometer-alarm-notifier
103         check_resource openstack-ceilometer-alarm-notifier stopped 600
104         pcs resource delete openstack-ceilometer-alarm-notifier
105
106         # remove constraints
107         pcs constraint remove ceilometer-delay-then-ceilometer-alarm-evaluator-constraint
108         pcs constraint remove ceilometer-alarm-evaluator-with-ceilometer-delay-colocation
109         pcs constraint remove ceilometer-alarm-evaluator-then-ceilometer-alarm-notifier-constraint
110         pcs constraint remove ceilometer-alarm-notifier-with-ceilometer-alarm-evaluator-colocation
111         pcs constraint remove ceilometer-alarm-notifier-then-ceilometer-notification-constraint
112         pcs constraint remove ceilometer-notification-with-ceilometer-alarm-notifier-colocation
113
114     fi
115
116     # uninstall openstack-ceilometer-alarm package
117     yum -y remove openstack-ceilometer-alarm
118
119 }