diff --git a/README.md b/README.md index 61ff672..293e627 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/beaker/puppet_install_helper.rb b/lib/beaker/puppet_install_helper.rb index 23e6605..8b91f22 100644 --- a/lib/beaker/puppet_install_helper.rb +++ b/lib/beaker/puppet_install_helper.rb @@ -51,8 +51,25 @@ 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') @@ -60,6 +77,9 @@ def run_puppet_install_helper_on(hosts, type_arg = find_install_type, version = 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 diff --git a/spec/unit/beaker/puppet_install_helper_spec.rb b/spec/unit/beaker/puppet_install_helper_spec.rb index 1e26777..23e61b0 100644 --- a/spec/unit/beaker/puppet_install_helper_spec.rb +++ b/spec/unit/beaker/puppet_install_helper_spec.rb @@ -10,10 +10,12 @@ 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 @@ -21,6 +23,7 @@ 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') @@ -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)