refactor shell quoting into #quoted_definition_string
This commit is contained in:
@@ -108,6 +108,17 @@ module Pacemaker
|
|||||||
"%s '%s'" % [self.class.description, name]
|
"%s '%s'" % [self.class.description, name]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns a single-quoted shell-escaped version of the definition
|
||||||
|
# string, suitable for use in a command like:
|
||||||
|
#
|
||||||
|
# echo '...' | crm configure load update -
|
||||||
|
def quoted_definition_string
|
||||||
|
"'%s'" % \
|
||||||
|
definition_string \
|
||||||
|
.gsub('\\') { '\\\\' } \
|
||||||
|
.gsub("'") { "\\'" }
|
||||||
|
end
|
||||||
|
|
||||||
def delete_command
|
def delete_command
|
||||||
"crm configure delete '#{name}'"
|
"crm configure delete '#{name}'"
|
||||||
end
|
end
|
||||||
|
@@ -64,10 +64,8 @@ def maybe_modify_resource(name)
|
|||||||
desired_colocation = cib_object_class.from_chef_resource(new_resource)
|
desired_colocation = cib_object_class.from_chef_resource(new_resource)
|
||||||
if desired_colocation.definition_string != @current_cib_object.definition_string
|
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}]"
|
Chef::Log.debug "changed from [#{@current_cib_object.definition_string}] to [#{desired_colocation.definition_string}]"
|
||||||
to_echo = desired_colocation.definition_string.chomp
|
to_echo = desired_colocation.quoted_definition_string
|
||||||
to_echo.gsub!('\\') { '\\\\' }
|
cmd = "echo #{to_echo} | crm configure load update -"
|
||||||
to_echo.gsub!("'", "\\'")
|
|
||||||
cmd = "echo '#{to_echo}' | crm configure load update -"
|
|
||||||
execute cmd do
|
execute cmd do
|
||||||
action :nothing
|
action :nothing
|
||||||
end.run_action(:run)
|
end.run_action(:run)
|
||||||
|
@@ -103,10 +103,8 @@ def maybe_modify_resource(name)
|
|||||||
desired_primitive = cib_object_class.from_chef_resource(new_resource)
|
desired_primitive = cib_object_class.from_chef_resource(new_resource)
|
||||||
if desired_primitive.op_string != @current_cib_object.op_string
|
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}]"
|
Chef::Log.debug "op changed from [#{@current_cib_object.op_string}] to [#{desired_primitive.op_string}]"
|
||||||
to_echo = desired_primitive.definition_string.chomp
|
to_echo = desired_primitive.quoted_definition_string
|
||||||
to_echo.gsub!('\\') { '\\\\' }
|
cmds = ["echo #{to_echo} | crm configure load update -"]
|
||||||
to_echo.gsub!("'", "\\'")
|
|
||||||
cmds = ["echo '#{to_echo}' | crm configure load update -"]
|
|
||||||
else
|
else
|
||||||
maybe_configure_params(name, cmds, :params)
|
maybe_configure_params(name, cmds, :params)
|
||||||
maybe_configure_params(name, cmds, :meta)
|
maybe_configure_params(name, cmds, :meta)
|
||||||
|
@@ -123,6 +123,21 @@ EOF
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#quoted_definition_string" do
|
||||||
|
it "should return the quoted definition string" do
|
||||||
|
primitive = Pacemaker::Resource::Primitive.new('foo')
|
||||||
|
primitive.definition = <<'EOF'.chomp
|
||||||
|
primitive foo ocf:openstack:keystone \
|
||||||
|
params bar="baz\\qux" bar2="baz'qux"
|
||||||
|
EOF
|
||||||
|
primitive.parse_definition
|
||||||
|
expect(primitive.quoted_definition_string).to eq(<<'EOF'.chomp)
|
||||||
|
'primitive foo ocf:openstack:keystone \\
|
||||||
|
params bar="baz\\qux" bar2="baz\'qux"'
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#parse_definition" do
|
describe "#parse_definition" do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
@parsed = Pacemaker::Resource::Primitive.new(fixture.name)
|
@parsed = Pacemaker::Resource::Primitive.new(fixture.name)
|
||||||
|
@@ -46,10 +46,9 @@ describe "Chef::Provider::PacemakerColocation" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should modify the constraint if it has a different score" do
|
it "should modify the constraint if it has a different score" do
|
||||||
echo_string = colo.definition_string.chomp.gsub('inf', '100')
|
echo_string = colo.quoted_definition_string.gsub('inf', '100')
|
||||||
echo_string.gsub!('\\') { '\\\\' }
|
|
||||||
expected_configure_cmd_args = [
|
expected_configure_cmd_args = [
|
||||||
"echo '#{echo_string}' | crm configure load update -"
|
"echo #{echo_string} | crm configure load update -"
|
||||||
]
|
]
|
||||||
test_modify(expected_configure_cmd_args) do
|
test_modify(expected_configure_cmd_args) do
|
||||||
@resource.score '100'
|
@resource.score '100'
|
||||||
@@ -60,10 +59,9 @@ describe "Chef::Provider::PacemakerColocation" do
|
|||||||
new_resource = 'bar:Stopped'
|
new_resource = 'bar:Stopped'
|
||||||
expected = colo.dup
|
expected = colo.dup
|
||||||
expected.resources = expected.resources.dup + [new_resource]
|
expected.resources = expected.resources.dup + [new_resource]
|
||||||
echo_string = expected.definition_string.chomp
|
echo_string = expected.quoted_definition_string
|
||||||
echo_string.gsub!('\\') { '\\\\' }
|
|
||||||
expected_configure_cmd_args = [
|
expected_configure_cmd_args = [
|
||||||
"echo '#{echo_string}' | crm configure load update -"
|
"echo #{echo_string} | crm configure load update -"
|
||||||
]
|
]
|
||||||
test_modify(expected_configure_cmd_args) do
|
test_modify(expected_configure_cmd_args) do
|
||||||
@resource.resources expected.resources
|
@resource.resources expected.resources
|
||||||
@@ -73,10 +71,9 @@ describe "Chef::Provider::PacemakerColocation" do
|
|||||||
it "should modify the constraint if it has a different resource" do
|
it "should modify the constraint if it has a different resource" do
|
||||||
new_resources = ['bar:Started']
|
new_resources = ['bar:Started']
|
||||||
colo.resources = new_resources
|
colo.resources = new_resources
|
||||||
echo_string = colo.definition_string.chomp
|
echo_string = colo.quoted_definition_string
|
||||||
echo_string.gsub!('\\') { '\\\\' }
|
|
||||||
expected_configure_cmd_args = [
|
expected_configure_cmd_args = [
|
||||||
"echo '#{echo_string}' | crm configure load update -"
|
"echo #{echo_string} | crm configure load update -"
|
||||||
]
|
]
|
||||||
test_modify(expected_configure_cmd_args) do
|
test_modify(expected_configure_cmd_args) do
|
||||||
@resource.resources new_resources
|
@resource.resources new_resources
|
||||||
|
@@ -91,10 +91,9 @@ describe "Chef::Provider::PacemakerPrimitive" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "should modify the primitive if it has different op values" do
|
it "should modify the primitive if it has different op values" do
|
||||||
echo_string = rsc.definition_string.chomp
|
echo_string = rsc.quoted_definition_string.gsub!('60', '120')
|
||||||
echo_string.gsub!('\\') { '\\\\' }.gsub!('60', '120')
|
|
||||||
expected_configure_cmd_args = [
|
expected_configure_cmd_args = [
|
||||||
"echo '#{echo_string}' | crm configure load update -"
|
"echo #{echo_string} | crm configure load update -"
|
||||||
]
|
]
|
||||||
test_modify(expected_configure_cmd_args) do
|
test_modify(expected_configure_cmd_args) do
|
||||||
new_op = Hash[rsc.op]
|
new_op = Hash[rsc.op]
|
||||||
|
Reference in New Issue
Block a user