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 and acceptance tests for new cs_clone resource parameters

Write documentation about promotable clones
  • Loading branch information
Maarten Beeckmans committed Apr 12, 2023
1 parent 81243e8 commit a0bc5c7
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 23 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,22 @@ cs_clone { 'nginx_service-clone' :
}
```
Configure a Promotable (Active/Passive) resource
```puppet
cs_clone { 'redis-clone':
ensure => present,
primitive => 'redis',
clone_max => 2,
clone_node_max => 1,
promotable => true,
promoted_max => 1,
promoted_node_max => 1,
notify_clones => true,
}
```
### Corosync Properties
A few global settings can be changed with the "cs_property" section.
Expand Down
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
92 changes: 76 additions & 16 deletions spec/acceptance/cs_clone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,17 @@ def fetch_value_command(name)
it 'creates the clone' do
pp = <<-EOS
cs_clone { 'duncan_vip_complex_clone_#{type}':
ensure => present,
#{type} => '#{property_value}',
clone_max => 42,
notify_clones => false,
clone_node_max => 2,
globally_unique => true,
ordered => false,
interleave => false,
ensure => present,
#{type} => '#{property_value}',
clone_max => 42,
notify_clones => false,
clone_node_max => 2,
globally_unique => true,
ordered => false,
interleave => false,
promotable => false,
promoted_max => 5,
promoted_node_max => 2,
}
EOS
apply_manifest(pp, catch_failures: true, debug: false, trace: true)
Expand Down Expand Up @@ -172,17 +175,38 @@ def fetch_value_command(name)
end
end

it 'sets promotable' do
shell(fetch_value_command('promotable')) do |r|
expect(r.stdout).to match(%r{value="false"})
end
end

it 'sets promoted_max' do
shell(fetch_value_command('promoted-max')) do |r|
expect(r.stdout).to match(%r{value="5"})
end
end

it 'sets promoted_node_max' do
shell(fetch_value_command('promoted-node-max')) do |r|
expect(r.stdout).to match(%r{value="2"})
end
end

it 'changes the clone' do
pp = <<-EOS
cs_clone { 'duncan_vip_complex_clone_#{type}':
ensure => present,
#{type} => '#{property_value}',
clone_max => 43,
clone_node_max => 1,
notify_clones => true,
globally_unique => false,
ordered => true,
interleave => true,
ensure => present,
#{type} => '#{property_value}',
clone_max => 43,
clone_node_max => 1,
notify_clones => true,
globally_unique => false,
ordered => true,
interleave => true,
promotable => true,
promoted_max => 6,
promoted_node_max => 1,
}
EOS
apply_manifest(pp, catch_failures: true, debug: false, trace: true)
Expand Down Expand Up @@ -229,6 +253,24 @@ def fetch_value_command(name)
end
end

it 'sets promotable' do
shell(fetch_value_command('promotable')) do |r|
expect(r.stdout).to match(%r{value="true"})
end
end

it 'sets promoted_max' do
shell(fetch_value_command('promoted-max')) do |r|
expect(r.stdout).to match(%r{value="6"})
end
end

it 'sets promoted_node_max' do
shell(fetch_value_command('promoted-node-max')) do |r|
expect(r.stdout).to match(%r{value="1"})
end
end

it 'removes some parameters' do
pp = <<-EOS
cs_clone { 'duncan_vip_complex_clone_#{type}':
Expand Down Expand Up @@ -281,6 +323,24 @@ def fetch_value_command(name)
expect(r.stdout).to match(%r{value="true"})
end
end

it 'deletes promotable' do
assert_raises(Beaker::Host::CommandFailure) do
shell(fetch_value_command('promotable'))
end
end

it 'deletes promoted-max' do
assert_raises(Beaker::Host::CommandFailure) do
shell(fetch_value_command('promoted-max'))
end
end

it 'deletes promoted-node-max' do
assert_raises(Beaker::Host::CommandFailure) do
shell(fetch_value_command('promoted-node-max'))
end
end
end
# rubocop:enable RSpec/RepeatedExample
end
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 a0bc5c7

Please sign in to comment.