Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix upgrade without replica #198

Merged
merged 3 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions plans/upgrade.pp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

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

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

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

# Determine which compilers are associated with which DR group
$compiler_m1_targets = $compiler_targets.filter |$target| {
($cert_extensions[$target.name][peadm::oid('peadm_availability_group')]
== $cert_extensions[$primary_target[0].name][peadm::oid('peadm_availability_group')])
($cert_extensions.dig($target, peadm::oid('peadm_availability_group'))
== $cert_extensions.dig($primary_target[0], peadm::oid('peadm_availability_group')))
}

$compiler_m2_targets = $compiler_targets.filter |$target| {
($cert_extensions[$target.name][peadm::oid('peadm_availability_group')]
== $cert_extensions[$replica_target[0].name][peadm::oid('peadm_availability_group')])
($cert_extensions.dig($target, peadm::oid('peadm_availability_group'))
== $cert_extensions.dig($replica_target[0], peadm::oid('peadm_availability_group')))
}

$primary_target.peadm::fail_on_transport('pcp')
Expand Down
13 changes: 13 additions & 0 deletions spec/fixtures/plans/trusted-compiler.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"certname" : "compiler",
"extensions" : {
"pp_auth_role" : "pe_compiler",
"1.3.6.1.4.1.34380.1.3.13" : "pe_compiler",
"1.3.6.1.4.1.34380.1.1.9813" : "A"
},
"dns-alt-names" : [
"pe-server-d8b317-0.us-west1-a.c.davidsand.internal",
"pe-server-d8b317-0.us-west1-a.c.davidsand.internal",
"puppet"
]
}
13 changes: 13 additions & 0 deletions spec/fixtures/plans/trusted-primary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"certname" : "primary",
"extensions" : {
"1.3.6.1.4.1.34380.1.3.39" : "true",
"1.3.6.1.4.1.34380.1.1.9812" : "puppet/primary",
"1.3.6.1.4.1.34380.1.1.9813" : "A"
},
"dns-alt-names" : [
"pe-server-d8b317-0.us-west1-a.c.davidsand.internal",
"pe-server-d8b317-0.us-west1-a.c.davidsand.internal",
"puppet"
]
}
37 changes: 30 additions & 7 deletions spec/plans/upgrade_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,43 @@
# Include the BoltSpec library functions
include BoltSpec::Plans

let(:trustedjson) do
JSON.parse File.read(File.expand_path(File.join(fixtures, 'plans', 'trusted_facts.json')))
end

it 'minimum variables to run' do
def allow_standard_non_returning_calls
allow_apply
allow_any_task
allow_any_plan
allow_any_command
allow_out_message
end

let(:trusted_primary) do
JSON.parse File.read(File.expand_path(File.join(fixtures, 'plans', 'trusted-primary.json')))
end

let(:trusted_compiler) do
JSON.parse File.read(File.expand_path(File.join(fixtures, 'plans', 'trusted-compiler.json')))
end

it 'minimum variables to run' do
allow_standard_non_returning_calls

expect_task('peadm::read_file').always_return({ 'content' => 'mock' })
expect_task('peadm::cert_data').return_for_targets('primary' => trusted_primary)

expect(run_plan('peadm::upgrade',
'primary_host' => 'primary',
'version' => '2019.8.6')).to be_ok
end

it 'runs with a primary, compilers, but no replica' do
allow_standard_non_returning_calls

expect_task('peadm::cert_data').return_for_targets('primary' => trustedjson)
expect_task('peadm::read_file').always_return({ 'content' => 'mock' })
expect_task('peadm::cert_data').return_for_targets('primary' => trusted_primary,
'compiler' => trusted_compiler)

expect(run_plan('peadm::upgrade', 'primary_host' => 'primary', 'version' => '2019.8.6')).to be_ok
expect(run_plan('peadm::upgrade',
'primary_host' => 'primary',
'compiler_hosts' => 'compiler',
'version' => '2019.8.6')).to be_ok
end
end