diff --git a/lib/puppet/provider/cs_primitive/crm.rb b/lib/puppet/provider/cs_primitive/crm.rb index 004a7fec..92e5039a 100644 --- a/lib/puppet/provider/cs_primitive/crm.rb +++ b/lib/puppet/provider/cs_primitive/crm.rb @@ -23,19 +23,26 @@ # for creating a new provider instance. def self.element_to_hash(e) hash = { - primitive_class: e.attributes['class'], - primitive_type: e.attributes['type'], - provided_by: e.attributes['provider'], - name: e.attributes['id'].to_sym, - ensure: :present, - provider: name, - parameters: nvpairs_to_hash(e.elements['instance_attributes']), - operations: [], - utilization: nvpairs_to_hash(e.elements['utilization']), - metadata: nvpairs_to_hash(e.elements['meta_attributes']), - existing_metadata: nvpairs_to_hash(e.elements['meta_attributes']), - ms_metadata: {}, - promotable: :false + primitive_class: e.attributes['class'], + primitive_type: e.attributes['type'], + provided_by: e.attributes['provider'], + name: e.attributes['id'].to_sym, + ensure: :present, + provider: name, + parameters: nvpairs_to_hash(e.elements['instance_attributes']), + 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: [] } operations = e.elements['operations'] diff --git a/spec/classes/corosync_qdevice_spec.rb b/spec/classes/corosync_qdevice_spec.rb index 66f88d51..6ac64d54 100644 --- a/spec/classes/corosync_qdevice_spec.rb +++ b/spec/classes/corosync_qdevice_spec.rb @@ -7,60 +7,75 @@ } end - context 'standard quorum node install' do - ['pcs', 'corosync-qnetd'].each do |package| - it "does install #{package}" do - is_expected.to contain_package(package).with( - ensure: 'present' - ) + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts.merge(os_specific_facts(facts)) end - end - it 'creates the cluster group' do - is_expected.to contain_group('haclient').that_requires('Package[pcs]') - end + provider_package = case facts[:default_provider] + when 'pcs' + 'pcs' + else + 'crmsh' + end - it 'sets the hacluster password' do - is_expected.to contain_user('hacluster').with( - ensure: 'present', - password: 'some-secret-hash', - gid: 'haclient' - ) - end + context 'standard quorum node install' do + [provider_package, 'corosync-qnetd'].each do |package| + it "does install #{package}" do + is_expected.to contain_package(package).with( + ensure: 'present' + ) + end + end - it 'configures the pcsd service' do - is_expected.to contain_service('pcsd').with( - ensure: 'running', - enable: 'true', - require: [ - 'Package[pcs]', - 'Package[corosync-qnetd]' - ] - ) - end + it 'creates the cluster group' do + is_expected.to contain_group('haclient').that_requires("Package[#{provider_package}]") + end - it 'configures the net quorum device' do - is_expected.to contain_exec('pcs qdevice setup model net --enable --start').with( - path: '/sbin:/bin:/usr/sbin:/usr/bin', - onlyif: [ - 'test ! -f /etc/corosync/qnetd/nssdb/qnetd-cacert.crt' - ], - require: 'Service[pcsd]' - ) - end + it 'sets the hacluster password' do + is_expected.to contain_user('hacluster').with( + ensure: 'present', + password: 'some-secret-hash', + gid: 'haclient' + ) + end + + it 'configures the pcsd service' do + is_expected.to contain_service('pcsd').with( + ensure: 'running', + enable: 'true', + require: [ + 'Package[pcs]', + 'Package[corosync-qnetd]' + ] + ) + end - it 'makes sure the net quorum device is started' do - is_expected.to contain_exec('pcs qdevice start net').with( - path: '/sbin:/bin:/usr/sbin:/usr/bin', - onlyif: [ - 'test -f /etc/corosync/qnetd/nssdb/qnetd-cacert.crt', - 'test 0 -ne $(pcs qdevice status net >/dev/null 2>&1; echo $?)' - ], - require: [ - 'Package[pcs]', - 'Package[corosync-qnetd]' - ] - ) + it 'configures the net quorum device' do + is_expected.to contain_exec('pcs qdevice setup model net --enable --start').with( + path: '/sbin:/bin:/usr/sbin:/usr/bin', + onlyif: [ + 'test ! -f /etc/corosync/qnetd/nssdb/qnetd-cacert.crt' + ], + require: 'Service[pcsd]' + ) + end + + it 'makes sure the net quorum device is started' do + is_expected.to contain_exec('pcs qdevice start net').with( + path: '/sbin:/bin:/usr/sbin:/usr/bin', + onlyif: [ + 'test -f /etc/corosync/qnetd/nssdb/qnetd-cacert.crt', + 'test 0 -ne $(pcs qdevice status net >/dev/null 2>&1; echo $?)' + ], + require: [ + 'Package[pcs]', + 'Package[corosync-qnetd]' + ] + ) + end + end end end end diff --git a/spec/classes/corosync_spec.rb b/spec/classes/corosync_spec.rb index 8b2c426c..f5246f1c 100644 --- a/spec/classes/corosync_spec.rb +++ b/spec/classes/corosync_spec.rb @@ -656,12 +656,12 @@ auth_command = if facts[:default_provider] == 'pcs' if Gem::Version.new(fact('pcs_version')) < Gem::Version.new('0.10.0') - 'pcs cluster auth' + 'cluster auth' else - 'pcs host auth' + 'host auth' end else - 'pcs cluster auth' + 'cluster auth' end cluster_name_arg = if facts[:default_provider] == 'pcs' if Gem::Version.new(fact('pcs_version')) < Gem::Version.new('0.10.0') @@ -672,6 +672,12 @@ else '--name' end + provider_package = case facts[:default_provider] + when 'pcs' + 'pcs' + else + 'crmsh' + end context 'without secauth' do let(:params) do @@ -721,20 +727,11 @@ end end - if facts[:default_provider] == 'pcs' - it 'installs the pcs package' do - is_expected.to contain_package('pcs').with( - ensure: 'present', - install_options: nil - ) - end - else - it 'install the crmsh package' do - is_expected.to contain_package('crmsh').with( - ensure: 'present', - install_options: nil - ) - end + it 'installs the provider package package' do + is_expected.to contain_package(provider_package).with( + ensure: 'present', + install_options: nil + ) end it 'does manage the pacemaker service' do @@ -784,7 +781,7 @@ end it 'configures the hacluster user and haclient group' do - is_expected.to contain_group('haclient').that_requires('Package[pcs]') + is_expected.to contain_group('haclient').that_requires("Package[#{provider_package}]") is_expected.to contain_user('hacluster').with( ensure: 'present', gid: 'haclient', @@ -802,7 +799,7 @@ it 'authorizes all nodes' do is_expected.to contain_exec('Authorize members').with( - command: "#{auth_command} node1.test.org node2.test.org node3.test.org -u hacluster -p some-secret-sauce", + command: "pcs #{auth_command} node1.test.org node2.test.org node3.test.org -u hacluster -p some-secret-sauce", path: '/sbin:/bin:/usr/sbin:/usr/bin', require: [ 'Service[pcsd]', @@ -810,24 +807,6 @@ ] ) end - context 'with pcs 0.10.0' do - let(:params) do - super().merge( - 'version_pcs' => '0.10.0' - ) - end - - it 'authorizes all nodes' do - is_expected.to contain_exec('Authorize members').with( - command: 'pcs host auth node1.test.org node2.test.org node3.test.org -u hacluster -p some-secret-sauce', - path: '/sbin:/bin:/usr/sbin:/usr/bin', - require: [ - 'Service[pcsd]', - 'User[hacluster]' - ] - ) - end - end end context 'using an ip baseid node list' do @@ -950,8 +929,8 @@ it 'does not contain the quorum device config in corosync.conf' do is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( %r!quorum { -provider: corosync_votequorum -}$!m + provider: corosync_votequorum + }$!m ) end @@ -1022,68 +1001,72 @@ ) end - it 'configures a temporary cluster if corosync.conf is missing' do - is_expected.to contain_exec('pcs_cluster_temporary').with( - command: "pcs cluster setup --force #{cluster_name_arg} cluster_test node1.test.org node2.test.org node3.test.org", - path: '/sbin:/bin:/usr/sbin:/usr/bin', - onlyif: 'test ! -f /etc/corosync/corosync.conf', - require: "Exec['Authorize members']" - ) - end - - it 'authorizes and adds the quorum device' do - is_expected.to contain_exec('Authorize qdevice').with( - command: "#{auth_command} quorum1.test.org -u hacluster -p quorum-secret-password", - path: '/sbin:/bin:/usr/sbin:/usr/bin', - onlyif: 'test 0 -ne $(grep quorum1.test.org /var/lib/pcsd/tokens >/dev/null 2>&1; echo $?)', - require: [ - 'Package[corosync-qdevice]', - "Exec['Authorize members']", - 'Exec[pcs_cluster_temporary]' - ] - ) + case facts[:default_provider] + when 'pcs' + it 'configures a temporary cluster if corosync.conf is missing' do + is_expected.to contain_exec('pcs_cluster_temporary').with( + command: "pcs cluster setup --force #{cluster_name_arg} cluster_test node1.test.org node2.test.org node3.test.org", + path: '/sbin:/bin:/usr/sbin:/usr/bin', + onlyif: 'test ! -f /etc/corosync/corosync.conf', + require: "Exec['Authorize members']" + ) + end - is_expected.to contain_exec('pcs_cluster_add_qdevice').with( - command: 'pcs quorum device add model net host=quorum1.test.org algorithm=ffsplit', - path: '/sbin:/bin:/usr/sbin:/usr/bin', - onlyif: [ - 'test 0 -ne $(pcs quorum config | grep "host:" >/dev/null 2>&1; echo $?)' - ], - require: "Exec['Authorize qdevice']" - ) - end - it 'contains the quorum configuration' do - is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( - %r!quorum { -provider: corosync_votequorum -device { - model: net - votes: 1 + it 'authorizes and adds the quorum device' do + is_expected.to contain_exec('Authorize qdevice').with( + command: "pcs #{auth_command} quorum1.test.org -u hacluster -p quorum-secret-password", + path: '/sbin:/bin:/usr/sbin:/usr/bin', + onlyif: 'test 0 -ne $(grep quorum1.test.org /var/lib/pcsd/tokens >/dev/null 2>&1; echo $?)', + require: [ + 'Package[corosync-qdevice]', + "Exec['Authorize members']", + 'Exec[pcs_cluster_temporary]' + ] + ) - net { - algorithm: ffsplit - host: quorum1[.]test[.]org - } -} -}!m - ) - end - end + is_expected.to contain_exec('pcs_cluster_add_qdevice').with( + command: 'pcs quorum device add model net host=quorum1.test.org algorithm=ffsplit', + path: '/sbin:/bin:/usr/sbin:/usr/bin', + onlyif: [ + 'test 0 -ne $(pcs quorum config | grep "host:" >/dev/null 2>&1; echo $?)' + ], + require: "Exec['Authorize qdevice']" + ) + end + it 'contains the quorum configuration' do + is_expected.to contain_file('/etc/corosync/corosync.conf').with_content( + %r!quorum { + provider: corosync_votequorum + device { + model: net + votes: 1 + + net { + algorithm: ffsplit + host: quorum1[.]test[.]org + } + } + }!m + ) + end - context 'with two nodes' do - let(:params) do - super().merge( - quorum_members: [ - 'node1.test.org', - 'node2.test.org' - ] - ) - end + context 'with two nodes' do + let(:params) do + super().merge( + quorum_members: [ + 'node1.test.org', + 'node2.test.org' + ] + ) + end - it 'does not configure two node' do - is_expected.not_to contain_file('/etc/corosync/corosync.conf').with_content( - %r{two_node: 1\n} - ) + it 'does not configure two node' do + is_expected.not_to contain_file('/etc/corosync/corosync.conf').with_content( + %r{two_node: 1\n} + ) + end + # else - to implement + end end end end