implement Pacemaker::Resource::Clone
This commit is contained in:
@@ -1,9 +1,34 @@
|
|||||||
require File.expand_path('../resource', File.dirname(__FILE__))
|
require File.expand_path('../resource', File.dirname(__FILE__))
|
||||||
|
require File.expand_path('../mixins/resource_meta', File.dirname(__FILE__))
|
||||||
|
|
||||||
class Pacemaker::Resource::Clone < Pacemaker::Resource
|
class Pacemaker::Resource::Clone < Pacemaker::Resource
|
||||||
TYPE = 'clone'
|
TYPE = 'clone'
|
||||||
register_type TYPE
|
register_type TYPE
|
||||||
|
|
||||||
attr_accessor :primitive
|
include Pacemaker::Mixins::Resource::Meta
|
||||||
|
|
||||||
|
attr_accessor :rsc
|
||||||
|
|
||||||
|
def self.attrs_to_copy_from_chef
|
||||||
|
%w(rsc meta)
|
||||||
|
end
|
||||||
|
|
||||||
|
def definition_string
|
||||||
|
str = "#{TYPE} #{name} #{rsc}"
|
||||||
|
unless meta.empty?
|
||||||
|
str << continuation_line(meta_string)
|
||||||
|
end
|
||||||
|
str
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_definition
|
||||||
|
unless definition =~ /^#{TYPE} (\S+) (\S+)/
|
||||||
|
raise Pacemaker::CIBObject::DefinitionParseError, \
|
||||||
|
"Couldn't parse definition '#{definition}'"
|
||||||
|
end
|
||||||
|
self.name = $1
|
||||||
|
self.rsc = $2
|
||||||
|
self.meta = self.class.extract_hash(definition, 'meta')
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
20
spec/fixtures/clone_resource.rb
vendored
20
spec/fixtures/clone_resource.rb
vendored
@@ -1,14 +1,20 @@
|
|||||||
require ::File.expand_path('../../libraries/pacemaker/resource/clone',
|
require File.expand_path('../../libraries/pacemaker/resource/clone',
|
||||||
::File.dirname(__FILE__))
|
File.dirname(__FILE__))
|
||||||
require ::File.expand_path('keystone_primitive', ::File.dirname(__FILE__))
|
|
||||||
|
|
||||||
module Chef::RSpec
|
module Chef::RSpec
|
||||||
module Pacemaker
|
module Pacemaker
|
||||||
module Config
|
module Config
|
||||||
include Chef::RSpec::Pacemaker::Config
|
CLONE_RESOURCE = ::Pacemaker::Resource::Clone.new('clone1')
|
||||||
|
CLONE_RESOURCE.rsc = 'primitive1'
|
||||||
CLONE = ::Pacemaker::Resource::Clone.new('clone1')
|
CLONE_RESOURCE.meta = [
|
||||||
CLONE.primitive = KEYSTONE
|
[ "globally-unique", "true" ],
|
||||||
|
[ "clone-max", "2" ],
|
||||||
|
[ "clone-node-max", "2" ]
|
||||||
|
]
|
||||||
|
CLONE_RESOURCE_DEFINITION = <<'EOF'.chomp
|
||||||
|
clone clone1 primitive1 \
|
||||||
|
meta clone-max="2" clone-node-max="2" globally-unique="true"
|
||||||
|
EOF
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
63
spec/libraries/pacemaker/resource/clone_spec.rb
Normal file
63
spec/libraries/pacemaker/resource/clone_spec.rb
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
require File.expand_path('../../../../libraries/pacemaker/resource/clone',
|
||||||
|
File.dirname(__FILE__))
|
||||||
|
require File.expand_path('../../../fixtures/clone_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::Clone do
|
||||||
|
let(:fixture) { Chef::RSpec::Pacemaker::Config::CLONE_RESOURCE.dup }
|
||||||
|
let(:fixture_definition) {
|
||||||
|
Chef::RSpec::Pacemaker::Config::CLONE_RESOURCE_DEFINITION
|
||||||
|
}
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
Mixlib::ShellOut.any_instance.stub(:run_command)
|
||||||
|
end
|
||||||
|
|
||||||
|
def object_type
|
||||||
|
'clone'
|
||||||
|
end
|
||||||
|
|
||||||
|
def pacemaker_object_class
|
||||||
|
Pacemaker::Resource::Clone
|
||||||
|
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
|
||||||
|
clone = Pacemaker::Resource::Clone.new('foo')
|
||||||
|
clone.definition = \
|
||||||
|
%!clone clone1 primitive1 meta globally-unique="true"!
|
||||||
|
clone.parse_definition
|
||||||
|
expect(clone.definition_string).to eq(<<'EOF'.chomp)
|
||||||
|
clone clone1 primitive1 \
|
||||||
|
meta globally-unique="true"
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#parse_definition" do
|
||||||
|
before(:each) do
|
||||||
|
@parsed = Pacemaker::Resource::Clone.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
|
Reference in New Issue
Block a user