Skip to content

Commit

Permalink
Merge pull request #499 from b1-systems/os/debian10
Browse files Browse the repository at this point in the history
Support pcs 0.10 syntax and Debian family with `pcs`
  • Loading branch information
bastelfreak authored Jan 17, 2022
2 parents cd23c0a + 2603790 commit 5f48a6c
Show file tree
Hide file tree
Showing 31 changed files with 663 additions and 574 deletions.
13 changes: 0 additions & 13 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1387,19 +1387,6 @@ A hash of metadata for the master/slave primitive state.

Default value: Hash.new

##### `promotable`

Valid values: `true`, `false`

Designates if the primitive is capable of being managed in a master/slave
state. This will create a new ms resource in your Corosync config and add
this primitive to it. Concequently Corosync will be helpful and update all
your colocation and order resources too but Puppet won't. Currenlty we unmunge
configuraiton entries that start with ms_ so that you don't have to account for
name change in all our manifests.

Default value: false

#### Parameters

The following parameters are available in the `cs_primitive` type.
Expand Down
3 changes: 3 additions & 0 deletions data/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
corosync::package_fence_agents: false
corosync::qdevice::provider: "%{alias('corosync::provider')}"
3 changes: 3 additions & 0 deletions data/os/Debian.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
corosync::provider: 'pcs'
corosync::pcs_version: '0.10.0'
3 changes: 3 additions & 0 deletions data/os/Debian/9.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
corosync::provider: 'crm'
corosync::pcs_version: ~
4 changes: 4 additions & 0 deletions data/os/RedHat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
corosync::provider: 'pcs'
corosync::pcs_version: '0.10.0'
corosync::package_fence_agents: true
2 changes: 2 additions & 0 deletions data/os/RedHat/7.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
corosync::pcs_version: '0.9.0'
3 changes: 3 additions & 0 deletions data/os/SLES.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
corosync::provider: 'crm'
corosync::pcs_version: ~
3 changes: 3 additions & 0 deletions data/os/Ubuntu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
corosync::pcs_version: '0.10.0'
corosync::provider: 'pcs'
2 changes: 2 additions & 0 deletions data/os/Ubuntu/18.04.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
corosync::pcs_version: '0.9.0'
18 changes: 18 additions & 0 deletions hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: 5

defaults: # Used for any hierarchy level that omits these keys.
datadir: data # This path is relative to hiera.yaml's directory.
data_hash: yaml_data # Use the built-in YAML backend.

hierarchy:
- name: "osfamily/major release"
paths:
# Used to distinguish between Debian and Ubuntu
- "os/%{facts.os.name}/%{facts.os.release.major}.yaml"
- "os/%{facts.os.family}/%{facts.os.release.major}.yaml"
- name: "osfamily"
paths:
- "os/%{facts.os.name}.yaml"
- "os/%{facts.os.family}.yaml"
- name: 'common'
path: 'common.yaml'
2 changes: 1 addition & 1 deletion lib/puppet/provider/cs_location/pcs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def flush
cmd = [command(:pcs), 'constraint', 'remove', @resource[:name]]
self.class.run_command_in_cib(cmd, @resource[:cib], false)
unless @property_hash[:node_name].nil?
cmd = [command(:pcs), 'constraint', 'location', 'add', @property_hash[:name], @property_hash[:primitive], @property_hash[:node_name], @property_hash[:score]]
cmd = [command(:pcs), 'constraint', 'location', 'add', '--force', @property_hash[:name], @property_hash[:primitive], @property_hash[:node_name], @property_hash[:score]]
cmd << "resource-discovery=#{@property_hash[:resource_discovery]}" unless @property_hash[:resource_discovery].nil?
self.class.run_command_in_cib(cmd, @resource[:cib])
end
Expand Down
50 changes: 0 additions & 50 deletions lib/puppet/provider/cs_primitive/crm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def self.element_to_hash(e)
metadata: nvpairs_to_hash(e.elements['meta_attributes']),
existing_metadata: nvpairs_to_hash(e.elements['meta_attributes']),
ms_metadata: {},
promotable: :false
}

operations = e.elements['operations']
Expand All @@ -56,15 +55,6 @@ def self.element_to_hash(e)
hash[:operations] << operation
end
end
if e.parent.name == 'master'
hash[:promotable] = :true
unless e.parent.elements['meta_attributes'].nil?
e.parent.elements['meta_attributes'].each_element do |m|
hash[:ms_metadata][m.attributes['name']] = m.attributes['value']
end
end
hash[:existing_ms_metadata] = hash[:ms_metadata].dup
end

hash
end
Expand Down Expand Up @@ -93,13 +83,11 @@ def create
primitive_class: @resource[:primitive_class],
provided_by: @resource[:provided_by],
primitive_type: @resource[:primitive_type],
promotable: @resource[:promotable]
}
@property_hash[:parameters] = @resource[:parameters] unless @resource[:parameters].nil?
@property_hash[:operations] = @resource[:operations] unless @resource[:operations].nil?
@property_hash[:utilization] = @resource[:utilization] unless @resource[:utilization].nil?
@property_hash[:metadata] = @resource[:metadata] unless @resource[:metadata].nil?
@property_hash[:ms_metadata] = @resource[:ms_metadata] unless @resource[:ms_metadata].nil?
@property_hash[:cib] = @resource[:cib] unless @resource[:cib].nil?
end

Expand Down Expand Up @@ -134,14 +122,6 @@ def metadata
@property_hash[:metadata]
end

def ms_metadata
@property_hash[:ms_metadata]
end

def promotable
@property_hash[:promotable]
end

# Our setters for parameters and operations. Setters are used when the
# resource already exists so we just update the current value in the
# property_hash and doing this marks it to be flushed.
Expand All @@ -161,23 +141,6 @@ def metadata=(should)
@property_hash[:metadata] = should
end

def ms_metadata=(should)
@property_hash[:ms_metadata] = should
end

def promotable=(should)
case should
when :true
@property_hash[:promotable] = should
when :false
@property_hash[:promotable] = should
cmd = [command(:crm), 'resource', 'stop', "ms_#{@resource[:name]}"]
self.class.run_command_in_cib(cmd, @resource[:cib])
cmd = [command(:crm), 'configure', 'delete', "ms_#{@resource[:name]}"]
self.class.run_command_in_cib(cmd, @resource[:cib])
end
end

# Flush is triggered on anything that has been detected as being
# modified in the property_hash. It generates a temporary file with
# the updates that need to be made. The temporary file is then used
Expand All @@ -202,9 +165,6 @@ def flush
if @property_hash[:existing_metadata] && @property_hash[:existing_metadata][parameter_name]
@property_hash[:metadata][parameter_name] = @property_hash[:existing_metadata]['target-role']
end
if @property_hash[:existing_ms_metadata] && @property_hash[:existing_ms_metadata][parameter_name]
@property_hash[:ms_metadata][parameter_name] = @property_hash[:existing_ms_metadata]['target-role']
end
end
end
unless @property_hash[:parameters].empty?
Expand Down Expand Up @@ -233,16 +193,6 @@ def flush
updated << "#{parameters} " unless parameters.nil?
updated << "#{utilization} " unless utilization.nil?
updated << "#{metadatas} " unless metadatas.nil?
if @property_hash[:promotable] == :true
updated << "\n"
updated << "ms ms_#{@property_hash[:name]} #{@property_hash[:name]} "
unless @property_hash[:ms_metadata].empty?
updated << 'meta '
@property_hash[:ms_metadata].each_pair do |k, v|
updated << "#{k}=#{v} "
end
end
end
debug("Loading update: #{updated}")
Tempfile.open('puppet_crm_update') do |tmpfile|
tmpfile.write(updated)
Expand Down
74 changes: 6 additions & 68 deletions lib/puppet/provider/cs_primitive/pcs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,11 @@ def self.element_to_hash(e)
operations: [],
utilization: nvpairs_to_hash(e.elements['utilization']),
metadata: nvpairs_to_hash(e.elements['meta_attributes']),
ms_metadata: {},
promotable: :false,
existing_resource: :true,
existing_primitive_class: e.attributes['class'],
existing_primitive_type: e.attributes['type'],
existing_promotable: :false,
existing_provided_by: e.attributes['provider'],
existing_metadata: nvpairs_to_hash(e.elements['meta_attributes']),
existing_ms_metadata: {},
existing_operations: []
}

Expand All @@ -67,16 +63,6 @@ def self.element_to_hash(e)
hash[:existing_operations] << operation
end
end
if e.parent.name == 'master'
hash[:promotable] = :true
hash[:existing_promotable] = :true
unless e.parent.elements['meta_attributes'].nil?
e.parent.elements['meta_attributes'].each_element do |m|
hash[:ms_metadata][m.attributes['name']] = m.attributes['value']
end
hash[:existing_ms_metadata] = hash[:ms_metadata].dup
end
end

hash
end
Expand Down Expand Up @@ -117,14 +103,12 @@ def create
primitive_class: @resource[:primitive_class],
provided_by: @resource[:provided_by],
primitive_type: @resource[:primitive_type],
promotable: @resource[:promotable],
existing_resource: :false
}
@property_hash[:parameters] = @resource[:parameters] unless @resource[:parameters].nil?
@property_hash[:operations] = @resource[:operations] unless @resource[:operations].nil?
@property_hash[:utilization] = @resource[:utilization] unless @resource[:utilization].nil?
@property_hash[:metadata] = @resource[:metadata] unless @resource[:metadata].nil?
@property_hash[:ms_metadata] = @resource[:ms_metadata] unless @resource[:ms_metadata].nil?
@property_hash[:existing_metadata] = {}
end

Expand All @@ -136,16 +120,6 @@ def destroy
@property_hash.clear
end

def promotable=(should)
case should
when :true
@property_hash[:promotable] = should
when :false
@property_hash[:promotable] = should
self.class.run_command_in_cib([command(:pcs), 'resource', 'delete', "ms_#{@resource[:name]}"], @resource[:cib])
end
end

# Performs a subset of flush operations which are relevant only to stonith
# resources. Non stonith resources will never call this method.
#
Expand Down Expand Up @@ -229,39 +203,18 @@ def _flush_resource(operations, parameters, utilization, metadatas)
end

if @property_hash[:existing_resource] == :false || force_reinstall == :true
cmd = if Facter.value(:osfamily) == 'RedHat' && Facter.value(:operatingsystemmajrelease).to_s == '7'
[command(:pcs), pcs_subcommand, 'create', '--force', '--no-default-ops', (@property_hash[:name]).to_s]
else
cmd = [command(:pcs), pcs_subcommand, 'create', '--force', (@property_hash[:name]).to_s]
end
cmd = [command(:pcs), pcs_subcommand, 'create', '--force', '--no-default-ops', (@property_hash[:name]).to_s]
cmd << resource_type
cmd += parameters unless parameters.nil?
cmd += operations unless operations.nil?
cmd += utilization unless utilization.nil?
cmd += metadatas unless metadatas.nil?
self.class.run_command_in_cib(cmd, @resource[:cib])
# if we are using a master/slave resource, prepend ms_ before its name
# and declare it as a master/slave resource
if @property_hash[:promotable] == :true
cmd = [command(:pcs), pcs_subcommand, 'master', "ms_#{@property_hash[:name]}", (@property_hash[:name]).to_s]
unless @property_hash[:ms_metadata].empty?
cmd << 'meta'
@property_hash[:ms_metadata].each_pair do |k, v|
cmd << "#{k}=#{v}"
end
end
self.class.run_command_in_cib(cmd, @resource[:cib])
end
# try to remove the default monitor operation
default_op = { 'monitor' => { 'interval' => '60s' } }
unless @property_hash[:operations].include?(default_op)
cmd = [command(:pcs), pcs_subcommand, 'op', 'remove', (@property_hash[:name]).to_s, 'monitor', 'interval=60s']
self.class.run_command_in_cib(cmd, @resource[:cib], false)
end
# default_op = { 'monitor' => { 'interval' => '60s' } }
# unless @property_hash[:operations].include?(default_op)
# cmd = [command(:pcs), pcs_subcommand, 'op', 'remove', (@property_hash[:name]).to_s, 'monitor', 'interval=60s']
# end
self.class.run_command_in_cib(cmd, @resource[:cib], false)
else
if @property_hash[:promotable] == :false && @property_hash[:existing_promotable] == :true
self.class.run_command_in_cib([command(:pcs), pcs_subcommand, 'delete', '--force', "ms_#{@property_hash[:name]}"], @resource[:cib])
end
@property_hash[:existing_operations].reject { |op| @property_hash[:operations].include?(op) }.each do |o|
cmd = [command(:pcs), pcs_subcommand, 'op', 'remove', (@property_hash[:name]).to_s]
cmd << o.keys.first.to_s
Expand All @@ -276,19 +229,6 @@ def _flush_resource(operations, parameters, utilization, metadatas)
cmd += utilization unless utilization.nil?
cmd += metadatas unless metadatas.nil?
self.class.run_command_in_cib(cmd, @resource[:cib])
if @property_hash[:promotable] == :true
cmd = [command(:pcs), pcs_subcommand, 'update', "ms_#{@property_hash[:name]}"]
unless @property_hash[:ms_metadata].empty? && @property_hash[:existing_ms_metadata].empty?
cmd << 'meta'
@property_hash[:ms_metadata].each_pair do |k, v|
cmd << "#{k}=#{v}"
end
@property_hash[:existing_ms_metadata].keys.reject { |key| @property_hash[:ms_metadata].key?(key) }.each do |k|
cmd << "#{k}="
end
end
self.class.run_command_in_cib(cmd, @resource[:cib])
end
end
end

Expand Down Expand Up @@ -332,8 +272,6 @@ def flush
if @resource && @resource.class.name == :cs_primitive && @resource[:unmanaged_metadata]
@resource[:unmanaged_metadata].each do |parameter_name|
@property_hash[:metadata].delete(parameter_name)
@property_hash[:ms_metadata].delete(parameter_name) if @property_hash[:ms_metadata]
@property_hash[:existing_ms_metadata].delete(parameter_name) if @property_hash[:existing_ms_metadata]
@property_hash[:existing_metadata].delete(parameter_name) if @property_hash[:existing_metadata]
end
end
Expand Down
56 changes: 0 additions & 56 deletions lib/puppet/type/cs_primitive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,62 +243,6 @@ def change_to_s(currentvalue, newvalue)
# rubocop:enable Style/EmptyLiteral
end

newproperty(:ms_metadata) do
desc 'A hash of metadata for the master/slave primitive state.'

munge do |value_hash|
# Ruby 1.8.7 does not support each_with_object
# rubocop:disable Style/EachWithObject
value_hash.reduce({}) do |memo, (key, value)|
# rubocop:enable Style/EachWithObject
memo[key] = String(value)
memo
end
end

def insync?(is)
super(is.reject { |k| @resource[:unmanaged_metadata].include?(k) })
end

# rubocop:disable Style/PredicateName
def is_to_s(is)
# rubocop:enable Style/PredicateName
super(is.reject { |k| @resource[:unmanaged_metadata].include?(k) })
end

def should_to_s(should)
super(should.reject { |k| @resource[:unmanaged_metadata].include?(k) })
end

def change_to_s(currentvalue, newvalue)
if @resource[:unmanaged_metadata].count.zero?
super
else
super + " (unmanaged parameters: #{@resource[:unmanaged_metadata].join(', ')})"
end
end

validate do |value|
raise Puppet::Error, 'Puppet::Type::Cs_Primitive: ms_metadata property must be a hash' unless value.is_a? Hash
end
# rubocop:disable Style/EmptyLiteral
defaultto Hash.new
# rubocop:enable Style/EmptyLiteral
end

newproperty(:promotable) do
desc "Designates if the primitive is capable of being managed in a master/slave
state. This will create a new ms resource in your Corosync config and add
this primitive to it. Concequently Corosync will be helpful and update all
your colocation and order resources too but Puppet won't. Currenlty we unmunge
configuraiton entries that start with ms_ so that you don't have to account for
name change in all our manifests."

newvalues(:true, :false)

defaultto :false
end

autorequire(:cs_shadow) do
autos = []
autos << @parameters[:cib].value if @parameters[:cib]
Expand Down
Loading

0 comments on commit 5f48a6c

Please sign in to comment.