support modification of primitive op values
This commit is contained in:
@@ -34,7 +34,7 @@ action :create do
|
|||||||
[ name, @current_resource.agent, new_resource.agent ]
|
[ name, @current_resource.agent, new_resource.agent ]
|
||||||
end
|
end
|
||||||
|
|
||||||
modify_resource(name)
|
maybe_modify_resource(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -133,12 +133,22 @@ def create_resource(name)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def modify_resource(name)
|
def maybe_modify_resource(name)
|
||||||
Chef::Log.info "Checking existing resource primitive #{name} for modifications"
|
Chef::Log.info "Checking existing resource primitive #{name} for modifications"
|
||||||
|
|
||||||
cmds = []
|
cmds = []
|
||||||
modify_params(name, cmds, :params)
|
|
||||||
modify_params(name, cmds, :meta)
|
desired_primitive = Pacemaker::Resource::Primitive.from_chef_resource(new_resource)
|
||||||
|
if desired_primitive.op_string != @current_primitive.op_string
|
||||||
|
Chef::Log.debug "op changed from [#{@current_primitive.op_string}] to [#{desired_primitive.op_string}]"
|
||||||
|
to_echo = desired_primitive.definition_string.chomp
|
||||||
|
to_echo.gsub!('\\') { '\\\\' }
|
||||||
|
to_echo.gsub!("'", "\\'")
|
||||||
|
cmds = ["echo '#{to_echo}' | crm configure load update -"]
|
||||||
|
else
|
||||||
|
maybe_configure_params(name, cmds, :params)
|
||||||
|
maybe_configure_params(name, cmds, :meta)
|
||||||
|
end
|
||||||
|
|
||||||
cmds.each do |cmd|
|
cmds.each do |cmd|
|
||||||
execute cmd do
|
execute cmd do
|
||||||
@@ -149,7 +159,7 @@ def modify_resource(name)
|
|||||||
new_resource.updated_by_last_action(true) unless cmds.empty?
|
new_resource.updated_by_last_action(true) unless cmds.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def modify_params(name, cmds, data_type)
|
def maybe_configure_params(name, cmds, data_type)
|
||||||
configure_cmd_prefix = "crm_resource --resource #{name}"
|
configure_cmd_prefix = "crm_resource --resource #{name}"
|
||||||
|
|
||||||
new_resource.send(data_type).each do |param, new_value|
|
new_resource.send(data_type).each do |param, new_value|
|
||||||
|
@@ -100,6 +100,21 @@ describe "Chef::Provider::PacemakerPrimitive" do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should modify the primitive if it has different op values" do
|
||||||
|
echo_string = rsc.definition_string.chomp
|
||||||
|
echo_string.gsub!('\\') { '\\\\' }.gsub!('60', '120')
|
||||||
|
expected_configure_cmd_args = [
|
||||||
|
"echo '#{echo_string}' | crm configure load update -"
|
||||||
|
]
|
||||||
|
test_modify(expected_configure_cmd_args) do
|
||||||
|
new_op = Hash[rsc.op]
|
||||||
|
# Ensure we're not modifying our expectation as well as the input
|
||||||
|
new_op['monitor'] = new_op['monitor'].dup
|
||||||
|
new_op['monitor']['timeout'] = '120'
|
||||||
|
@resource.op new_op
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "should create a primitive if it doesn't already exist" do
|
it "should create a primitive if it doesn't already exist" do
|
||||||
expect_definition("")
|
expect_definition("")
|
||||||
# Later, the :create action calls Pacemaker::Resource::Primitive#exists? to check
|
# Later, the :create action calls Pacemaker::Resource::Primitive#exists? to check
|
||||||
|
Reference in New Issue
Block a user