Skip to content

Commit

Permalink
(PE-15259) Inform BeakerAnswers if we need legacy database defaults
Browse files Browse the repository at this point in the history
Based on this setting, BeakerAnswers can provide legacy bash default
values for database user parameters in the meep hiera config.  This is
necessary if we are upgrading from an older pe that beaker just
installed using the legacy script/answer defaults.

Also logs the actual answers/pe.conf file that was generated so we can
see what is going on.
  • Loading branch information
jpartlow committed May 26, 2016
1 parent 6113452 commit 7ef0347
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 4 deletions.
36 changes: 32 additions & 4 deletions lib/beaker-pe/install/pe_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,28 @@ def prepare_host_installer_options(host)
host
end

# Adds in settings needed by BeakerAnswers:
#
# * :format => :bash or :hiera depending on which legacy or meep format we need
# * :include_legacy_database_defaults => true or false. True
# indicates that we are upgrading from a legacy version and
# BeakerAnswers should include the database defaults for user
# which were set for the legacy install.
#
# @param [Beaker::Host] host that we are generating answers for
# @param [Hash] opts The Beaker options hash
# @return [Hash] a dup of the opts hash with additional settings for BeakerAnswers
def setup_beaker_answers_opts(host, opts)
beaker_answers_opts = host['pe_installer_type'] == 'meep' ?
{ :format => :hiera } :
{ :format => :bash }

beaker_answers_opts[:include_legacy_database_defaults] =
opts[:type] == :upgrade && !use_meep?(host['previous_pe_ver'])

opts.merge(beaker_answers_opts)
end

# Generates a Beaker Answers object for the passed *host* and creates
# the answer or pe.conf configuration file on the *host* needed for
# installation.
Expand All @@ -550,11 +572,17 @@ def prepare_host_installer_options(host)
# @param [Hash] opts The Beaker options hash
# @return [BeakerAnswers::Answers] the generated answers object
def generate_installer_conf_file_for(host, hosts, opts)
format = host['pe_installer_type'] == 'meep' ? :hiera : :bash
beaker_opts = opts.merge(:format => format )
answers = BeakerAnswers::Answers.create(opts[:pe_ver] || host['pe_ver'], hosts, beaker_opts)
beaker_answers_opts = setup_beaker_answers_opts(host, opts)
answers = BeakerAnswers::Answers.create(
opts[:pe_ver] || host['pe_ver'], hosts, beaker_answers_opts
)
configuration = answers.installer_configuration_string(host)
create_remote_file(host, host['pe_installer_conf_file'], configuration)

step "Generate the #{host['pe_installer_conf_file']} on #{host}" do
logger.debug(configuration)
create_remote_file(host, host['pe_installer_conf_file'], configuration)
end

answers
end

Expand Down
78 changes: 78 additions & 0 deletions spec/beaker-pe/install/pe_utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,73 @@ def slice_installer_options(host)
end
end

describe 'setup_beaker_answers_opts' do
let(:opts) { {} }
let(:host) { hosts.first }

context 'for legacy installer' do
it 'adds option for bash format' do
host['pe_installer_type'] = 'legacy'
expect(subject.setup_beaker_answers_opts(host, opts)).to eq(
opts.merge(
:format => :bash,
:include_legacy_database_defaults => false,
)
)
end
end

context 'for meep installer' do
before(:each) do
ENV['INSTALLER_TYPE'] = 'meep'
host['pe_ver'] = '2016.2.0'
host['pe_installer_type'] = 'meep'
end

after(:each) do
ENV.delete('INSTALLER_TYPE')
end

it 'adds option for hiera format' do
expect(subject.setup_beaker_answers_opts(host, opts)).to eq(
opts.merge(
:format => :hiera,
:include_legacy_database_defaults => false,
)
)
end

context 'when upgrading' do
let(:opts) { { :type => :upgrade } }

context 'from meep' do
it 'sets legacy password defaults false' do
host['pe_ver'] = '2016.2.1'
host['previous_pe_ver'] = '2016.2.0'
expect(subject.setup_beaker_answers_opts(host, opts)).to eq(
opts.merge(
:format => :hiera,
:include_legacy_database_defaults => false,
)
)
end
end

context 'from legacy' do
it 'sets legacy password defaults to true' do
host['previous_pe_ver'] = '3.8.5'
expect(subject.setup_beaker_answers_opts(host, opts)).to eq(
opts.merge(
:format => :hiera,
:include_legacy_database_defaults => true,
)
)
end
end
end
end
end

describe 'fetch_pe' do

it 'can push a local PE .tar.gz to a host and unpack it' do
Expand Down Expand Up @@ -755,6 +822,7 @@ def slice_installer_options(host)

it 'sets puppet-agent acceptable_exit_codes correctly for config helper on upgrade' do
hosts = make_hosts({
:previous_pe_ver => '3.0',
:pe_ver => '4.0',
:roles => ['agent'],
}, 2)
Expand Down Expand Up @@ -962,6 +1030,16 @@ def slice_installer_options(host)
subject.upgrade_pe_on(hosts[0], {}, path)
end

it 'sets previous_pe_ver' do
subject.hosts = hosts
host = hosts[0]
host['pe_ver'] = '3.8.5'
host['pe_upgrade_ver'] = '2016.2.0'
expect(subject).to receive(:do_install).with([host], Hash)
subject.upgrade_pe_on([host], {})
expect(host['pe_ver']).to eq('2016.2.0')
expect(host['previous_pe_ver']).to eq('3.8.5')
end
end

describe 'fetch_and_push_pe' do
Expand Down

0 comments on commit 7ef0347

Please sign in to comment.