Skip to content

Commit

Permalink
Make promotable resources configurable with cs_clone
Browse files Browse the repository at this point in the history
Add the attributes promotable, promoted_max and promoted_node_max to the
cs_clone resource.

Write unit tests for new cs_clone resource parameters
  • Loading branch information
Maarten Beeckmans committed Apr 12, 2023
1 parent 81243e8 commit c22873b
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 7 deletions.
11 changes: 10 additions & 1 deletion lib/puppet/provider/cs_clone/crm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def self.instances
globally_unique: items['globally-unique'],
ordered: items['ordered'],
interleave: items['interleave'],
promotable: items['promotable'],
promoted_max: items['promoted-max'],
promoted_node_max: items['promoted-node-max'],
existing_resource: :true
}

Expand Down Expand Up @@ -67,6 +70,9 @@ def create
ordered: @resource[:ordered],
interleave: @resource[:interleave],
cib: @resource[:cib],
promotable: @resource[:promotable],
promoted_max: @resource[:promoted_max],
promoted_node_max: @resource[:promoted_node_max],
existing_resource: :false
}
end
Expand Down Expand Up @@ -105,7 +111,10 @@ def flush
notify_clones: 'notify',
globally_unique: 'globally-unique',
ordered: 'ordered',
interleave: 'interleave'
interleave: 'interleave',
promotable: 'promotable',
promoted_max: 'promoted-max',
promoted_node_max: 'promoted-node-max'
}.each do |property, clone_property|
meta << "#{clone_property}=#{@resource.should(property)}" unless @resource.should(property) == :absent
end
Expand Down
15 changes: 12 additions & 3 deletions lib/puppet/provider/cs_clone/pcs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ def self.instances
notify_clones: items['notify'],
globally_unique: items['globally-unique'],
ordered: items['ordered'],
interleave: items['interleave']
interleave: items['interleave'],
promotable: items['promotable'],
promoted_max: items['promoted-max'],
promoted_node_max: items['promoted-node-max']
}

if e.elements['primitive']
Expand Down Expand Up @@ -82,7 +85,10 @@ def create
notify_clones: @resource[:notify_clones],
globally_unique: @resource[:globally_unique],
ordered: @resource[:ordered],
interleave: @resource[:interleave]
interleave: @resource[:interleave],
promotable: @resource[:promotable],
promoted_max: @resource[:promoted_max],
promoted_node_max: @resource[:promoted_node_max]
}
end

Expand Down Expand Up @@ -125,7 +131,10 @@ def flush
notify_clones: 'notify',
globally_unique: 'globally-unique',
ordered: 'ordered',
interleave: 'interleave'
interleave: 'interleave',
promotable: 'promotable',
promoted_max: 'promoted-max',
promoted_node_max: 'promoted-node-max'
}.each do |property, clone_property|
cmd << "#{clone_property}=#{@resource.should(property)}" unless @resource.should(property) == :absent
end
Expand Down
25 changes: 25 additions & 0 deletions lib/puppet/type/cs_clone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,31 @@
defaultto :absent
end

newproperty(:promotable) do
desc 'If true, clone instances can perform a special role that Pacemaker will manage via the resource agent’s
promote and demote actions. The resource agent must support these actions. Allowed values: false, true'

newvalues(:true, :false, :absent)

defaultto :absent
end

newproperty(:promoted_max) do
desc 'If promotable is true, the number of instances that can be promoted at one time across the entire cluster'

newvalues(%r{\d+}, :absent)

defaultto :absent
end

newproperty(:promoted_node_max) do
desc 'If promotable is true and globally-unique is false, the number of clone instances can be promoted at one time on a single node'

newvalues(%r{\d+}, :absent)

defaultto :absent
end

newparam(:cib) do
desc "Corosync applies its configuration immediately. Using a CIB allows
you to group multiple primitives and relationships to be applied at
Expand Down
18 changes: 18 additions & 0 deletions spec/unit/puppet/provider/cs_clone_crm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,23 @@ def expect_update(pattern)
expect_update(%r{\sinterleave=true})
instance.flush
end

it 'sets promotable' do
instance.resource[:interleave] = :true
expect_update(%r{\spromotable=true})
instance.flush
end

it 'sets max promoted' do
instance.resource[:promoted_max] = 3
expect_update(%r{\spromoted-max=3})
instance.flush
end

it 'sets max node promoted' do
instance.resource[:promoted_node_max] = 3
expect_update(%r{\spromoted-node-max=3})
instance.flush
end
end
end
18 changes: 18 additions & 0 deletions spec/unit/puppet/provider/cs_clone_pcs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,24 @@
expect_commands(%r{interleave=true})
instance.flush
end

it 'sets promotable' do
instance.resource[:promotable] = :true
expect_commands(%r{promotable=true})
instance.flush
end

it 'sets max promoted' do
instance.resource[:promotable_max] = 3
expect_commands(%r{promotable-max=3})
instance.flush
end

it 'sets max node promotable' do
instance.resource[:promotable_node_max] = 3
expect_commands(%r{promotable-node-max=3})
instance.flush
end
end

context 'when changing clone id' do
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/puppet/type/cs_clone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
end
end

[:primitive, :clone_max, :clone_node_max, :notify_clones, :globally_unique,
:ordered, :interleave].each do |property|
[:primitive, :clone_max, :clone_node_max, :notify_clones, :globally_unique, :ordered,
:interleave, :promotable, :promoted_max, :promoted_node_max].each do |property|
it "should have a #{property} property" do
expect(subject).to be_validproperty(property)
end
Expand All @@ -40,7 +40,7 @@
end

describe 'when validating attributes' do
[:notify_clones, :globally_unique, :ordered, :interleave].each do |attribute|
[:notify_clones, :globally_unique, :ordered, :interleave, :promotable].each do |attribute|
it "should validate that the #{attribute} attribute can be true/false" do
[true, false].each do |value|
expect(subject.new(
Expand Down

0 comments on commit c22873b

Please sign in to comment.