Fixes missing provider mappings for OpenDaylight
[apex-tripleo-heat-templates.git] / extraconfig / tasks / yum_update.sh
1 #!/bin/bash
2
3 # A heat-config-script which runs yum update during a stack-update.
4 # Inputs:
5 #   deploy_action - yum will only be run if this is UPDATE
6 #   update_identifier - yum will only run for previously unused values of update_identifier
7 #   command - yum sub-command to run, defaults to "update"
8 #   command_arguments - yum command arguments, defaults to ""
9
10 echo "Started yum_update.sh on server $deploy_server_id at `date`"
11 echo -n "false" > $heat_outputs_path.update_managed_packages
12
13 if [[ -z "$update_identifier" ]]; then
14     echo "Not running due to unset update_identifier"
15     exit 0
16 fi
17
18 timestamp_dir=/var/lib/overcloud-yum-update
19 mkdir -p $timestamp_dir
20
21 # sanitise to remove unusual characters
22 update_identifier=${update_identifier//[^a-zA-Z0-9-_]/}
23
24 # seconds to wait for this node to rejoin the cluster after update
25 cluster_start_timeout=600
26 galera_sync_timeout=1800
27 cluster_settle_timeout=1800
28
29 timestamp_file="$timestamp_dir/$update_identifier"
30 if [[ -a "$timestamp_file" ]]; then
31     echo "Not running for already-run timestamp \"$update_identifier\""
32     exit 0
33 fi
34 touch "$timestamp_file"
35
36 command_arguments=${command_arguments:-}
37
38 list_updates=$(yum list updates)
39
40 if [[ "$list_updates" == "" ]]; then
41     echo "No packages require updating"
42     exit 0
43 fi
44
45 pacemaker_status=$(systemctl is-active pacemaker)
46
47 if [[ "$pacemaker_status" == "active" ]] ; then
48     echo "Pacemaker running, stopping cluster node and doing full package update"
49     node_count=$(pcs status xml | grep -o "<nodes_configured.*/>" | grep -o 'number="[0-9]*"' | grep -o "[0-9]*")
50     if [[ "$node_count" == "1" ]] ; then
51         echo "Active node count is 1, stopping node with --force"
52         pcs cluster stop --force
53     else
54         pcs cluster stop
55     fi
56 else
57     echo "Upgrading openstack-puppet-modules"
58     yum -q -y update openstack-puppet-modules
59     echo "Upgrading other packages is handled by config management tooling"
60     echo -n "true" > $heat_outputs_path.update_managed_packages
61     exit 0
62 fi
63
64 command=${command:-update}
65 full_command="yum -q -y $command $command_arguments"
66 echo "Running: $full_command"
67
68 result=$($full_command)
69 return_code=$?
70 echo "$result"
71 echo "yum return code: $return_code"
72
73 if [[ "$pacemaker_status" == "active" ]] ; then
74     echo "Starting cluster node"
75     pcs cluster start
76
77     hostname=$(hostname -s)
78     tstart=$(date +%s)
79     while [[ "$(pcs status | grep "^Online" | grep -F -o $hostname)" == "" ]]; do
80         sleep 5
81         tnow=$(date +%s)
82         if (( tnow-tstart > cluster_start_timeout )) ; then
83             echo "ERROR $hostname failed to join cluster in $cluster_start_timeout seconds"
84             pcs status
85             exit 1
86         fi
87     done
88
89     tstart=$(date +%s)
90     while ! clustercheck; do
91         sleep 5
92         tnow=$(date +%s)
93         if (( tnow-tstart > galera_sync_timeout )) ; then
94             echo "ERROR galera sync timed out"
95             exit 1
96         fi
97     done
98
99     echo "Waiting for pacemaker cluster to settle"
100     if ! timeout -k 10 $cluster_settle_timeout crm_resource --wait; then
101         echo "ERROR timed out while waiting for the cluster to settle"
102         exit 1
103     fi
104
105     pcs status
106 fi
107
108 echo "Finished yum_update.sh on server $deploy_server_id at `date`"
109
110 exit $return_code