From bdbfbf14c2b39568b989ceefd7011db0ce42a8fb Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Wed, 5 Nov 2014 00:42:30 +0100 Subject: [PATCH] fix #maintenance_mode? return value Make #maintenance_mode? return a sensible value even when openais is down or uninstalled. This is especially helpful when it is invoked by Chef's start_handler. --- .../libraries/maintenance_mode_helpers.rb | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/chef/cookbooks/crowbar-pacemaker/libraries/maintenance_mode_helpers.rb b/chef/cookbooks/crowbar-pacemaker/libraries/maintenance_mode_helpers.rb index d471b762..04845822 100644 --- a/chef/cookbooks/crowbar-pacemaker/libraries/maintenance_mode_helpers.rb +++ b/chef/cookbooks/crowbar-pacemaker/libraries/maintenance_mode_helpers.rb @@ -19,6 +19,26 @@ module CrowbarPacemaker # Chef::Provider::PacemakerService LWRP. module MaintenanceModeHelpers def maintenance_mode? + # For once, we want 2>&1 to come before >/dev/null, not after! + cibadmin = %x(cibadmin -Ql 2>&1 >/dev/null) + case cibadmin + when /Connection refused/ + # Cluster is not up, so let things proceed so that Chef can + # start it if appropriate. + return false + when /command not found/ + # pacemaker has been deinstalled? + return false + end + + if ! $?.success? + Chef::Log.warn("cibadmin -Ql failed when checking Pacemaker maintenance mode!") + Chef::Log.warn(cibadmin) + Chef::Log.warn("Something wrong, so treating as if in maintenance " + + "mode; will need manual intervention.") + return true + end + !! (%x(crm node show #{node.hostname}) =~ /maintenance:\s*on/) end