implement Pacemaker::Constraint::Order
This commit is contained in:
31
libraries/pacemaker/constraint/order.rb
Normal file
31
libraries/pacemaker/constraint/order.rb
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
require File.expand_path('../constraint', File.dirname(__FILE__))
|
||||||
|
|
||||||
|
class Pacemaker::Constraint::Order < Pacemaker::Constraint
|
||||||
|
TYPE = 'order'
|
||||||
|
register_type TYPE
|
||||||
|
|
||||||
|
attr_accessor :score, :ordering
|
||||||
|
|
||||||
|
def self.attrs_to_copy_from_chef
|
||||||
|
%w(score ordering)
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_definition
|
||||||
|
# FIXME: add support for symmetrical=<bool>
|
||||||
|
# Currently we take the easy way out and don't bother parsing the ordering.
|
||||||
|
# See the crm(8) man page for the official BNF grammar.
|
||||||
|
score_regexp = %r{\d+|[-+]?inf|Mandatory|Optional|Serialize}
|
||||||
|
unless definition =~ /^#{self.class::TYPE} (\S+) (#{score_regexp}): (.+?)\s*$/
|
||||||
|
raise Pacemaker::CIBObject::DefinitionParseError, \
|
||||||
|
"Couldn't parse definition '#{definition}'"
|
||||||
|
end
|
||||||
|
self.name = $1
|
||||||
|
self.score = $2
|
||||||
|
self.ordering = $3
|
||||||
|
end
|
||||||
|
|
||||||
|
def definition_string
|
||||||
|
"#{self.class::TYPE} #{name} #{score}: #{ordering}"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
14
spec/fixtures/order_constraint.rb
vendored
Normal file
14
spec/fixtures/order_constraint.rb
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
require ::File.expand_path('../../libraries/pacemaker/constraint/order',
|
||||||
|
File.dirname(__FILE__))
|
||||||
|
|
||||||
|
module Chef::RSpec
|
||||||
|
module Pacemaker
|
||||||
|
module Config
|
||||||
|
ORDER_CONSTRAINT = \
|
||||||
|
::Pacemaker::Constraint::Order.new('order1')
|
||||||
|
ORDER_CONSTRAINT.score = 'Mandatory'
|
||||||
|
ORDER_CONSTRAINT.ordering = 'primitive1 clone1'
|
||||||
|
ORDER_CONSTRAINT_DEFINITION = 'order order1 Mandatory: primitive1 clone1'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
61
spec/libraries/pacemaker/constraint/order_spec.rb
Normal file
61
spec/libraries/pacemaker/constraint/order_spec.rb
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
this_dir = File.dirname(__FILE__)
|
||||||
|
require File.expand_path('../../../../libraries/pacemaker/constraint/order',
|
||||||
|
this_dir)
|
||||||
|
require File.expand_path('../../../fixtures/order_constraint', this_dir)
|
||||||
|
require File.expand_path('../../../helpers/cib_object', this_dir)
|
||||||
|
|
||||||
|
describe Pacemaker::Constraint::Order do
|
||||||
|
let(:fixture) { Chef::RSpec::Pacemaker::Config::ORDER_CONSTRAINT.dup }
|
||||||
|
let(:fixture_definition) {
|
||||||
|
Chef::RSpec::Pacemaker::Config::ORDER_CONSTRAINT_DEFINITION
|
||||||
|
}
|
||||||
|
|
||||||
|
def object_type
|
||||||
|
'order'
|
||||||
|
end
|
||||||
|
|
||||||
|
def pacemaker_object_class
|
||||||
|
Pacemaker::Constraint::Order
|
||||||
|
end
|
||||||
|
|
||||||
|
def fields
|
||||||
|
%w(name score ordering)
|
||||||
|
end
|
||||||
|
|
||||||
|
it_should_behave_like "a CIB object"
|
||||||
|
|
||||||
|
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
|
||||||
|
order = pacemaker_object_class.new('foo')
|
||||||
|
order.definition = \
|
||||||
|
%!order order1 Mandatory: rsc1 rsc2!
|
||||||
|
order.parse_definition
|
||||||
|
expect(order.definition_string).to eq(<<'EOF'.chomp)
|
||||||
|
order order1 Mandatory: rsc1 rsc2
|
||||||
|
EOF
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#parse_definition" do
|
||||||
|
before(:each) do
|
||||||
|
@parsed = pacemaker_object_class.new(fixture.name)
|
||||||
|
@parsed.definition = fixture_definition
|
||||||
|
@parsed.parse_definition
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should parse the score" do
|
||||||
|
expect(@parsed.score).to eq(fixture.score)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should parse the ordering" do
|
||||||
|
expect(@parsed.ordering).to eq(fixture.ordering)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue
Block a user