
Newly created primitive resources weren't being marked as updated in real runs, because exists? was being run on an old object. Furthermore, the tests didn't catch this because #exists? on any instance of Pacemaker::Resource::Primitive was being mocked to return true. The fix requires re-invoking Pacemaker::CIBObject.from_name after attempting to create the new primitive, so that cib_object.exists? accurately reflects whether the creation succeeded. However, testing this required mocking Mixlib::Shellout#stdout to first return "" and then secondly a definition string for the created resource, and unfortunately this exposed a nasty bug in rspec-mocks: https://github.com/rspec/rspec-mocks/issues/559 So we revamp the mocking of Mixlib::Shellout#stdout to use doubles instead of #expect_any_instance_of.
119 lines
3.3 KiB
Ruby
119 lines
3.3 KiB
Ruby
require 'spec_helper'
|
|
require File.expand_path('../../../../libraries/pacemaker/resource/primitive',
|
|
File.dirname(__FILE__))
|
|
require File.expand_path('../../../fixtures/keystone_primitive',
|
|
File.dirname(__FILE__))
|
|
require File.expand_path('../../../helpers/cib_object',
|
|
File.dirname(__FILE__))
|
|
require File.expand_path('../../../helpers/meta_examples',
|
|
File.dirname(__FILE__))
|
|
|
|
describe Pacemaker::Resource::Primitive do
|
|
let(:fixture) { Chef::RSpec::Pacemaker::Config::KEYSTONE_PRIMITIVE.dup }
|
|
let(:fixture_definition) {
|
|
Chef::RSpec::Pacemaker::Config::KEYSTONE_PRIMITIVE_DEFINITION
|
|
}
|
|
|
|
def object_type
|
|
'primitive'
|
|
end
|
|
|
|
def pacemaker_object_class
|
|
Pacemaker::Resource::Primitive
|
|
end
|
|
|
|
def fields
|
|
%w(name agent params_string meta_string op_string)
|
|
end
|
|
|
|
it_should_behave_like "a CIB object"
|
|
|
|
describe "#params_string" do
|
|
it "should return empty string with nil params" do
|
|
fixture.params = nil
|
|
expect(fixture.params_string).to eq("")
|
|
end
|
|
|
|
it "should return empty string with empty params" do
|
|
fixture.params = {}
|
|
expect(fixture.params_string).to eq("")
|
|
end
|
|
|
|
it "should return a resource params string" do
|
|
fixture.params = {
|
|
"foo" => "bar",
|
|
"baz" => "qux",
|
|
}
|
|
expect(fixture.params_string).to eq(%'params baz="qux" foo="bar"')
|
|
end
|
|
end
|
|
|
|
describe "#op_string" do
|
|
it "should return empty string with nil op" do
|
|
fixture.op = nil
|
|
expect(fixture.op_string).to eq("")
|
|
end
|
|
|
|
it "should return empty string with empty op" do
|
|
fixture.op = {}
|
|
expect(fixture.op_string).to eq("")
|
|
end
|
|
|
|
it "should return a resource op string" do
|
|
fixture.op = {
|
|
"monitor" => {
|
|
"foo" => "bar",
|
|
"baz" => "qux",
|
|
}
|
|
}
|
|
expect(fixture.op_string).to eq(%'op monitor baz="qux" foo="bar"')
|
|
end
|
|
end
|
|
|
|
it_should_behave_like "with meta attributes"
|
|
|
|
describe "#definition_string" 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 "#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
|
|
before(:each) do
|
|
@parsed = Pacemaker::Resource::Primitive.new(fixture.name)
|
|
@parsed.definition = fixture_definition
|
|
@parsed.parse_definition
|
|
end
|
|
|
|
it "should parse the agent" do
|
|
expect(@parsed.agent).to eq(fixture.agent)
|
|
end
|
|
end
|
|
end
|