fix primitive definition strings with fewer parameters

This commit is contained in:
Adam Spiers
2014-02-04 18:13:50 +00:00
parent c21a592ab1
commit 4f144955ee
3 changed files with 24 additions and 8 deletions

View File

@@ -34,7 +34,8 @@ class Pacemaker::Resource::Primitive < Pacemaker::Resource
self.op = {}
%w(start stop monitor).each do |op|
self.op[op] = self.class.extract_hash(definition, "op #{op}")
h = self.class.extract_hash(definition, "op #{op}")
self.op[op] = h unless h.empty?
end
end
@@ -51,12 +52,16 @@ class Pacemaker::Resource::Primitive < Pacemaker::Resource
end
def definition_string
return <<EOF
#{TYPE} #{name} #{agent} \\
#{params_string} \\
#{meta_string} \\
#{op_string}
EOF
str = "#{TYPE} #{name} #{agent}"
indent = ' ' * 9
%w(params meta op).each do |data_type|
unless send(data_type).empty?
data_string = send("#{data_type}_string")
str << " \\\n#{indent}#{data_string}"
else
end
end
str
end
def crm_configure_command

View File

@@ -21,7 +21,7 @@ module Chef::RSpec
[ "monitor", { "timeout" => "60", "interval" => "10s" } ],
[ "start", { "timeout" => "240", "interval" => "10s" } ]
]
KEYSTONE_PRIMITIVE_DEFINITION = <<'EOF'
KEYSTONE_PRIMITIVE_DEFINITION = <<'EOF'.chomp
primitive keystone ocf:openstack:keystone \
params os_auth_url="http://node1:5000/v2.0" os_password="adminpw" os_tenant_name="openstack" os_username="admin" user="openstack-keystone" \
meta is-managed="true" target-role="Started" \

View File

@@ -110,6 +110,17 @@ describe Pacemaker::Resource::Primitive do
it "should return the definition string" do
expect(fixture.definition_string).to eq(fixture_definition)
end
it "should return a short definition string" do
primitive = Pacemaker::Resource::Primitive.new('foo')
primitive.definition = \
%!primitive foo ocf:heartbeat:IPaddr2 params foo="bar"!
primitive.parse_definition
expect(primitive.definition_string).to eq(<<'EOF'.chomp)
primitive foo ocf:heartbeat:IPaddr2 \
params foo="bar"
EOF
end
end
describe "#parse_definition" do