implement Pacemaker::Resource::Clone

This commit is contained in:
Adam Spiers
2014-03-03 15:33:03 +00:00
parent 47fc1d74a2
commit b16805872c
3 changed files with 102 additions and 8 deletions

View File

@@ -1,9 +1,34 @@
require File.expand_path('../resource', File.dirname(__FILE__))
require File.expand_path('../mixins/resource_meta', File.dirname(__FILE__))
class Pacemaker::Resource::Clone < Pacemaker::Resource
TYPE = 'clone'
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

View File

@@ -1,14 +1,20 @@
require ::File.expand_path('../../libraries/pacemaker/resource/clone',
::File.dirname(__FILE__))
require ::File.expand_path('keystone_primitive', ::File.dirname(__FILE__))
require File.expand_path('../../libraries/pacemaker/resource/clone',
File.dirname(__FILE__))
module Chef::RSpec
module Pacemaker
module Config
include Chef::RSpec::Pacemaker::Config
CLONE = ::Pacemaker::Resource::Clone.new('clone1')
CLONE.primitive = KEYSTONE
CLONE_RESOURCE = ::Pacemaker::Resource::Clone.new('clone1')
CLONE_RESOURCE.rsc = 'primitive1'
CLONE_RESOURCE.meta = [
[ "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

View 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