Merge "Remove unused Neutron Agents container"
[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   if timeout -k 10 $timeout crm_resource --wait; then
23       node_states=$(pcs status --full | grep "$service" | grep -v Clone)
24       if echo "$node_states" | grep -q "$match_for_incomplete"; then
25           echo_error "ERROR: cluster finished transition but $service was not in $state state, exiting."
26           exit 1
27       else
28         echo "$service has $state"
29       fi
30   else
31       echo_error "ERROR: cluster remained unstable for more than $timeout seconds, exiting."
32       exit 1
33   fi
34
35 }
36
37 function echo_error {
38     echo "$@" | tee /dev/fd2
39 }
40
41 function systemctl_swift {
42     services=( openstack-swift-account-auditor openstack-swift-account-reaper openstack-swift-account-replicator openstack-swift-account \
43                openstack-swift-container-auditor openstack-swift-container-replicator openstack-swift-container-updater openstack-swift-container \
44                openstack-swift-object-auditor openstack-swift-object-replicator openstack-swift-object-updater openstack-swift-object openstack-swift-proxy )
45     action=$1
46     case $action in
47         stop)
48             services=$(systemctl | grep swift | grep running | awk '{print $1}')
49             ;;
50         start)
51             enable_swift_storage=$(hiera -c /etc/puppet/hiera.yaml 'enable_swift_storage')
52             if [[ $enable_swift_storage != "true" ]]; then
53                 services=( openstack-swift-proxy )
54             fi
55             ;;
56         *)  services=() ;;  # for safetly, should never happen
57     esac
58     for S in ${services[@]}; do
59         systemctl $action $S
60     done
61 }