Merge "Add flag to assert that puppet manages the keystone endpoints"
[apex-tripleo-heat-templates.git] / extraconfig / tasks / pacemaker_common_functions.sh
1 #!/bin/bash
2
3 set -eu
4
5 function check_resource {
6
7   if [ "$#" -ne 3 ]; then
8       echo_error "ERROR: check_resource function expects 3 parameters, $# given"
9       exit 1
10   fi
11
12   service=$1
13   state=$2
14   timeout=$3
15
16   if [ "$state" = "stopped" ]; then
17       match_for_incomplete='Started'
18   else # started
19       match_for_incomplete='Stopped'
20   fi
21
22   nodes_local=$(pcs status  | grep ^Online | sed 's/.*\[ \(.*\) \]/\1/g' | sed 's/ /\|/g')
23   if timeout -k 10 $timeout crm_resource --wait; then
24       node_states=$(pcs status --full | grep "$service" | grep -v Clone | { egrep "$nodes_local" || true; } )
25       if echo "$node_states" | grep -q "$match_for_incomplete"; then
26           echo_error "ERROR: cluster finished transition but $service was not in $state state, exiting."
27           exit 1
28       else
29         echo "$service has $state"
30       fi
31   else
32       echo_error "ERROR: cluster remained unstable for more than $timeout seconds, exiting."
33       exit 1
34   fi
35
36 }
37
38 function echo_error {
39     echo "$@" | tee /dev/fd2
40 }
41
42 function systemctl_swift {
43     services=( openstack-swift-account-auditor openstack-swift-account-reaper openstack-swift-account-replicator openstack-swift-account \
44                openstack-swift-container-auditor openstack-swift-container-replicator openstack-swift-container-updater openstack-swift-container \
45                openstack-swift-object-auditor openstack-swift-object-replicator openstack-swift-object-updater openstack-swift-object openstack-swift-proxy )
46     action=$1
47     case $action in
48         stop)
49             services=$(systemctl | grep swift | grep running | awk '{print $1}')
50             ;;
51         start)
52             enable_swift_storage=$(hiera -c /etc/puppet/hiera.yaml 'enable_swift_storage')
53             if [[ $enable_swift_storage != "true" ]]; then
54                 services=( openstack-swift-proxy )
55             fi
56             ;;
57         *)  services=() ;;  # for safetly, should never happen
58     esac
59     for S in ${services[@]}; do
60         systemctl $action $S
61     done
62 }