Skip to content

Commit c7cdcac

Browse files
towoMark Habenicht
andcommitted
Include the distinctions for pcs cluster auth in 0.10.0
Include @mark8x57's changes from #513 along with version gating to still maintain support for pcs 0.9 (although one would have to check if any pcs 0.9 is still in use by supported distributions). Co-authored-by: Mark Habenicht <[email protected]>
1 parent b838f9d commit c7cdcac

File tree

2 files changed

+70
-23
lines changed

2 files changed

+70
-23
lines changed

manifests/init.pp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,18 @@
596596
# addresses
597597
$node_string = join($quorum_members, ' ')
598598

599+
# Define the pcs host command, this changed with 0.10.0 as per #513
600+
$pcs_auth_command = versioncmp($version_pcs, '0.10.0') ? {
601+
'-1' => 'pcs cluster auth',
602+
default => 'pcs host auth',
603+
}
604+
599605
# Attempt to authorize all members. The command will return successfully
600606
# if they were already authenticated so it's safe to run every time this
601607
# is applied.
602608
# TODO - make it run only once
603-
exec { 'pcs_cluster_auth':
604-
command => "pcs cluster auth ${node_string} ${auth_credential_string}",
609+
exec { 'Authorize members':
610+
command => "${pcs_auth_command} ${node_string} ${auth_credential_string}",
605611
path => $exec_path,
606612
require => [
607613
Service['pcsd'],
@@ -624,14 +630,18 @@
624630
}
625631

626632
if $manage_quorum_device and $manage_pcsd_auth and $is_auth_node and $set_votequorum {
633+
$pcs_cluster_setup_namearg = versioncmp($version_pcs, '0.10.0') ? {
634+
'-1' => '--name',
635+
default => '',
636+
}
627637
# If the cluster hasn't been configured yet, temporarily configure it so
628-
# the pcs_cluster_auth_qdevice command doesn't fail. This should generate
638+
# the Authorize qdevice command doesn't fail. This should generate
629639
# a temporary corosync.conf which will then be overwritten
630640
exec { 'pcs_cluster_temporary':
631-
command => "pcs cluster setup --force --name ${cluster_name} ${node_string}",
641+
command => "pcs cluster setup --force ${pcs_cluster_setup_namearg} ${cluster_name} ${node_string}",
632642
path => $exec_path,
633643
onlyif => 'test ! -f /etc/corosync/corosync.conf',
634-
require => Exec['pcs_cluster_auth'],
644+
require => Exec['Authorize members'],
635645
}
636646
# We need to do this so the temporary cluster doesn't delete our authkey
637647
if $enable_secauth {
@@ -644,13 +654,13 @@
644654
$qdevice_token_check = "${token_prefix} ${quorum_device_host} ${token_suffix}"
645655

646656
$quorum_device_password = $sensitive_quorum_device_password.unwrap
647-
exec { 'pcs_cluster_auth_qdevice':
648-
command => "pcs cluster auth ${quorum_device_host} -u hacluster -p ${quorum_device_password}",
657+
exec { 'Authorize qdevice':
658+
command => "${pcs_auth_command} ${quorum_device_host} -u hacluster -p ${quorum_device_password}",
649659
path => $exec_path,
650660
onlyif => $qdevice_token_check,
651661
require => [
652662
Package[$package_quorum_device],
653-
Exec['pcs_cluster_auth'],
663+
Exec['Authorize members'],
654664
Exec['pcs_cluster_temporary'],
655665
],
656666
}
@@ -666,7 +676,7 @@
666676
onlyif => [
667677
'test 0 -ne $(pcs quorum config | grep "host:" >/dev/null 2>&1; echo $?)',
668678
],
669-
require => Exec['pcs_cluster_auth_qdevice'],
679+
require => Exec['Authorize qdevice'],
670680
before => File['/etc/corosync/corosync.conf'],
671681
notify => Service['corosync-qdevice'],
672682
}

spec/classes/corosync_spec.rb

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@
66
multicast_address: '239.1.1.2' }
77
end
88

9+
auth_command = if fact('default_provider') == 'pcs'
10+
if Gem::Version.new(fact('pcs_version')) < Gem::Version.new('0.10.0')
11+
'pcs cluster auth'
12+
else
13+
'pcs host auth'
14+
end
15+
else
16+
'pcs cluster auth'
17+
end
18+
cluster_name_arg = if fact('default_provider') == 'pcs'
19+
if Gem::Version.new(fact('pcs_version')) < Gem::Version.new('0.10.0')
20+
'--name'
21+
else
22+
''
23+
end
24+
else
25+
'--name'
26+
end
27+
928
shared_examples_for 'corosync' do
1029
it { is_expected.to compile.with_all_deps }
1130

@@ -746,7 +765,7 @@
746765
let(:node) { 'node2.test.org' }
747766

748767
it 'does not perform the auth' do
749-
is_expected.not_to contain_exec('pcs_cluster_auth')
768+
is_expected.not_to contain_exec('Authorize members')
750769
end
751770
end
752771

@@ -768,15 +787,33 @@
768787
end
769788

770789
it 'authorizes all nodes' do
771-
is_expected.to contain_exec('pcs_cluster_auth').with(
772-
command: 'pcs cluster auth node1.test.org node2.test.org node3.test.org -u hacluster -p some-secret-sauce',
790+
is_expected.to contain_exec('Authorize members').with(
791+
command: "#{auth_command} node1.test.org node2.test.org node3.test.org -u hacluster -p some-secret-sauce",
773792
path: '/sbin:/bin:/usr/sbin:/usr/bin',
774793
require: [
775794
'Service[pcsd]',
776795
'User[hacluster]'
777796
]
778797
)
779798
end
799+
context 'with pcs 0.10.0' do
800+
let(:params) do
801+
super().merge(
802+
'version_pcs' => '0.10.0'
803+
)
804+
end
805+
806+
it 'authorizes all nodes' do
807+
is_expected.to contain_exec('Authorize members').with(
808+
command: 'pcs host auth node1.test.org node2.test.org node3.test.org -u hacluster -p some-secret-sauce',
809+
path: '/sbin:/bin:/usr/sbin:/usr/bin',
810+
require: [
811+
'Service[pcsd]',
812+
'User[hacluster]'
813+
]
814+
)
815+
end
816+
end
780817
end
781818

782819
context 'using an ip baseid node list' do
@@ -800,7 +837,7 @@
800837
let(:facts) { override_facts(super(), networking: { ip: '192.168.0.10' }) }
801838

802839
it 'match ip and auth nodes by member names' do
803-
is_expected.to contain_exec('pcs_cluster_auth').with(
840+
is_expected.to contain_exec('Authorize members').with(
804841
command: 'pcs cluster auth 192.168.0.10 192.168.0.12 192.168.0.13 -u hacluster -p some-secret-sauce',
805842
path: '/sbin:/bin:/usr/sbin:/usr/bin',
806843
require: [
@@ -827,7 +864,7 @@
827864
end
828865

829866
it 'still detects that this is the auth-node' do
830-
is_expected.to contain_exec('pcs_cluster_auth')
867+
is_expected.to contain_exec('Authorize members')
831868
end
832869
end
833870
end
@@ -909,7 +946,7 @@
909946
end
910947

911948
it 'does not attempt to authorize or configure the quorum node' do
912-
is_expected.not_to contain_exec('pcs_cluster_auth_qdevice')
949+
is_expected.not_to contain_exec('Authorize qdevice')
913950
is_expected.not_to contain_exec('pcs_cluster_add_qdevice')
914951
end
915952
end
@@ -950,7 +987,7 @@
950987
end
951988

952989
it 'does not authorize or add the quorum device' do
953-
is_expected.not_to contain_exec('pcs_cluster_auth_qdevice')
990+
is_expected.not_to contain_exec('Authorize qdevice')
954991
is_expected.not_to contain_exec('pcs_cluster_add_qdevice')
955992
end
956993
end
@@ -973,34 +1010,34 @@
9731010

9741011
it 'configures a temporary cluster if corosync.conf is missing' do
9751012
is_expected.to contain_exec('pcs_cluster_temporary').with(
976-
command: 'pcs cluster setup --force --name cluster_test node1.test.org node2.test.org node3.test.org',
1013+
command: "pcs cluster setup --force #{cluster_name_arg} cluster_test node1.test.org node2.test.org node3.test.org",
9771014
path: '/sbin:/bin:/usr/sbin:/usr/bin',
9781015
onlyif: 'test ! -f /etc/corosync/corosync.conf',
979-
require: 'Exec[pcs_cluster_auth]'
1016+
require: "Exec['Authorize members']"
9801017
)
9811018
end
9821019

9831020
it 'authorizes and adds the quorum device' do
984-
is_expected.to contain_exec('pcs_cluster_auth_qdevice').with(
985-
command: 'pcs cluster auth quorum1.test.org -u hacluster -p quorum-secret-password',
1021+
is_expected.to contain_exec('Authorize qdevice').with(
1022+
command: "#{auth_command} quorum1.test.org -u hacluster -p quorum-secret-password",
9861023
path: '/sbin:/bin:/usr/sbin:/usr/bin',
9871024
onlyif: 'test 0 -ne $(grep quorum1.test.org /var/lib/pcsd/tokens >/dev/null 2>&1; echo $?)',
9881025
require: [
9891026
'Package[corosync-qdevice]',
990-
'Exec[pcs_cluster_auth]',
1027+
"Exec['Authorize members']",
9911028
'Exec[pcs_cluster_temporary]'
9921029
]
9931030
)
1031+
9941032
is_expected.to contain_exec('pcs_cluster_add_qdevice').with(
9951033
command: 'pcs quorum device add model net host=quorum1.test.org algorithm=ffsplit',
9961034
path: '/sbin:/bin:/usr/sbin:/usr/bin',
9971035
onlyif: [
9981036
'test 0 -ne $(pcs quorum config | grep "host:" >/dev/null 2>&1; echo $?)'
9991037
],
1000-
require: 'Exec[pcs_cluster_auth_qdevice]'
1038+
require: "Exec['Authorize qdevice']"
10011039
)
10021040
end
1003-
10041041
it 'contains the quorum configuration' do
10051042
is_expected.to contain_file('/etc/corosync/corosync.conf').with_content(
10061043
%r!quorum {

0 commit comments

Comments
 (0)