Blame SOURCES/bz1400103-nova-compute-wait-nova-compute-unfence.patch

4c01c1
diff -uNr a/heartbeat/nova-compute-wait b/heartbeat/nova-compute-wait
4c01c1
--- a/heartbeat/nova-compute-wait	2016-11-29 12:36:05.437464639 +0100
4c01c1
+++ b/heartbeat/nova-compute-wait	2016-11-29 12:52:54.790724139 +0100
4c01c1
@@ -1,30 +1,15 @@
4c01c1
 #!/bin/sh
4c01c1
+# Copyright 2015 Red Hat, Inc.
4c01c1
 #
4c01c1
+# Description:  Manages compute daemons
4c01c1
 #
4c01c1
-# nova-compute-wait agent manages compute daemons.
4c01c1
+# Authors: Andrew Beekhof
4c01c1
 #
4c01c1
-# Copyright (c) 2015
4c01c1
-#
4c01c1
-# This program is free software; you can redistribute it and/or modify
4c01c1
-# it under the terms of version 2 of the GNU General Public License as
4c01c1
-# published by the Free Software Foundation.
4c01c1
-#
4c01c1
-# This program is distributed in the hope that it would be useful, but
4c01c1
-# WITHOUT ANY WARRANTY; without even the implied warranty of
4c01c1
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
4c01c1
-#
4c01c1
-# Further, this software is distributed without any warranty that it is
4c01c1
-# free of the rightful claim of any third person regarding infringement
4c01c1
-# or the like.  Any license provided herein, whether implied or
4c01c1
-# otherwise, applies only to this software file.  Patent licenses, if
4c01c1
-# any, provided herein do not apply to combinations of this program with
4c01c1
-# other software, or any other product whatsoever.
4c01c1
-#
4c01c1
-# You should have received a copy of the GNU General Public License
4c01c1
-# along with this program; if not, write the Free Software Foundation,
4c01c1
-# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
4c01c1
+# Support:      openstack@lists.openstack.org
4c01c1
+# License:      Apache Software License (ASL) 2.0
4c01c1
 #
4c01c1
 
4c01c1
+
4c01c1
 #######################################################################
4c01c1
 # Initialization:
4c01c1
 
4c01c1
@@ -137,6 +122,8 @@
4c01c1
 }
4c01c1
 
4c01c1
 nova_start() {
4c01c1
+    build_unfence_overlay
4c01c1
+
4c01c1
     state=$(attrd_updater -p -n evacuate -N ${NOVA_HOST} | sed -e 's/.*value=//' | tr -d '"' )
4c01c1
     if [ "x$state" = x ]; then
4c01c1
 	: never been fenced
4c01c1
@@ -147,8 +134,8 @@
4c01c1
 	sleep ${OCF_RESKEY_evacuation_delay}
4c01c1
 
4c01c1
     else
4c01c1
-	ocf_log info "Waiting for pending evacuations from ${NOVA_HOST}"
4c01c1
 	while [ "x$state" != "xno" ]; do
4c01c1
+	    ocf_log info "Waiting for pending evacuations from ${NOVA_HOST}"
4c01c1
 	    state=$(attrd_updater -p -n evacuate -N ${NOVA_HOST} | sed -e 's/.*value=//' | tr -d '"' )
4c01c1
 	    sleep 5
4c01c1
 	done
4c01c1
@@ -156,14 +143,22 @@
4c01c1
 	ocf_log info "Pausing to give evacuations from ${NOVA_HOST} time to complete"
4c01c1
 	sleep ${OCF_RESKEY_evacuation_delay}
4c01c1
     fi
4c01c1
+
4c01c1
+    touch "$statefile"
4c01c1
+
4c01c1
     return $OCF_SUCCESS
4c01c1
 }
4c01c1
 
4c01c1
 nova_stop() {
4c01c1
+    rm -f "$statefile"
4c01c1
     return $OCF_SUCCESS
4c01c1
 }
4c01c1
 
4c01c1
 nova_monitor() {
4c01c1
+    if [ ! -f "$statefile" ]; then
4c01c1
+        return $OCF_NOT_RUNNING
4c01c1
+    fi
4c01c1
+
4c01c1
     return $OCF_SUCCESS
4c01c1
 }
4c01c1
 
4c01c1
@@ -171,17 +166,113 @@
4c01c1
     return $OCF_SUCCESS
4c01c1
 }
4c01c1
 
4c01c1
+build_unfence_overlay() {
4c01c1
+    fence_options=""
4c01c1
+
4c01c1
+    if [ -z "${OCF_RESKEY_auth_url}" ]; then
4c01c1
+	candidates=$(/usr/sbin/stonith_admin -l ${NOVA_HOST})
4c01c1
+	for candidate in ${candidates}; do
4c01c1
+	    pcs stonith show $d | grep -q fence_compute
4c01c1
+	    if [ $? = 0 ]; then
4c01c1
+		ocf_log info "Unfencing nova based on: $candidate"
4c01c1
+		fence_auth=$(pcs stonith show $candidate | grep Attributes: | sed -e s/Attributes:// -e s/-/_/g -e 's/[^ ]\+=/OCF_RESKEY_\0/g' -e s/passwd/password/g)
4c01c1
+		eval "export $fence_auth"
4c01c1
+		break
4c01c1
+	    fi
4c01c1
+	done
4c01c1
+    fi    
4c01c1
+
4c01c1
+    # Copied from NovaEvacuate 
4c01c1
+    if [ -z "${OCF_RESKEY_auth_url}" ]; then
4c01c1
+        ocf_exit_reason "auth_url not configured"
4c01c1
+        exit $OCF_ERR_CONFIGURED
4c01c1
+    fi
4c01c1
+
4c01c1
+    fence_options="${fence_options} -k ${OCF_RESKEY_auth_url}"
4c01c1
+
4c01c1
+    if [ -z "${OCF_RESKEY_username}" ]; then
4c01c1
+        ocf_exit_reason "username not configured"
4c01c1
+        exit $OCF_ERR_CONFIGURED
4c01c1
+    fi
4c01c1
+
4c01c1
+    fence_options="${fence_options} -l ${OCF_RESKEY_username}"
4c01c1
+
4c01c1
+    if [ -z "${OCF_RESKEY_password}" ]; then
4c01c1
+        ocf_exit_reason "password not configured"
4c01c1
+        exit $OCF_ERR_CONFIGURED
4c01c1
+    fi
4c01c1
+
4c01c1
+    fence_options="${fence_options} -p ${OCF_RESKEY_password}"
4c01c1
+
4c01c1
+    if [ -z "${OCF_RESKEY_tenant_name}" ]; then
4c01c1
+        ocf_exit_reason "tenant_name not configured"
4c01c1
+        exit $OCF_ERR_CONFIGURED
4c01c1
+    fi
4c01c1
+
4c01c1
+    fence_options="${fence_options} -t ${OCF_RESKEY_tenant_name}"
4c01c1
+
4c01c1
+    if [ -n "${OCF_RESKEY_domain}" ]; then
4c01c1
+        fence_options="${fence_options} -d ${OCF_RESKEY_domain}"
4c01c1
+    fi
4c01c1
+
4c01c1
+    if [ -n "${OCF_RESKEY_region_name}" ]; then
4c01c1
+        fence_options="${fence_options} \
4c01c1
+            --region-name ${OCF_RESKEY_region_name}"
4c01c1
+    fi
4c01c1
+
4c01c1
+    if [ -n "${OCF_RESKEY_insecure}" ]; then
4c01c1
+        if ocf_is_true "${OCF_RESKEY_insecure}"; then
4c01c1
+            fence_options="${fence_options} --insecure"
4c01c1
+        fi
4c01c1
+    fi
4c01c1
+
4c01c1
+    if [ -n "${OCF_RESKEY_no_shared_storage}" ]; then
4c01c1
+        if ocf_is_true "${OCF_RESKEY_no_shared_storage}"; then
4c01c1
+            fence_options="${fence_options} --no-shared-storage"
4c01c1
+        fi
4c01c1
+    fi
4c01c1
+
4c01c1
+    if [ -n "${OCF_RESKEY_endpoint_type}" ]; then
4c01c1
+        case ${OCF_RESKEY_endpoint_type} in
4c01c1
+            adminURL|publicURL|internalURL)
4c01c1
+                ;;
4c01c1
+            *)
4c01c1
+                ocf_exit_reason "endpoint_type ${OCF_RESKEY_endpoint_type}" \
4c01c1
+                    "not valid. Use adminURL or publicURL or internalURL"
4c01c1
+                exit $OCF_ERR_CONFIGURED
4c01c1
+                ;;
4c01c1
+        esac
4c01c1
+        fence_options="${fence_options} -e ${OCF_RESKEY_endpoint_type}"
4c01c1
+    fi
4c01c1
+
4c01c1
+    mkdir -p /run/systemd/system/openstack-nova-compute.service.d
4c01c1
+    cat<<EOF>/run/systemd/system/openstack-nova-compute.service.d/unfence-20.conf
4c01c1
+[Service]
4c01c1
+ExecStartPost=/sbin/fence_compute ${fence_options} -o on -n ${NOVA_HOST}
4c01c1
+EOF
4c01c1
+}
4c01c1
+
4c01c1
 nova_validate() {
4c01c1
     rc=$OCF_SUCCESS
4c01c1
 
4c01c1
     check_binary crudini
4c01c1
     check_binary nova-compute
4c01c1
+    check_binary fence_compute
4c01c1
 
4c01c1
     if [ ! -f /etc/nova/nova.conf ]; then
4c01c1
 	   ocf_exit_reason "/etc/nova/nova.conf not found"
4c01c1
 	   exit $OCF_ERR_CONFIGURED
4c01c1
     fi
4c01c1
 
4c01c1
+    # Is the state directory writable?
4c01c1
+    state_dir=$(dirname $statefile)
4c01c1
+    touch "$state_dir/$$"
4c01c1
+    if [ $? != 0 ]; then
4c01c1
+        ocf_exit_reason "Invalid state directory: $state_dir"
4c01c1
+        return $OCF_ERR_ARGS
4c01c1
+    fi
4c01c1
+    rm -f "$state_dir/$$"
4c01c1
+
4c01c1
     NOVA_HOST=$(crudini --get /etc/nova/nova.conf DEFAULT host 2>/dev/null)
4c01c1
     if [ $? = 1 ]; then
4c01c1
         short_host=$(uname -n | awk -F. '{print $1}')
4c01c1
@@ -198,6 +289,8 @@
4c01c1
     return $rc
4c01c1
 }
4c01c1
 
4c01c1
+statefile="${HA_RSCTMP}/${OCF_RESOURCE_INSTANCE}.active"
4c01c1
+
4c01c1
 : ${OCF_RESKEY_evacuation_delay=120}
4c01c1
 case $__OCF_ACTION in
4c01c1
 meta-data)	meta_data
4c01c1
@@ -221,3 +314,4 @@
4c01c1
 rc=$?
4c01c1
 ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
4c01c1
 exit $rc
4c01c1
+
4c01c1
diff -uNr a/heartbeat/NovaEvacuate b/heartbeat/NovaEvacuate
4c01c1
--- a/heartbeat/NovaEvacuate	2016-11-29 12:36:05.425464769 +0100
4c01c1
+++ b/heartbeat/NovaEvacuate	2016-11-29 12:52:38.548900211 +0100
4c01c1
@@ -1,30 +1,16 @@
4c01c1
 #!/bin/sh
4c01c1
 #
4c01c1
+# Copyright 2015 Red Hat, Inc.
4c01c1
 #
4c01c1
-# NovaCompute agent manages compute daemons.
4c01c1
+# Description:  Manages evacuation of nodes running nova-compute
4c01c1
 #
4c01c1
-# Copyright (c) 2015
4c01c1
+# Authors: Andrew Beekhof
4c01c1
 #
4c01c1
-# This program is free software; you can redistribute it and/or modify
4c01c1
-# it under the terms of version 2 of the GNU General Public License as
4c01c1
-# published by the Free Software Foundation.
4c01c1
-#
4c01c1
-# This program is distributed in the hope that it would be useful, but
4c01c1
-# WITHOUT ANY WARRANTY; without even the implied warranty of
4c01c1
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
4c01c1
-#
4c01c1
-# Further, this software is distributed without any warranty that it is
4c01c1
-# free of the rightful claim of any third person regarding infringement
4c01c1
-# or the like.  Any license provided herein, whether implied or
4c01c1
-# otherwise, applies only to this software file.  Patent licenses, if
4c01c1
-# any, provided herein do not apply to combinations of this program with
4c01c1
-# other software, or any other product whatsoever.
4c01c1
-#
4c01c1
-# You should have received a copy of the GNU General Public License
4c01c1
-# along with this program; if not, write the Free Software Foundation,
4c01c1
-# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
4c01c1
+# Support:      openstack@lists.openstack.org
4c01c1
+# License:      Apache Software License (ASL) 2.0
4c01c1
 #
4c01c1
 
4c01c1
+
4c01c1
 #######################################################################
4c01c1
 # Initialization:
4c01c1