Skip to content

Commit

Permalink
(PE-14271) Extract installer configuration methods
Browse files Browse the repository at this point in the history
...from the existing code to generate answers and expand it to
generalize the installer settings and configuration file.  Passes
existing specs.  Will be further specialized to handle legacy/meep
cases.
  • Loading branch information
jpartlow committed May 26, 2016
1 parent b22c379 commit 3071c5e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
44 changes: 41 additions & 3 deletions lib/beaker-pe/install/pe_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def installer_cmd(host, opts)
host.install_from_file("puppet-enterprise-#{version}-#{host['platform']}.swix")
else
pe_debug = host[:pe_debug] || opts[:pe_debug] ? ' -D' : ''
"cd #{host['working_dir']}/#{host['dist']} && ./#{host['pe_installer']}#{pe_debug} -a #{host['working_dir']}/answers"
"cd #{host['working_dir']}/#{host['dist']} && ./#{host['pe_installer']}#{pe_debug} #{host['pe_installer_conf_setting']}"
end
end

Expand Down Expand Up @@ -433,8 +433,8 @@ def do_install hosts, opts = {}
acceptable_codes = host['platform'] =~ /osx/ ? [1] : [0, 1]
setup_defaults_and_config_helper_on(host, master, acceptable_codes)
else
answers = BeakerAnswers::Answers.create(opts[:pe_ver] || host['pe_ver'], hosts, opts)
create_remote_file host, "#{host['working_dir']}/answers", answers.answer_string(host)
prepare_host_installer_options(host)
generate_installer_conf_file_for(host, hosts, opts)
on host, installer_cmd(host, opts)
configure_type_defaults_on(host)
end
Expand Down Expand Up @@ -497,6 +497,44 @@ def do_install hosts, opts = {}
end
end

# Set installer options on the passed *host* according to current
# version and external INSTALLER_TYPE setting.
#
# Sets:
# * 'pe_installer_conf_file'
# * 'pe_installer_conf_setting'
# * 'pe_installer_type'
#
# @param [Beaker::Host] host The host object to configure
# @return [Beaker::Host] The same host object passed in
def prepare_host_installer_options(host)
conf_file = "#{host['working_dir']}/answers"
host['pe_installer_conf_file'] = conf_file
host['pe_installer_conf_setting'] = "-a #{conf_file}"
host['pe_installer_type'] = 'legacy'
host
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.
#
# Expects the host['pe_installer_conf_file'] to have been set, which is
# where the configuration will be written to, and expects
# host['pe_installer_type'] to have been set to either 'legacy' or
# 'meep'.
#
# @param [Beaker::Host] host The host to create a configuration file on
# @param [Array<Beaker::Host]> hosts All of the hosts to be configured
# @param [Hash] opts The Beaker options hash
# @return [BeakerAnswers::Answers] the generated answers object
def generate_installer_conf_file_for(host, hosts, opts)
answers = BeakerAnswers::Answers.create(opts[:pe_ver] || host['pe_ver'], hosts, opts)
configuration = answers.answer_string(host)
create_remote_file(host, host['pe_installer_conf_file'], configuration)
answers
end

# Builds the agent_only and not_agent_only arrays needed for installation.
#
# @param [Array<Host>] hosts hosts to split up into the arrays
Expand Down
4 changes: 3 additions & 1 deletion spec/beaker-pe/install/pe_utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def logger
:working_dir => '/tmp' } ) }
let(:unixhost) { make_host( 'unixhost', { :platform => 'linux',
:pe_ver => '3.0',
:type => 'pe',
:type => 'pe',
:working_dir => '/tmp',
:dist => 'puppet-enterprise-3.1.0-rc0-230-g36c9e5c-debian-7-i386' } ) }
let(:eoshost) { make_host( 'eoshost', { :platform => 'eos',
Expand Down Expand Up @@ -192,6 +192,7 @@ def logger
it 'generates a unix PE install command for a unix host' do
the_host = unixhost.dup
the_host['pe_installer'] = 'puppet-enterprise-installer'
the_host['pe_installer_conf_setting'] = '-a /tmp/answers'
expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp/puppet-enterprise-3.1.0-rc0-230-g36c9e5c-debian-7-i386 && ./puppet-enterprise-installer -a /tmp/answers"
end

Expand Down Expand Up @@ -229,6 +230,7 @@ def logger
it 'generates a unix PE install command in verbose for a unix host when pe_debug is enabled' do
the_host = unixhost.dup
the_host['pe_installer'] = 'puppet-enterprise-installer'
the_host['pe_installer_conf_setting'] = '-a /tmp/answers'
the_host[:pe_debug] = true
expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp/puppet-enterprise-3.1.0-rc0-230-g36c9e5c-debian-7-i386 && ./puppet-enterprise-installer -D -a /tmp/answers"
end
Expand Down

0 comments on commit 3071c5e

Please sign in to comment.