Skip to content

Commit

Permalink
Merge pull request #532 from maartenbeeckmans/master
Browse files Browse the repository at this point in the history
Make promotable resources configurable with cs_clone
  • Loading branch information
bastelfreak authored Apr 8, 2024
2 parents db4c373 + 8a3d093 commit 92ab3b5
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 56 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,21 @@ 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
25 changes: 25 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,31 @@ Default value: `absent`

The corosync resource primitive to be cloned.

##### `promotable`

Valid values: `true`, `false`, `absent`

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

Default value: `absent`

##### `promoted_max`

Valid values: `%r{\d+}`, `absent`

If promotable is true, the number of instances that can be promoted at one time across the entire cluster

Default value: `absent`

##### `promoted_node_max`

Valid values: `%r{\d+}`, `absent`

If promotable is true and globally-unique is false, the number of clone instances can be promoted at one time on a single node

Default value: `absent`

#### Parameters

The following parameters are available in the `cs_clone` type.
Expand Down
47 changes: 28 additions & 19 deletions lib/puppet/provider/cs_clone/crm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,17 @@ def self.instances
items = nvpairs_to_hash(e.elements['meta_attributes'])

clone_instance = {
name: e.attributes['id'],
ensure: :present,
clone_max: items['clone-max'],
clone_node_max: items['clone-node-max'],
notify_clones: items['notify'],
globally_unique: items['globally-unique'],
ordered: items['ordered'],
interleave: items['interleave'],
name: e.attributes['id'],
ensure: :present,
clone_max: items['clone-max'],
clone_node_max: items['clone-node-max'],
notify_clones: items['notify'],
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 All @@ -56,16 +59,19 @@ def self.instances
# of actually doing the work.
def create
@property_hash = {
name: @resource[:name],
ensure: :present,
primitive: @resource[:primitive],
clone_max: @resource[:clone_max],
clone_node_max: @resource[:clone_node_max],
notify_clones: @resource[:notify_clones],
globally_unique: @resource[:globally_unique],
ordered: @resource[:ordered],
interleave: @resource[:interleave],
cib: @resource[:cib],
name: @resource[:name],
ensure: :present,
primitive: @resource[:primitive],
clone_max: @resource[:clone_max],
clone_node_max: @resource[:clone_node_max],
notify_clones: @resource[:notify_clones],
globally_unique: @resource[:globally_unique],
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 @@ -104,7 +110,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
47 changes: 28 additions & 19 deletions lib/puppet/provider/cs_clone/pcs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ def self.instances
items = nvpairs_to_hash(e.elements['meta_attributes'])

clone_instance = {
name: e.attributes['id'],
ensure: :present,
clone_max: items['clone-max'],
clone_node_max: items['clone-node-max'],
notify_clones: items['notify'],
globally_unique: items['globally-unique'],
ordered: items['ordered'],
interleave: items['interleave']
name: e.attributes['id'],
ensure: :present,
clone_max: items['clone-max'],
clone_node_max: items['clone-node-max'],
notify_clones: items['notify'],
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']
}

if e.elements['primitive']
Expand All @@ -76,16 +79,19 @@ def self.instances
# of actually doing the work.
def create
@property_hash = {
name: @resource[:name],
ensure: :present,
primitive: @resource[:primitive],
group: @resource[:group],
clone_max: @resource[:clone_max],
clone_node_max: @resource[:clone_node_max],
notify_clones: @resource[:notify_clones],
globally_unique: @resource[:globally_unique],
ordered: @resource[:ordered],
interleave: @resource[:interleave]
name: @resource[:name],
ensure: :present,
primitive: @resource[:primitive],
group: @resource[:group],
clone_max: @resource[:clone_max],
clone_node_max: @resource[:clone_node_max],
notify_clones: @resource[:notify_clones],
globally_unique: @resource[:globally_unique],
ordered: @resource[:ordered],
interleave: @resource[:interleave],
promotable: @resource[:promotable],
promoted_max: @resource[:promoted_max],
promoted_node_max: @resource[:promoted_node_max]
}
end

Expand Down Expand Up @@ -128,7 +134,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 @@ -78,6 +78,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 @@ -120,14 +120,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 @@ -178,17 +181,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 @@ -235,6 +259,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 @@ -287,6 +329,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 @@ -193,5 +193,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 @@ -178,6 +178,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[:promoted_max] = 3
expect_commands(%r{promoted-max=3})
instance.flush
end

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

context 'when changing clone id' do
Expand Down
Loading

0 comments on commit 92ab3b5

Please sign in to comment.