implement Pacemaker::Resource::MasterSlave

This commit is contained in:
Adam Spiers
2014-03-14 10:03:28 +00:00
parent 35bc3a4ceb
commit 821971c8a4
4 changed files with 96 additions and 0 deletions

View File

@@ -2,5 +2,6 @@ this_dir = File.dirname(__FILE__)
require File.expand_path('pacemaker/resource/primitive', this_dir)
require File.expand_path('pacemaker/resource/clone', this_dir)
require File.expand_path('pacemaker/resource/ms', this_dir)
require File.expand_path('pacemaker/resource/group', this_dir)
require File.expand_path('pacemaker/constraint/colocation', this_dir)

View File

@@ -0,0 +1,10 @@
require File.expand_path('clone', File.dirname(__FILE__))
class Pacemaker::Resource::MasterSlave < Pacemaker::Resource::Clone
TYPE = 'ms'
register_type TYPE
#include Pacemaker::Mixins::Resource::Meta
attr_accessor :rsc
end

22
spec/fixtures/ms_resource.rb vendored Normal file
View File

@@ -0,0 +1,22 @@
require File.expand_path('../../libraries/pacemaker/resource/ms',
File.dirname(__FILE__))
module Chef::RSpec
module Pacemaker
module Config
MS_RESOURCE = ::Pacemaker::Resource::MasterSlave.new('ms1')
MS_RESOURCE.rsc = 'primitive1'
MS_RESOURCE.meta = [
[ "globally-unique", "true" ],
[ "clone-max", "2" ],
[ "clone-node-max", "2" ],
[ "master-max", "1" ],
[ "master-node-max", "1" ]
]
MS_RESOURCE_DEFINITION = <<'EOF'.chomp
ms ms1 primitive1 \
meta clone-max="2" clone-node-max="2" globally-unique="true" master-max="1" master-node-max="1"
EOF
end
end
end

View File

@@ -0,0 +1,63 @@
require 'spec_helper'
require File.expand_path('../../../../libraries/pacemaker/resource/ms',
File.dirname(__FILE__))
require File.expand_path('../../../fixtures/ms_resource', 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::MasterSlave do
let(:fixture) { Chef::RSpec::Pacemaker::Config::MS_RESOURCE.dup }
let(:fixture_definition) {
Chef::RSpec::Pacemaker::Config::MS_RESOURCE_DEFINITION
}
before(:each) do
Mixlib::ShellOut.any_instance.stub(:run_command)
end
def object_type
'ms'
end
def pacemaker_object_class
Pacemaker::Resource::MasterSlave
end
def fields
%w(name rsc)
end
it_should_behave_like "a CIB object"
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
ms = Pacemaker::Resource::MasterSlave.new('foo')
ms.definition = \
%!ms ms1 primitive1 meta globally-unique="true"!
ms.parse_definition
expect(ms.definition_string).to eq(<<'EOF'.chomp)
ms ms1 primitive1 \
meta globally-unique="true"
EOF
end
end
describe "#parse_definition" do
before(:each) do
@parsed = Pacemaker::Resource::MasterSlave.new(fixture.name)
@parsed.definition = fixture_definition
@parsed.parse_definition
end
it "should parse the rsc" do
expect(@parsed.rsc).to eq(fixture.rsc)
end
end
end