diff --git a/libraries/pacemaker/cib_object.rb b/libraries/pacemaker/cib_object.rb index 0111252..8ed347b 100644 --- a/libraries/pacemaker/cib_object.rb +++ b/libraries/pacemaker/cib_object.rb @@ -119,6 +119,10 @@ module Pacemaker .gsub("'") { "\\'" } end + def reconfigure_command + "echo #{quoted_definition_string} | crm configure load update -" + end + def delete_command "crm configure delete '#{name}'" end diff --git a/providers/colocation.rb b/providers/colocation.rb index 61ddfeb..cc0c7eb 100644 --- a/providers/colocation.rb +++ b/providers/colocation.rb @@ -64,8 +64,7 @@ def maybe_modify_resource(name) desired_colocation = cib_object_class.from_chef_resource(new_resource) if desired_colocation.definition_string != @current_cib_object.definition_string Chef::Log.debug "changed from [#{@current_cib_object.definition_string}] to [#{desired_colocation.definition_string}]" - to_echo = desired_colocation.quoted_definition_string - cmd = "echo #{to_echo} | crm configure load update -" + cmd = desired_colocation.reconfigure_command execute cmd do action :nothing end.run_action(:run) diff --git a/providers/primitive.rb b/providers/primitive.rb index 449d721..95feda3 100644 --- a/providers/primitive.rb +++ b/providers/primitive.rb @@ -103,8 +103,7 @@ def maybe_modify_resource(name) desired_primitive = cib_object_class.from_chef_resource(new_resource) if desired_primitive.op_string != @current_cib_object.op_string Chef::Log.debug "op changed from [#{@current_cib_object.op_string}] to [#{desired_primitive.op_string}]" - to_echo = desired_primitive.quoted_definition_string - cmds = ["echo #{to_echo} | crm configure load update -"] + cmds = [desired_primitive.reconfigure_command] else maybe_configure_params(name, cmds, :params) maybe_configure_params(name, cmds, :meta) diff --git a/spec/providers/colocation_spec.rb b/spec/providers/colocation_spec.rb index b289c1f..70472c1 100644 --- a/spec/providers/colocation_spec.rb +++ b/spec/providers/colocation_spec.rb @@ -46,12 +46,11 @@ describe "Chef::Provider::PacemakerColocation" do end it "should modify the constraint if it has a different score" do - echo_string = colo.quoted_definition_string.gsub('inf', '100') - expected_configure_cmd_args = [ - "echo #{echo_string} | crm configure load update -" - ] + new_score = '100' + colo.score = new_score + expected_configure_cmd_args = [colo.reconfigure_command] test_modify(expected_configure_cmd_args) do - @resource.score '100' + @resource.score new_score end end @@ -59,10 +58,7 @@ describe "Chef::Provider::PacemakerColocation" do new_resource = 'bar:Stopped' expected = colo.dup expected.resources = expected.resources.dup + [new_resource] - echo_string = expected.quoted_definition_string - expected_configure_cmd_args = [ - "echo #{echo_string} | crm configure load update -" - ] + expected_configure_cmd_args = [expected.reconfigure_command] test_modify(expected_configure_cmd_args) do @resource.resources expected.resources end @@ -71,10 +67,7 @@ describe "Chef::Provider::PacemakerColocation" do it "should modify the constraint if it has a different resource" do new_resources = ['bar:Started'] colo.resources = new_resources - echo_string = colo.quoted_definition_string - expected_configure_cmd_args = [ - "echo #{echo_string} | crm configure load update -" - ] + expected_configure_cmd_args = [colo.reconfigure_command] test_modify(expected_configure_cmd_args) do @resource.resources new_resources end diff --git a/spec/providers/primitive_spec.rb b/spec/providers/primitive_spec.rb index 4f3e6dd..7b6bac7 100644 --- a/spec/providers/primitive_spec.rb +++ b/spec/providers/primitive_spec.rb @@ -91,9 +91,8 @@ describe "Chef::Provider::PacemakerPrimitive" do end it "should modify the primitive if it has different op values" do - echo_string = rsc.quoted_definition_string.gsub!('60', '120') expected_configure_cmd_args = [ - "echo #{echo_string} | crm configure load update -" + rsc.reconfigure_command.gsub('60', '120') ] test_modify(expected_configure_cmd_args) do new_op = Hash[rsc.op]