move extract_hash to Pacemaker::Resource
It is needed by the imminent Pacemaker::Resource::Group, not just by Pacemaker::Resource::Primitive.
This commit is contained in:
parent
8607295e05
commit
ac1f930681
@ -24,5 +24,31 @@ module Pacemaker
|
|||||||
"crm resource stop '#{name}'"
|
"crm resource stop '#{name}'"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# CIB object definitions look something like:
|
||||||
|
#
|
||||||
|
# primitive keystone ocf:openstack:keystone \
|
||||||
|
# params os_username="crowbar" os_password="crowbar" os_tenant_name="openstack" \
|
||||||
|
# meta target-role="Started" is-managed="true" \
|
||||||
|
# op monitor interval="10" timeout=30s \
|
||||||
|
# op start interval="10s" timeout="240" \
|
||||||
|
#
|
||||||
|
# This method extracts a Hash from one of the params / meta / op lines.
|
||||||
|
def self.extract_hash(obj_definition, data_type)
|
||||||
|
unless obj_definition =~ /\s+#{data_type} (.+?)\s*\\?$/
|
||||||
|
return {}
|
||||||
|
end
|
||||||
|
|
||||||
|
h = {}
|
||||||
|
Shellwords.split($1).each do |kvpair|
|
||||||
|
break if kvpair == 'op'
|
||||||
|
unless kvpair =~ /^(.+?)=(.+)$/
|
||||||
|
raise "Couldn't understand '#{kvpair}' for '#{data_type}' section "\
|
||||||
|
"of #{name} primitive (definition was [#{obj_definition}])"
|
||||||
|
end
|
||||||
|
h[$1] = $2.sub(/^"(.*)"$/, "\1")
|
||||||
|
end
|
||||||
|
h
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -96,30 +96,4 @@ class Pacemaker::Resource::Primitive < Pacemaker::Resource
|
|||||||
end.compact.join(' ')
|
end.compact.join(' ')
|
||||||
end
|
end
|
||||||
|
|
||||||
# CIB object definitions look something like:
|
|
||||||
#
|
|
||||||
# primitive keystone ocf:openstack:keystone \
|
|
||||||
# params os_username="crowbar" os_password="crowbar" os_tenant_name="openstack" \
|
|
||||||
# meta target-role="Started" is-managed="true" \
|
|
||||||
# op monitor interval="10" timeout=30s \
|
|
||||||
# op start interval="10s" timeout="240" \
|
|
||||||
#
|
|
||||||
# This method extracts a Hash from one of the params / meta / op lines.
|
|
||||||
def self.extract_hash(obj_definition, data_type)
|
|
||||||
unless obj_definition =~ /\s+#{data_type} (.+?)\s*\\?$/
|
|
||||||
return {}
|
|
||||||
end
|
|
||||||
|
|
||||||
h = {}
|
|
||||||
Shellwords.split($1).each do |kvpair|
|
|
||||||
break if kvpair == 'op'
|
|
||||||
unless kvpair =~ /^(.+?)=(.+)$/
|
|
||||||
raise "Couldn't understand '#{kvpair}' for '#{data_type}' section "\
|
|
||||||
"of #{name} primitive (definition was [#{obj_definition}])"
|
|
||||||
end
|
|
||||||
h[$1] = $2.sub(/^"(.*)"$/, "\1")
|
|
||||||
end
|
|
||||||
h
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -89,23 +89,6 @@ describe Pacemaker::Resource::Primitive do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "::extract_hash" do
|
|
||||||
it "should extract a params hash from config" do
|
|
||||||
expect(fixture.class.extract_hash(fixture.definition_string, "params")).to \
|
|
||||||
eq(Hash[fixture.params])
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should extract an op start hash from config" do
|
|
||||||
expect(fixture.class.extract_hash(fixture.definition_string, 'op start')).to \
|
|
||||||
eq(Hash[fixture.op]['start'])
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should extract an op monitor hash from config" do
|
|
||||||
expect(fixture.class.extract_hash(fixture.definition_string, 'op monitor')).to \
|
|
||||||
eq(Hash[fixture.op]['monitor'])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#definition_string" do
|
describe "#definition_string" do
|
||||||
it "should return the definition string" do
|
it "should return the definition string" do
|
||||||
expect(fixture.definition_string).to eq(fixture_definition)
|
expect(fixture.definition_string).to eq(fixture_definition)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
require File.expand_path('../../../libraries/pacemaker/resource',
|
require File.expand_path('../../../libraries/pacemaker/resource',
|
||||||
File.dirname(__FILE__))
|
File.dirname(__FILE__))
|
||||||
|
require File.expand_path('../../fixtures/keystone_primitive',
|
||||||
|
File.dirname(__FILE__))
|
||||||
|
|
||||||
describe Pacemaker::Resource do
|
describe Pacemaker::Resource do
|
||||||
describe "#running?" do
|
describe "#running?" do
|
||||||
@ -25,4 +27,23 @@ describe Pacemaker::Resource do
|
|||||||
expect(rsc.running?).to be(false)
|
expect(rsc.running?).to be(false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "::extract_hash" do
|
||||||
|
let(:fixture) { Chef::RSpec::Pacemaker::Config::KEYSTONE_PRIMITIVE.dup }
|
||||||
|
|
||||||
|
it "should extract a params hash from config" do
|
||||||
|
expect(fixture.class.extract_hash(fixture.definition_string, "params")).to \
|
||||||
|
eq(Hash[fixture.params])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should extract an op start hash from config" do
|
||||||
|
expect(fixture.class.extract_hash(fixture.definition_string, 'op start')).to \
|
||||||
|
eq(Hash[fixture.op]['start'])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should extract an op monitor hash from config" do
|
||||||
|
expect(fixture.class.extract_hash(fixture.definition_string, 'op monitor')).to \
|
||||||
|
eq(Hash[fixture.op]['monitor'])
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user