Skip to content

Commit 42b730a

Browse files
authored
Merge pull request #198 from puppetlabs/fix-upgrade-without-replica
Fix upgrade without replica
2 parents 8be0a94 + 8ef9bd5 commit 42b730a

File tree

4 files changed

+63
-13
lines changed

4 files changed

+63
-13
lines changed

plans/upgrade.pp

+7-6
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181

8282
# Gather certificate extension information from all systems
8383
$cert_extensions = run_task('peadm::cert_data', $all_targets).reduce({}) |$memo,$result| {
84-
$memo + { $result.target.name => $result['extensions'] }
84+
$memo + { $result.target => $result['extensions'] }
8585
}
8686

8787
$convert_targets = $cert_extensions.filter |$name,$exts| {
@@ -95,7 +95,8 @@
9595

9696
# Ensure needed trusted facts are available
9797
if $cert_extensions.any |$_,$cert| {
98-
[peadm::oid('peadm_role'), 'pp_auth_role'].all |$ext| { $cert[$ext] == undef }
98+
[peadm::oid('peadm_role'), 'pp_auth_role'].all |$ext| { $cert[$ext] == undef } or
99+
$cert[peadm::oid('peadm_availability_group')] == undef
99100
} {
100101
fail_plan(@(HEREDOC/L))
101102
Required trusted facts are not present; upgrade cannot be completed. If \
@@ -106,13 +107,13 @@
106107

107108
# Determine which compilers are associated with which DR group
108109
$compiler_m1_targets = $compiler_targets.filter |$target| {
109-
($cert_extensions[$target.name][peadm::oid('peadm_availability_group')]
110-
== $cert_extensions[$primary_target[0].name][peadm::oid('peadm_availability_group')])
110+
($cert_extensions.dig($target, peadm::oid('peadm_availability_group'))
111+
== $cert_extensions.dig($primary_target[0], peadm::oid('peadm_availability_group')))
111112
}
112113

113114
$compiler_m2_targets = $compiler_targets.filter |$target| {
114-
($cert_extensions[$target.name][peadm::oid('peadm_availability_group')]
115-
== $cert_extensions[$replica_target[0].name][peadm::oid('peadm_availability_group')])
115+
($cert_extensions.dig($target, peadm::oid('peadm_availability_group'))
116+
== $cert_extensions.dig($replica_target[0], peadm::oid('peadm_availability_group')))
116117
}
117118

118119
$primary_target.peadm::fail_on_transport('pcp')
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"certname" : "compiler",
3+
"extensions" : {
4+
"pp_auth_role" : "pe_compiler",
5+
"1.3.6.1.4.1.34380.1.3.13" : "pe_compiler",
6+
"1.3.6.1.4.1.34380.1.1.9813" : "A"
7+
},
8+
"dns-alt-names" : [
9+
"pe-server-d8b317-0.us-west1-a.c.davidsand.internal",
10+
"pe-server-d8b317-0.us-west1-a.c.davidsand.internal",
11+
"puppet"
12+
]
13+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"certname" : "primary",
3+
"extensions" : {
4+
"1.3.6.1.4.1.34380.1.3.39" : "true",
5+
"1.3.6.1.4.1.34380.1.1.9812" : "puppet/primary",
6+
"1.3.6.1.4.1.34380.1.1.9813" : "A"
7+
},
8+
"dns-alt-names" : [
9+
"pe-server-d8b317-0.us-west1-a.c.davidsand.internal",
10+
"pe-server-d8b317-0.us-west1-a.c.davidsand.internal",
11+
"puppet"
12+
]
13+
}

spec/plans/upgrade_spec.rb

+30-7
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,43 @@
44
# Include the BoltSpec library functions
55
include BoltSpec::Plans
66

7-
let(:trustedjson) do
8-
JSON.parse File.read(File.expand_path(File.join(fixtures, 'plans', 'trusted_facts.json')))
9-
end
10-
11-
it 'minimum variables to run' do
7+
def allow_standard_non_returning_calls
128
allow_apply
139
allow_any_task
1410
allow_any_plan
1511
allow_any_command
1612
allow_out_message
13+
end
14+
15+
let(:trusted_primary) do
16+
JSON.parse File.read(File.expand_path(File.join(fixtures, 'plans', 'trusted-primary.json')))
17+
end
18+
19+
let(:trusted_compiler) do
20+
JSON.parse File.read(File.expand_path(File.join(fixtures, 'plans', 'trusted-compiler.json')))
21+
end
22+
23+
it 'minimum variables to run' do
24+
allow_standard_non_returning_calls
25+
26+
expect_task('peadm::read_file').always_return({ 'content' => 'mock' })
27+
expect_task('peadm::cert_data').return_for_targets('primary' => trusted_primary)
28+
29+
expect(run_plan('peadm::upgrade',
30+
'primary_host' => 'primary',
31+
'version' => '2019.8.6')).to be_ok
32+
end
33+
34+
it 'runs with a primary, compilers, but no replica' do
35+
allow_standard_non_returning_calls
1736

18-
expect_task('peadm::cert_data').return_for_targets('primary' => trustedjson)
1937
expect_task('peadm::read_file').always_return({ 'content' => 'mock' })
38+
expect_task('peadm::cert_data').return_for_targets('primary' => trusted_primary,
39+
'compiler' => trusted_compiler)
2040

21-
expect(run_plan('peadm::upgrade', 'primary_host' => 'primary', 'version' => '2019.8.6')).to be_ok
41+
expect(run_plan('peadm::upgrade',
42+
'primary_host' => 'primary',
43+
'compiler_hosts' => 'compiler',
44+
'version' => '2019.8.6')).to be_ok
2245
end
2346
end

0 commit comments

Comments
 (0)