beaker-puppet 0.13.3 → 0.13.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da73693c535ed78cfde43029b2c2c7b0bc3e0d4f
4
- data.tar.gz: 4706afb84f74dd8d13cf7d5ad46bb320f5294dad
3
+ metadata.gz: d322c80a47192acedb35fe134e928ca9fad94f94
4
+ data.tar.gz: d4dfedaa36a7a51a237388eebee0d8c9e664ee28
5
5
  SHA512:
6
- metadata.gz: b0a14fb382b29db5da6fb1bdd7b10d7a6437a55b43fe12be2015add2ea9105d14fe989978f276571053eab8b9fdb7e19ff2b5dc6eae6c61fcaba0fc90f1c2ddf
7
- data.tar.gz: 318c2814ff69d56716c9451f3cb80e6fd180ff037e02917bde5326b88534c6ca5d1aa26333b34438186b4ad2f2893c15c52eb24206edb61dc712b8273122f77b
6
+ metadata.gz: 94e08a2ccdd6e9e75f18d28bae39262ab9af24432a65021d07756ececb4651c942ab9069a3243194a25e06cbc9d2ee5c32afd5ca2d63fc0ab540609421e3ebc7
7
+ data.tar.gz: 3fcb942b149e20a2c46e9cbc2d39f0bc69ff0f4dd734ab52684df47bba1b1f2746d00453a969bd7353cb97c2b255288951cd63277f07d6a442de4b5725beac59
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  require 'timeout'
2
3
  require 'inifile'
3
4
  require 'resolv'
@@ -47,6 +48,18 @@ module Beaker
47
48
  # running the command.
48
49
  #
49
50
 
51
+ # Read a setting from the puppet master config
52
+ #
53
+ # @param [Host] host The host
54
+ # @param [String] setting The setting to read
55
+ #
56
+ def puppet_config(host, setting, section: nil)
57
+ command = "config print #{setting}"
58
+ command += " --section #{section}" if section
59
+
60
+ on(host, puppet(command)).stdout.strip
61
+ end
62
+
50
63
  # Return the name of the puppet user.
51
64
  #
52
65
  # @param [Host] host One object that acts like a Beaker::Host
@@ -54,7 +67,7 @@ module Beaker
54
67
  # @note This method assumes puppet is installed on the host.
55
68
  #
56
69
  def puppet_user(host)
57
- return host.puppet('master')['user']
70
+ puppet_config(host, 'user', section: 'master')
58
71
  end
59
72
 
60
73
  # Return the name of the puppet group.
@@ -64,7 +77,7 @@ module Beaker
64
77
  # @note This method assumes puppet is installed on the host.
65
78
  #
66
79
  def puppet_group(host)
67
- return host.puppet('master')['group']
80
+ puppet_config(host, 'group', section: 'master')
68
81
  end
69
82
 
70
83
  # Test Puppet running in a certain run mode with specific options.
@@ -135,10 +148,10 @@ module Beaker
135
148
  # :master => {:masterlog => '/elswhere'},
136
149
  # :agent => {:server => 'localhost'} ) do
137
150
  #
138
- # ...tests to be ran...
151
+ # ...tests to be run...
139
152
  # end
140
153
  #
141
- def with_puppet_running_on host, conf_opts, testdir = host.tmpdir(File.basename(@path)), &block
154
+ def with_puppet_running_on(host, conf_opts, testdir = host.tmpdir(File.basename(@path)), &block)
142
155
  raise(ArgumentError, "with_puppet_running_on's conf_opts must be a Hash. You provided a #{conf_opts.class}: '#{conf_opts}'") if !conf_opts.kind_of?(Hash)
143
156
  cmdline_args = conf_opts[:__commandline_args__]
144
157
  service_args = conf_opts[:__service_args__] || {}
@@ -151,8 +164,8 @@ module Beaker
151
164
  logger.debug "Setting curl retries to #{curl_retries}"
152
165
 
153
166
  if options[:is_puppetserver] || host[:is_puppetserver]
154
- confdir = host.puppet('master')['confdir']
155
- vardir = host.puppet('master')['vardir']
167
+ confdir = puppet_config(host, 'confdir', section: 'master')
168
+ vardir = puppet_config(host, 'vardir', section: 'master')
156
169
 
157
170
  if cmdline_args
158
171
  split_args = cmdline_args.split()
@@ -176,7 +189,10 @@ module Beaker
176
189
  modify_tk_config(host, puppetserver_conf, puppetserver_opts)
177
190
  end
178
191
  begin
179
- backup_file = backup_the_file(host, host.puppet('master')['confdir'], testdir, 'puppet.conf')
192
+ backup_file = backup_the_file(host,
193
+ puppet_config(host, 'confdir', section: 'master'),
194
+ testdir,
195
+ 'puppet.conf')
180
196
  lay_down_new_puppet_conf host, conf_opts, testdir
181
197
 
182
198
  if host.use_service_scripts? && !service_args[:bypass_service_script]
@@ -250,7 +266,7 @@ module Beaker
250
266
 
251
267
  # @!visibility private
252
268
  def restore_puppet_conf_from_backup( host, backup_file )
253
- puppet_conf = host.puppet('master')['config']
269
+ puppet_conf = puppet_config(host, 'config', section: 'master')
254
270
 
255
271
  if backup_file
256
272
  host.exec( Command.new( "if [ -f '#{backup_file}' ]; then " +
@@ -278,7 +294,7 @@ module Beaker
278
294
 
279
295
  # @!visibility private
280
296
  def stop_puppet_from_source_on( host )
281
- pid = host.exec( Command.new('cat `puppet master --configprint pidfile`') ).stdout.chomp
297
+ pid = host.exec( Command.new('cat `puppet config print --section master pidfile`') ).stdout.chomp
282
298
  host.exec( Command.new( "kill #{pid}" ) )
283
299
  Timeout.timeout(10) do
284
300
  while host.exec( Command.new( "kill -0 #{pid}"), :acceptable_exit_codes => [0,1] ).exit_code == 0 do
@@ -305,7 +321,7 @@ module Beaker
305
321
 
306
322
  # @!visibility private
307
323
  def lay_down_new_puppet_conf( host, configuration_options, testdir )
308
- puppetconf_main = host.puppet('master')['config']
324
+ puppetconf_main = puppet_config(host, 'config', section: 'master')
309
325
  puppetconf_filename = File.basename(puppetconf_main)
310
326
  puppetconf_test = File.join(testdir, puppetconf_filename)
311
327
 
@@ -321,7 +337,7 @@ module Beaker
321
337
 
322
338
  # @!visibility private
323
339
  def puppet_conf_for host, conf_opts
324
- puppetconf = host.exec( Command.new( "cat #{host.puppet('master')['config']}" ) ).stdout
340
+ puppetconf = host.exec( Command.new( "cat #{puppet_config(host, 'config', section: 'master')}" ) ).stdout
325
341
  new_conf = IniFile.new(content: puppetconf).merge( conf_opts )
326
342
 
327
343
  new_conf
@@ -845,24 +861,15 @@ module Beaker
845
861
  # @param [String] name A remote path prefix for the new temp
846
862
  # directory. Default value is '/tmp/beaker'
847
863
  # @param [String] user The name of user that should own the temp
848
- # directory. If no username is specified, use `puppet master
849
- # --configprint user` to obtain username from master. Raise RuntimeError
864
+ # directory. If no username is specified, use `puppet config print user
865
+ # --section master` to obtain username from master. Raise RuntimeError
850
866
  # if this puppet command returns a non-zero exit code.
851
867
  #
852
868
  # @return [String] Returns the name of the newly-created dir.
853
869
  def create_tmpdir_for_user(host, name='/tmp/beaker', user=nil)
854
- if not user
855
- result = on host, puppet("master --configprint user")
856
- if not result.exit_code == 0
857
- raise "`puppet master --configprint` failed, check that puppet is installed on #{host} or explicitly pass in a user name."
858
- end
859
- user = result.stdout.strip
860
- end
861
-
870
+ user ||= puppet_config(host, 'user', section: 'master')
862
871
  create_tmpdir_on(host, name, user)
863
-
864
872
  end
865
-
866
873
  end
867
874
  end
868
875
  end
@@ -1,3 +1,3 @@
1
1
  module BeakerPuppet
2
- VERSION = '0.13.3'
2
+ VERSION = '0.13.4'
3
3
  end
@@ -14,7 +14,7 @@ test_name "Validate Sign Cert" do
14
14
  step "Clear SSL on all hosts"
15
15
  hosts.each do |host|
16
16
  ssldir = on(host, puppet('agent --configprint ssldir')).stdout.chomp
17
- on(host, "rm -rf '#{ssldir}'")
17
+ on(host, "rm -rf '#{ssldir}/*'")
18
18
  end
19
19
 
20
20
  step "Master: Start Puppet Master" do
@@ -22,10 +22,6 @@ test_name "Validate Sign Cert" do
22
22
  :main => {
23
23
  :dns_alt_names => "puppet,#{hostname},#{fqdn}",
24
24
  },
25
- :__service_args__ => {
26
- # apache2 service scripts can't restart if we've removed the ssl dir
27
- :bypass_service_script => true,
28
- },
29
25
  }
30
26
  with_puppet_running_on(master, master_opts) do
31
27
 
@@ -43,32 +43,19 @@ describe ClassMixedWithDSLHelpers do
43
43
  context 'with no user argument' do
44
44
 
45
45
  context 'with no path name argument' do
46
- context 'without puppet installed on host' do
47
- it 'raises an error' do
48
- cmd = "the command"
49
- allow(result).to receive(:exit_code).and_return(1)
50
- expect(Beaker::Command).to receive(:new).with(/puppet master --configprint user/, [], {"ENV"=>{}, :cmdexe=>true}).and_return(cmd)
51
- expect(subject).to receive(:on).with(host, cmd).and_return(result)
52
- expect{
53
- subject.create_tmpdir_for_user host
54
- }.to raise_error(RuntimeError, /`puppet master --configprint` failed,/)
55
- end
56
- end
57
- context 'with puppet installed on host' do
58
- it 'executes chown once' do
59
- cmd = "the command"
60
- expect(Beaker::Command).to receive(:new).with(/puppet master --configprint user/, [], {"ENV"=>{}, :cmdexe=>true}).and_return(cmd)
61
- expect(subject).to receive(:on).with(host, cmd).and_return(result)
62
- expect(subject).to receive(:create_tmpdir_on).with(host, /\/tmp\/beaker/, /puppet/)
63
- subject.create_tmpdir_for_user(host)
64
- end
46
+ it 'executes chown once' do
47
+ cmd = "the command"
48
+ expect(Beaker::Command).to receive(:new).with(/puppet config print user --section master/, [], {"ENV"=>{}, :cmdexe=>true}).and_return(cmd)
49
+ expect(subject).to receive(:on).with(host, cmd).and_return(result)
50
+ expect(subject).to receive(:create_tmpdir_on).with(host, /\/tmp\/beaker/, /puppet/)
51
+ subject.create_tmpdir_for_user(host)
65
52
  end
66
53
  end
67
54
 
68
55
  context 'with path name argument' do
69
56
  it 'executes chown once' do
70
57
  cmd = "the command"
71
- expect(Beaker::Command).to receive(:new).with(/puppet master --configprint user/, [], {"ENV"=>{}, :cmdexe=>true}).and_return(cmd)
58
+ expect(Beaker::Command).to receive(:new).with(/puppet config print user --section master/, [], {"ENV"=>{}, :cmdexe=>true}).and_return(cmd)
72
59
  expect(subject).to receive(:on).with(host, cmd).and_return(result)
73
60
  expect(subject).to receive(:create_tmpdir_on).with(host, /\/tmp\/bogus/, /puppet/)
74
61
  subject.create_tmpdir_for_user(host, "/tmp/bogus")
@@ -748,11 +735,9 @@ describe ClassMixedWithDSLHelpers do
748
735
  stub_post_setup
749
736
  allow( subject ).to receive( :options) .and_return( {:is_puppetserver => true})
750
737
  allow( subject ).to receive( :modify_tk_config)
751
- allow( host ).to receive(:puppet).with( any_args ).and_return({
752
- 'confdir' => default_confdir,
753
- 'vardir' => default_vardir,
754
- 'config' => "#{default_confdir}/puppet.conf"
755
- })
738
+ allow( subject ).to receive(:puppet_config).with(host, 'confdir', anything).and_return(default_confdir)
739
+ allow( subject ).to receive(:puppet_config).with(host, 'vardir', anything).and_return(default_vardir)
740
+ allow( subject ).to receive(:puppet_config).with(host, 'config', anything).and_return("#{default_confdir}/puppet.conf")
756
741
  end
757
742
 
758
743
  describe 'when the global option for :is_puppetserver is false' do
@@ -973,7 +958,7 @@ describe ClassMixedWithDSLHelpers do
973
958
  execution = 0
974
959
  expect do
975
960
  subject.with_puppet_running_on(host, {}) do
976
- expect(host).to execute_commands_matching(/^puppet master/).exactly(4).times
961
+ expect(host).to execute_commands_matching(/^puppet master/).once
977
962
  execution += 1
978
963
  end
979
964
  end.to change { execution }.by(1)
@@ -990,7 +975,7 @@ describe ClassMixedWithDSLHelpers do
990
975
  execution = 0
991
976
  expect do
992
977
  subject.with_puppet_running_on(host, { :restart_when_done => true }) do
993
- expect(host).to execute_commands_matching(/^puppet master/).exactly(4).times
978
+ expect(host).to execute_commands_matching(/^puppet master/).once
994
979
  execution += 1
995
980
  end
996
981
  end.to change { execution }.by(1)
@@ -1002,19 +987,17 @@ describe ClassMixedWithDSLHelpers do
1002
987
 
1003
988
  describe 'backup and restore of puppet.conf' do
1004
989
  before :each do
1005
- mock_puppetconf_reader = Object.new
1006
- allow( mock_puppetconf_reader ).to receive( :[] ).with( 'config' ).and_return( '/root/mock/puppet.conf' )
1007
- allow( mock_puppetconf_reader ).to receive( :[] ).with( 'confdir' ).and_return( '/root/mock' )
1008
- allow( host ).to receive( :puppet ).with( any_args ).and_return( mock_puppetconf_reader )
990
+ allow(subject).to receive(:puppet_config).with(host, 'confdir', anything).and_return('/root/mock')
991
+ allow(subject).to receive(:puppet_config).with(host, 'config', anything).and_return('/root/mock/puppet.conf')
1009
992
  end
1010
993
 
1011
- let(:original_location) { host.puppet['config'] }
994
+ let(:original_location) { '/root/mock/puppet.conf' }
1012
995
  let(:backup_location) {
1013
- filename = File.basename(host.puppet['config'])
996
+ filename = File.basename(original_location)
1014
997
  File.join(tmpdir_path, "#{filename}.bak")
1015
998
  }
1016
999
  let(:new_location) {
1017
- filename = File.basename(host.puppet['config'])
1000
+ filename = File.basename(original_location)
1018
1001
  File.join(tmpdir_path, filename)
1019
1002
  }
1020
1003
 
@@ -172,7 +172,7 @@ describe ClassMixedWithDSLInstallUtils do
172
172
  it 'install an MSI from a URL on Windows' do
173
173
  @platform = 'windows'
174
174
 
175
- expect(subject).to receive(:install_msi_on).with(host, artifact_url)
175
+ expect(subject).to receive(:generic_install_msi_on).with(host, artifact_url)
176
176
 
177
177
  subject.install_artifact_on(host, artifact_url, 'project_name')
178
178
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beaker-puppet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.3
4
+ version: 0.13.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-16 00:00:00.000000000 Z
11
+ date: 2018-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec