Skip to content
This repository has been archived by the owner on Sep 24, 2019. It is now read-only.

Commit

Permalink
(MODULES-4653) Install puppetserver on master
Browse files Browse the repository at this point in the history
This commit updates the `run_puppet_install_helper_on` helper method
to install `puppetserver` on the host with a `master` role if one is
present in the beaker hosts array for the `foss` installation type.
  • Loading branch information
John Duarte committed Apr 6, 2017
1 parent 3c0be5e commit edf6b2f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The way to use this is to declare either `run_puppet_install_helper()` or `run_p
- `PUPPET_INSTALL_TYPE=foss` will read `PUPPET_INSTALL_VERSION` and:
- if `PUPPET_INSTALL_VERSION` is less than 4 will attempt to install that version of the system package if available, or else the ruby gem of that version.
- if `PUPPET_INSTALL_VERSION` is 4 or more it will attempt to install the corresponding puppet-agent package, or gem version otherwise.
- if a `master` role is defined, will install puppetserver on that node. Note that the corresponding puppet-agent dependency will be installed on that node rather than the specified `PUPPET_INSTALL_VERSION`.

The best way is explicitly set `PUPPET_INSTALL_TYPE` and `PUPPET_INSTALL_VERSION` to what you want. It'll probably do what you expect.

Expand Down
24 changes: 22 additions & 2 deletions lib/beaker/puppet_install_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,35 @@ def run_puppet_install_helper_on(hosts, type_arg = find_install_type, version =
when 'foss'
opts = options.merge(version: version,
default_action: 'gem_install')

install_puppet_on(hosts, opts)
hosts.each do |host|
if hosts_with_role(hosts, 'master').length>0 then
next if host == master
end
install_puppet_on(host, opts)
end
if hosts_with_role(hosts, 'master').length>0 then
# install puppetserver
install_puppetlabs_release_repo( master, 'pc1' )
master.install_package('puppetserver')
on(master, puppet('resource', 'service', 'puppetserver', 'ensure=running'))
agents.each do |agent|
on(agent, puppet('resource', 'host', 'puppet', 'ensure=present', "ip=#{master.get_ip}"))
on(agent, puppet('agent', '--test'), :acceptable_exit_codes => [0,1])
end
master['distmoduledir'] = on(master, puppet('config', 'print', 'modulepath')).stdout.split(':')[0]
sign_certificate_for(agents)
run_agent_on(agents)
end
# XXX install_puppet_on() will only add_aio_defaults_on when the nodeset
# type == 'aio', but we don't want to depend on that.
if opts[:version] && !version_is_less(opts[:version], '4.0.0')
add_aio_defaults_on(hosts)
add_puppet_paths_on(hosts)
end
Array(hosts).each do |host|
if hosts_with_role(hosts, 'master').length>0 then
next if host == master
end
if fact_on(host, 'osfamily') != 'windows'
on host, "mkdir -p #{host['distmoduledir']}"
# XXX Maybe this can just be removed? What PE/puppet version needs
Expand Down
43 changes: 40 additions & 3 deletions spec/unit/beaker/puppet_install_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@
allow(foss_host).to receive(:[]).with('distmoduledir').and_return('/dne')
allow(foss_host).to receive(:[]).with('platform').and_return('Debian')
allow(foss_host).to receive(:[]).with('pe_ver').and_return(nil)
allow(foss_host).to receive(:[]).with('roles').and_return(['agent'])
allow(foss_host).to receive(:puppet).and_return('hiera_config' => '/dne')
allow(pe_host).to receive(:[]).with('pe_ver').and_return('3.8.3')
allow(pe_host).to receive(:[]).with('distmoduledir').and_return('/dne')
allow(pe_host).to receive(:[]).with('platform').and_return('Debian')
allow(pe_host).to receive(:[]).with('roles').and_return(['agent'])
allow(pe_host).to receive(:puppet).and_return('hiera_config' => '/dne')
[foss_host, pe_host]
end
before :each do
allow(subject).to receive(:options).and_return({})
allow(subject).to receive(:on)
allow(subject).to receive(:fact_on)
allow(subject).to receive(:agents).and_return(hosts)
end
after :each do
ENV.delete('PUPPET_VERSION')
Expand Down Expand Up @@ -71,22 +74,56 @@
end
end
context 'for foss' do
let :hosts do
foss_host = double(is_pe?: false)
foss_master = double(is_pe?: false)
allow(foss_host).to receive(:[]).with('distmoduledir').and_return('/dne')
allow(foss_host).to receive(:[]).with('platform').and_return('Debian')
allow(foss_host).to receive(:[]).with('pe_ver').and_return(nil)
allow(foss_host).to receive(:[]).with('roles').and_return(['agent'])
allow(foss_host).to receive(:puppet).and_return('hiera_config' => '/dne')
allow(foss_master).to receive(:[]).with('pe_ver').and_return(nil)
allow(foss_master).to receive(:[]=).with('distmoduledir', 'foo')
allow(foss_master).to receive(:[]).with('platform').and_return('Debian')
allow(foss_master).to receive(:[]).with('roles').and_return(['master'])
allow(foss_master).to receive(:get_ip).and_return('1.2.3.4')
allow(foss_master).to receive(:install_package).with('puppetserver')
allow(foss_master).to receive(:get_ip).and_return('1.2.3.4')
[foss_host, foss_master]
end
let :result do
Beaker::Result.new( nil, nil )
end
before :each do
allow(subject).to receive(:master).and_return(hosts[1])
allow(subject).to receive(:sign_certificate_for)
allow(subject).to receive(:puppet_agent)
allow(subject).to receive(:puppet).with('resource', 'service', 'puppetserver', 'ensure=running')
allow(subject).to receive(:puppet).with('resource', 'host', 'puppet', 'ensure=present', 'ip=1.2.3.4')
allow(subject).to receive(:puppet).with('agent', '--test')
allow(subject).to receive(:puppet).with('config', 'print', 'modulepath')
allow(subject).to receive(:on).and_return(result)
result.stdout = 'foo:bar'
end
it 'uses foss explicitly' do
ENV['PUPPET_INSTALL_TYPE'] = 'foss'
expect(subject).to receive(:install_puppet_on).with(hosts, version: nil, default_action: 'gem_install')
expect(subject).to receive(:install_puppetlabs_release_repo).with(hosts[1], 'pc1')
expect(subject).to receive(:install_puppet_on).with(hosts[0], version: nil, default_action: 'gem_install')
subject.run_puppet_install_helper_on(hosts)
end
%w(PUPPET_VERSION PUPPET_INSTALL_VERSION).each do |version_var|
it 'uses foss with a version' do
ENV['PUPPET_INSTALL_TYPE'] = 'foss'
ENV[version_var] = '3.8.1'
expect(subject).to receive(:install_puppet_on).with(hosts, version: '3.8.1', default_action: 'gem_install')
expect(subject).to receive(:install_puppetlabs_release_repo).with(hosts[1], 'pc1')
expect(subject).to receive(:install_puppet_on).with(hosts[0], version: '3.8.1', default_action: 'gem_install')
subject.run_puppet_install_helper_on(hosts)
end
it 'uses foss with a >4 version detects AIO' do
ENV['PUPPET_INSTALL_TYPE'] = 'foss'
ENV[version_var] = '4.1.0'
expect(subject).to receive(:install_puppet_on).with(hosts, version: '4.1.0', default_action: 'gem_install')
expect(subject).to receive(:install_puppetlabs_release_repo).with(hosts[1], 'pc1')
expect(subject).to receive(:install_puppet_on).with(hosts[0], version: '4.1.0', default_action: 'gem_install')
expect(subject).to receive(:add_aio_defaults_on).with(hosts)
expect(subject).to receive(:add_puppet_paths_on).with(hosts)
subject.run_puppet_install_helper_on(hosts)
Expand Down

0 comments on commit edf6b2f

Please sign in to comment.