From 95563f791a54f85c8b79e925c25d373373457c75 Mon Sep 17 00:00:00 2001 From: Vincent Untz Date: Thu, 13 Mar 2014 15:31:54 +0100 Subject: [PATCH] Check that the specified STONITH plugin is available We simply need to check if the plugin is in the output of "stonith -L". --- recipes/stonith.rb | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/recipes/stonith.rb b/recipes/stonith.rb index 56db368..bede5ea 100644 --- a/recipes/stonith.rb +++ b/recipes/stonith.rb @@ -19,7 +19,23 @@ # # FIXME: delete old resources when switching mode (or plugin!) -# FIXME: check that the stonith plugin to use exists with stonith -L + +@stonith_plugins = nil + +def stonith_plugin_valid?(plugin) + if plugin.nil? || plugin.empty? + false + else + if @stonith_plugins.nil? + out = %x{stonith -L} + if $?.success? + @stonith_plugins = out.split("\n") + end + end + + !@stonith_plugins.nil? && @stonith_plugins.include?(plugin) + end +end case node[:pacemaker][:stonith][:mode] when "disabled" @@ -30,6 +46,12 @@ when "clone" plugin = node[:pacemaker][:stonith][:clone][:plugin] params = node[:pacemaker][:stonith][:clone][:params] + unless stonith_plugin_valid? plugin + message = "STONITH plugin #{plugin} is not available!" + Chef::Log.fatal(message) + raise message + end + if params.respond_to?('to_hash') primitive_params = params.to_hash elsif params.is_a?(String) @@ -60,6 +82,12 @@ when "clone" when "per_node" plugin = node[:pacemaker][:stonith][:per_node][:plugin] + unless stonith_plugin_valid? plugin + message = "STONITH plugin #{plugin} is not available!" + Chef::Log.fatal(message) + raise message + end + node[:pacemaker][:stonith][:per_node][:nodes].keys.each do |node_name| stonith_resource = "stonith-#{node_name}" params = node[:pacemaker][:stonith][:per_node][:nodes][node_name][:params]