beaker-puppet 0.17.1 → 1.0.0

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.
@@ -8,6 +8,8 @@ class ClassMixedWithDSLInstallUtils
8
8
  include Beaker::DSL::Roles
9
9
  include Beaker::DSL::Patterns
10
10
 
11
+ include Beaker::DSL::InstallUtils::ModuleUtils
12
+
11
13
  def logger
12
14
  @logger ||= RSpec::Mocks::Double.new('logger').as_null_object
13
15
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  class ClassMixedWithDSLInstallUtils
4
4
  include Beaker::DSL::Outcomes
5
- include BeakerPuppet::Install::Puppet5
5
+ include Beaker::DSL::InstallUtils::Puppet5
6
6
 
7
7
  def logger
8
8
  @logger ||= RSpec::Mocks::Double.new('logger').as_null_object
@@ -0,0 +1,263 @@
1
+ require 'spec_helper'
2
+
3
+ class ClassMixedWithDSLInstallUtils
4
+ include Beaker::DSL::Helpers
5
+ include Beaker::DSL::Patterns
6
+ include Beaker::DSL::InstallUtils
7
+
8
+ def logger
9
+ @logger ||= RSpec::Mocks::Double.new('logger').as_null_object
10
+ end
11
+ end
12
+
13
+ describe ClassMixedWithDSLInstallUtils do
14
+ let(:windows_temp) { 'C:\\Windows\\Temp' }
15
+ let( :batch_path ) { '/fake/batch/path' }
16
+ let(:msi_path) { 'c:\\foo\\puppet.msi' }
17
+ let(:winhost) { make_host( 'winhost',
18
+ { :platform => Beaker::Platform.new('windows-2008r2-64'),
19
+ :pe_ver => '3.0',
20
+ :working_dir => '/tmp',
21
+ :is_cygwin => true} ) }
22
+ let(:winhost_non_cygwin) { make_host( 'winhost_non_cygwin',
23
+ { :platform => 'windows',
24
+ :pe_ver => '3.0',
25
+ :working_dir => '/tmp',
26
+ :is_cygwin => 'false' } ) }
27
+ let(:hosts) { [ winhost, winhost_non_cygwin ] }
28
+
29
+ def expect_install_called(times = hosts.length)
30
+ result = expect( Beaker::Command ).to receive( :new )
31
+ .with( /^"#{batch_path}"$/, [], {:cmdexe => true})
32
+ .exactly( times ).times
33
+
34
+ yield result if block_given?
35
+ end
36
+
37
+ def expect_status_called(times = hosts.length)
38
+ expect( Beaker::Command ).to receive( :new )
39
+ .with( "sc qc puppet || sc qc pe-puppet", [], {:cmdexe => true} )
40
+ .exactly( times ).times
41
+ end
42
+
43
+ def expect_version_log_called(times = hosts.length)
44
+ [
45
+ "\\\"%ProgramFiles%\\Puppet Labs\\puppet\\misc\\versions.txt\\\"",
46
+ "\\\"%ProgramFiles(x86)%\\Puppet Labs\\puppet\\misc\\versions.txt\\\"",
47
+ ].each do |path|
48
+ expect( Beaker::Command ).to receive( :new )
49
+ .with( "\"if exist #{path} type #{path}\"", [], {:cmdexe => true} )
50
+ .exactly( times ).times
51
+ end
52
+ end
53
+
54
+ def expect_script_matches(hosts, contents)
55
+ hosts.each do |host|
56
+ expect( host )
57
+ .to receive( :do_scp_to ) do |local_path, remote_path|
58
+ expect(File.read(local_path)).to match(contents)
59
+ end
60
+ .and_return( true )
61
+ end
62
+ end
63
+
64
+ def expect_reg_query_called(times = hosts.length)
65
+ hosts.each do |host|
66
+ expect(host).to receive(:is_x86_64?).and_return(:true)
67
+ end
68
+
69
+ expect( Beaker::Command ).to receive( :new )
70
+ .with(%r{reg query "HKLM\\SOFTWARE\\Wow6432Node\\Puppet Labs\\PuppetInstaller}, [], {:cmdexe => true})
71
+ .exactly(times).times
72
+ end
73
+
74
+ describe "#install_msi_on" do
75
+ let( :log_file ) { '/fake/log/file.log' }
76
+ before :each do
77
+ allow( subject ).to receive( :on ).and_return( true )
78
+ allow( subject ).to receive( :create_install_msi_batch_on ).and_return( [batch_path, log_file] )
79
+ end
80
+
81
+ it "will specify a PUPPET_AGENT_STARTUP_MODE of Manual (disabling the service) by default" do
82
+ expect_install_called
83
+ expect_status_called
84
+ expect_reg_query_called
85
+ expect_version_log_called
86
+ expect( subject ).to receive( :create_install_msi_batch_on ).with(
87
+ anything, anything,
88
+ 'PUPPET_AGENT_STARTUP_MODE' => 'Manual')
89
+ subject.install_msi_on(hosts, msi_path, {})
90
+ end
91
+
92
+ it "allows configuration of PUPPET_AGENT_STARTUP_MODE" do
93
+ expect_install_called
94
+ expect_status_called
95
+ expect_reg_query_called
96
+ expect_version_log_called
97
+ value = 'Automatic'
98
+ expect( subject ).to receive( :create_install_msi_batch_on ).with(
99
+ anything, anything,
100
+ 'PUPPET_AGENT_STARTUP_MODE' => value)
101
+ subject.install_msi_on(hosts, msi_path, {'PUPPET_AGENT_STARTUP_MODE' => value})
102
+ end
103
+
104
+ it "will not generate a command to emit a log file without the :debug option set" do
105
+ expect_install_called
106
+ expect_status_called
107
+ expect( Beaker::Command ).not_to receive( :new ).with( /^type .*\.log$/, [], {:cmdexe => true} )
108
+ subject.install_msi_on(hosts, msi_path)
109
+ end
110
+
111
+ it "will generate a command to emit a log file when the install script fails" do
112
+ # note a single failure aborts executing against remaining hosts
113
+ hosts_affected = 1
114
+
115
+ expect_install_called(hosts_affected) { |e| e.and_raise }
116
+ expect_status_called(0)
117
+
118
+ expect( Beaker::Command ).to receive( :new ).with( /^type \".*\.log\"$/, [], {:cmdexe => true} ).exactly( hosts_affected ).times
119
+ expect { subject.install_msi_on(hosts, msi_path) }.to raise_error(RuntimeError)
120
+ end
121
+
122
+ it "will generate a command to emit a log file with the :debug option set" do
123
+ expect_install_called
124
+ expect_reg_query_called
125
+ expect_status_called
126
+ expect_version_log_called
127
+
128
+ expect( Beaker::Command ).to receive( :new ).with( /^type \".*\.log\"$/, [], {:cmdexe => true} ).exactly( hosts.length ).times
129
+ subject.install_msi_on(hosts, msi_path, {}, { :debug => true })
130
+ end
131
+
132
+ it 'will pass msi_path to #create_install_msi_batch_on as-is' do
133
+ expect_install_called
134
+ expect_reg_query_called
135
+ expect_status_called
136
+ expect_version_log_called
137
+ test_path = 'test/path'
138
+ expect( subject ).to receive( :create_install_msi_batch_on ).with(
139
+ anything, test_path, anything)
140
+ subject.install_msi_on(hosts, test_path)
141
+ end
142
+
143
+ it 'will search in Wow6432Node for the remembered startup setting on 64-bit hosts' do
144
+ expect_install_called
145
+ expect_status_called
146
+ expect_version_log_called
147
+
148
+ hosts.each do |host|
149
+ expect(host).to receive(:is_x86_64?).and_return(true)
150
+ end
151
+
152
+ expect( Beaker::Command ).to receive( :new )
153
+ .with('reg query "HKLM\\SOFTWARE\\Wow6432Node\\Puppet Labs\\PuppetInstaller" /v "RememberedPuppetAgentStartupMode" | findstr Foo', [], {:cmdexe => true})
154
+ .exactly(hosts.length).times
155
+
156
+ subject.install_msi_on(hosts, msi_path, {'PUPPET_AGENT_STARTUP_MODE' => "Foo"})
157
+ end
158
+
159
+ it 'will omit Wow6432Node in the registry search for remembered startup setting on 32-bit hosts' do
160
+ expect_install_called
161
+ expect_status_called
162
+ expect_version_log_called
163
+
164
+ hosts.each do |host|
165
+ expect(host).to receive(:is_x86_64?).and_return(false)
166
+ end
167
+
168
+ expect( Beaker::Command ).to receive( :new )
169
+ .with('reg query "HKLM\\SOFTWARE\\Puppet Labs\\PuppetInstaller" /v "RememberedPuppetAgentStartupMode" | findstr Foo', [], {:cmdexe => true})
170
+ .exactly(hosts.length).times
171
+
172
+ subject.install_msi_on(hosts, msi_path, {'PUPPET_AGENT_STARTUP_MODE' => "Foo"})
173
+ end
174
+ end
175
+
176
+ describe '#create_install_msi_batch_on' do
177
+ let( :tmp ) { '/tmp/create_install_msi_batch_on' }
178
+ let( :tmp_slashes ) { tmp.gsub('/', '\\') }
179
+
180
+ before :each do
181
+ FakeFS::FileSystem.add(File.expand_path tmp)
182
+ hosts.each do |host|
183
+ allow( host ).to receive( :system_temp_path ).and_return( tmp )
184
+ end
185
+ end
186
+
187
+ it 'passes msi_path & msi_opts down to #msi_install_script' do
188
+ allow( winhost ).to receive( :do_scp_to )
189
+ test_path = '/path/to/test/with/13540'
190
+ test_opts = { 'key1' => 'val1', 'key2' => 'val2' }
191
+ expect( subject ).to receive( :msi_install_script ).with(
192
+ test_path, test_opts, anything )
193
+ subject.create_install_msi_batch_on(winhost, test_path, test_opts)
194
+ end
195
+
196
+ it 'SCPs to & returns the same batch file path, corrected for slashes' do
197
+ test_time = Time.now
198
+ allow( Time ).to receive( :new ).and_return( test_time )
199
+ timestamp = test_time.strftime('%Y-%m-%d_%H.%M.%S')
200
+
201
+ correct_path = "#{tmp_slashes}\\install-puppet-msi-#{timestamp}.bat"
202
+ expect( winhost ).to receive( :do_scp_to ).with( anything, correct_path, {} )
203
+ test_path, _ = subject.create_install_msi_batch_on( winhost, msi_path, {} )
204
+ expect( test_path ).to be === correct_path
205
+ end
206
+
207
+ it 'returns & sends log_path to #msi_install_scripts, corrected for slashes' do
208
+ allow( winhost ).to receive( :do_scp_to )
209
+ test_time = Time.now
210
+ allow( Time ).to receive( :new ).and_return( test_time )
211
+ timestamp = test_time.strftime('%Y-%m-%d_%H.%M.%S')
212
+
213
+ correct_path = "#{tmp_slashes}\\install-puppet-#{timestamp}.log"
214
+ expect( subject ).to receive( :msi_install_script ).with(
215
+ anything, anything, correct_path )
216
+ _, log_path = subject.create_install_msi_batch_on( winhost, msi_path, {} )
217
+ expect( log_path ).to be === correct_path
218
+ end
219
+ end
220
+
221
+ describe '#msi_install_script' do
222
+ let( :log_path ) { '/log/msi_install_script' }
223
+
224
+ context 'msi_params parameter' do
225
+ it 'can take an empty hash' do
226
+ expected_cmd = /^start \/w msiexec\.exe \/i ".*" \/qn \/L\*V #{log_path}\ .exit/m
227
+ expect( subject.msi_install_script(msi_path, {}, log_path) ).to match(expected_cmd)
228
+ end
229
+
230
+ it 'uses a key-value pair correctly' do
231
+ params = { 'tk1' => 'tv1' }
232
+ expected_cmd = /^start \/w msiexec\.exe \/i ".*" \/qn \/L\*V #{log_path}\ tk1\=tv1/
233
+ expect( subject.msi_install_script(msi_path, params, log_path) ).to match(expected_cmd)
234
+ end
235
+
236
+ it 'uses multiple key-value pairs correctly' do
237
+ params = { 'tk1' => 'tv1', 'tk2' => 'tv2' }
238
+ expected_cmd = /^start \/w msiexec\.exe \/i ".*" \/qn \/L\*V #{log_path}\ tk1\=tv1\ tk2\=tv2/
239
+ expect( subject.msi_install_script(msi_path, params, log_path) ).to match(expected_cmd)
240
+ end
241
+ end
242
+
243
+ context 'msi_path parameter' do
244
+ it "will generate an appropriate command with a MSI file path using non-Windows slashes" do
245
+ msi_path = 'c:/foo/puppet.msi'
246
+ expected_cmd = /^start \/w msiexec\.exe \/i "c:\\foo\\puppet.msi" \/qn \/L\*V #{log_path}/
247
+ expect( subject.msi_install_script(msi_path, {}, log_path) ).to match(expected_cmd)
248
+ end
249
+
250
+ it "will generate an appropriate command with a MSI http(s) url" do
251
+ msi_url = "https://downloads.puppetlabs.com/puppet.msi"
252
+ expected_cmd = /^start \/w msiexec\.exe \/i "https\:\/\/downloads\.puppetlabs\.com\/puppet\.msi" \/qn \/L\*V #{log_path}/
253
+ expect( subject.msi_install_script(msi_url, {}, log_path) ).to match(expected_cmd)
254
+ end
255
+
256
+ it "will generate an appropriate command with a MSI file url" do
257
+ msi_url = "file://c:\\foo\\puppet.msi"
258
+ expected_cmd = /^start \/w msiexec\.exe \/i "file\:\/\/c:\\foo\\puppet\.msi" \/qn \/L\*V #{log_path}/
259
+ expect( subject.msi_install_script(msi_url, {}, log_path) ).to match(expected_cmd)
260
+ end
261
+ end
262
+ end
263
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ class ClassMixedWithDSLWrappers
4
+ include Beaker::DSL::Wrappers
5
+ end
6
+
7
+ describe ClassMixedWithDSLWrappers do
8
+ let(:empty_opts) { {'ENV' => {}, :cmdexe => true } }
9
+
10
+ describe '#facter' do
11
+ it 'should split out the options and pass "facter" as first arg to Command' do
12
+ expect( Beaker::Command ).to receive( :new ).
13
+ with('facter', [ '-p' ], empty_opts)
14
+ subject.facter( '-p' )
15
+ end
16
+ end
17
+
18
+ describe '#cfacter' do
19
+ it 'should split out the options and pass "cfacter" as first arg to Command' do
20
+ expect( Beaker::Command ).to receive( :new ).
21
+ with('cfacter', [ '-p' ], empty_opts)
22
+ subject.cfacter( '-p' )
23
+ end
24
+ end
25
+
26
+ describe 'deprecated puppet wrappers' do
27
+ %w( resource doc kick cert apply master agent filebucket ).each do |sub|
28
+ it "#{sub} delegates the proper info to #puppet" do
29
+ expect( subject ).to receive( :puppet ).with( sub, 'blah' )
30
+ subject.send( "puppet_#{sub}", 'blah')
31
+ end
32
+ end
33
+ end
34
+ 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.17.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-27 00:00:00.000000000 Z
11
+ date: 2018-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -100,6 +100,20 @@ dependencies:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0.10'
103
+ - !ruby/object:Gem::Dependency
104
+ name: beaker-vmpooler
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
103
117
  - !ruby/object:Gem::Dependency
104
118
  name: yard
105
119
  requirement: !ruby/object:Gem::Requirement
@@ -204,12 +218,13 @@ files:
204
218
  - acceptance/config/git/acceptance-options.rb
205
219
  - acceptance/config/nodes/vagrant-ubuntu-1404.yml
206
220
  - acceptance/config/pkg/acceptance-options.rb
207
- - acceptance/lib/beaker/acceptance/install_utils.rb
208
221
  - acceptance/pre_suite/gem/install.rb
209
222
  - acceptance/pre_suite/git/install.rb
210
223
  - acceptance/pre_suite/pkg/install.rb
211
224
  - acceptance/tests/README.md
212
225
  - acceptance/tests/backwards_compatible.rb
226
+ - acceptance/tests/clone_git_repo_on_test.rb
227
+ - acceptance/tests/create_tmpdir_on_test.rb
213
228
  - acceptance/tests/install_smoke_test.rb
214
229
  - acceptance/tests/stub_host.rb
215
230
  - acceptance/tests/web_helpers_test.rb
@@ -228,6 +243,7 @@ files:
228
243
  - lib/beaker-puppet/install_utils/module_utils.rb
229
244
  - lib/beaker-puppet/install_utils/puppet5.rb
230
245
  - lib/beaker-puppet/install_utils/puppet_utils.rb
246
+ - lib/beaker-puppet/install_utils/windows_utils.rb
231
247
  - lib/beaker-puppet/version.rb
232
248
  - lib/beaker-puppet/wrappers.rb
233
249
  - lib/beaker/dsl/helpers/facter_helpers.rb
@@ -261,10 +277,13 @@ files:
261
277
  - spec/beaker-puppet/helpers/facter_helpers_spec.rb
262
278
  - spec/beaker-puppet/helpers/puppet_helpers_spec.rb
263
279
  - spec/beaker-puppet/helpers/tk_helpers_spec.rb
280
+ - spec/beaker-puppet/install_utils/ezbake_utils_spec.rb
264
281
  - spec/beaker-puppet/install_utils/foss_utils_spec.rb
265
282
  - spec/beaker-puppet/install_utils/module_utils_spec.rb
266
283
  - spec/beaker-puppet/install_utils/puppet5_spec.rb
267
284
  - spec/beaker-puppet/install_utils/puppet_utils_spec.rb
285
+ - spec/beaker-puppet/install_utils/windows_utils_spec.rb
286
+ - spec/beaker-puppet/wrappers_spec.rb
268
287
  - spec/helpers.rb
269
288
  - spec/spec_helper.rb
270
289
  - tasks/ci.rake
@@ -1,58 +0,0 @@
1
- module Beaker
2
- module Acceptance
3
- module InstallUtils
4
-
5
- PLATFORM_PATTERNS = {
6
- :redhat => /fedora|el|centos/,
7
- :debian => /debian|ubuntu/,
8
- :debian_ruby18 => /debian|ubuntu-lucid|ubuntu-precise/,
9
- :solaris_10 => /solaris-10/,
10
- :solaris_11 => /solaris-11/,
11
- :windows => /windows/,
12
- :sles => /sles/,
13
- }.freeze
14
-
15
- # Installs packages on the hosts.
16
- #
17
- # @param hosts [Array<Host>] Array of hosts to install packages to.
18
- # @param package_hash [Hash{Symbol=>Array<String,Array<String,String>>}]
19
- # Keys should be a symbol for a platform in PLATFORM_PATTERNS. Values
20
- # should be an array of package names to install, or of two element
21
- # arrays where a[0] is the command we expect to find on the platform
22
- # and a[1] is the package name (when they are different).
23
- # @param options [Hash{Symbol=>Boolean}]
24
- # @option options [Boolean] :check_if_exists First check to see if
25
- # command is present before installing package. (Default false)
26
- # @return true
27
- def install_packages_on(hosts, package_hash, options = {})
28
- return true if hosts == nil
29
- check_if_exists = options[:check_if_exists]
30
- hosts = [hosts] unless hosts.kind_of?(Array)
31
- hosts.each do |host|
32
- package_hash.each do |platform_key,package_list|
33
- if pattern = PLATFORM_PATTERNS[platform_key]
34
- if pattern.match(host['platform'])
35
- package_list.each do |cmd_pkg|
36
- if cmd_pkg.kind_of?(Array)
37
- command, package = cmd_pkg
38
- else
39
- command = package = cmd_pkg
40
- end
41
- if !check_if_exists || !host.check_for_package(command)
42
- host.logger.notify("Installing #{package}")
43
- additional_switches = '--allow-unauthenticated' if platform_key == :debian
44
- host.install_package(package, additional_switches)
45
- end
46
- end
47
- end
48
- else
49
- raise("Unknown platform '#{platform_key}' in package_hash")
50
- end
51
- end
52
- end
53
- return true
54
- end
55
-
56
- end
57
- end
58
- end