beaker 1.21.0 → 2.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.
Files changed (103) hide show
  1. checksums.yaml +8 -8
  2. data/.gitignore +1 -0
  3. data/.rspec +1 -0
  4. data/CONTRIBUTING.md +1 -0
  5. data/HISTORY.md +17288 -2
  6. data/Rakefile +6 -2
  7. data/beaker.gemspec +15 -19
  8. data/lib/beaker.rb +2 -5
  9. data/lib/beaker/answers.rb +2 -0
  10. data/lib/beaker/answers/version34.rb +37 -1
  11. data/lib/beaker/cli.rb +4 -0
  12. data/lib/beaker/command.rb +16 -84
  13. data/lib/beaker/command_factory.rb +13 -2
  14. data/lib/beaker/dsl/assertions.rb +25 -2
  15. data/lib/beaker/dsl/ezbake_utils.rb +2 -2
  16. data/lib/beaker/dsl/helpers.rb +66 -12
  17. data/lib/beaker/dsl/install_utils.rb +128 -66
  18. data/lib/beaker/dsl/wrappers.rb +41 -3
  19. data/lib/beaker/host.rb +42 -6
  20. data/lib/beaker/host/mac.rb +62 -0
  21. data/lib/beaker/host/mac/group.rb +96 -0
  22. data/lib/beaker/host/mac/user.rb +93 -0
  23. data/lib/beaker/host/unix/exec.rb +1 -1
  24. data/lib/beaker/host/unix/pkg.rb +11 -11
  25. data/lib/beaker/host/windows.rb +4 -4
  26. data/lib/beaker/host_prebuilt_steps.rb +194 -58
  27. data/lib/beaker/hypervisor.rb +16 -9
  28. data/lib/beaker/hypervisor/aws_sdk.rb +61 -17
  29. data/lib/beaker/hypervisor/docker.rb +14 -2
  30. data/lib/beaker/hypervisor/ec2_helper.rb +15 -3
  31. data/lib/beaker/hypervisor/vagrant.rb +22 -10
  32. data/lib/beaker/hypervisor/vagrant_libvirt.rb +11 -0
  33. data/lib/beaker/hypervisor/vagrant_virtualbox.rb +1 -1
  34. data/lib/beaker/hypervisor/vcloud_pooled.rb +8 -39
  35. data/lib/beaker/logger.rb +15 -9
  36. data/lib/beaker/network_manager.rb +2 -2
  37. data/lib/beaker/options/command_line_parser.rb +1 -1
  38. data/lib/beaker/options/parser.rb +1 -8
  39. data/lib/beaker/options/presets.rb +70 -45
  40. data/lib/beaker/perf.rb +3 -4
  41. data/lib/beaker/platform.rb +2 -1
  42. data/lib/beaker/result.rb +3 -9
  43. data/lib/beaker/ssh_connection.rb +2 -0
  44. data/lib/beaker/test_case.rb +2 -21
  45. data/lib/beaker/test_suite.rb +21 -25
  46. data/lib/beaker/version.rb +1 -1
  47. data/spec/beaker/answers_spec.rb +36 -0
  48. data/spec/beaker/cli_spec.rb +45 -45
  49. data/spec/beaker/command_spec.rb +25 -36
  50. data/spec/beaker/dsl/assertions_spec.rb +20 -27
  51. data/spec/beaker/dsl/ezbake_utils_spec.rb +5 -5
  52. data/spec/beaker/dsl/helpers_spec.rb +293 -208
  53. data/spec/beaker/dsl/install_utils_spec.rb +310 -189
  54. data/spec/beaker/dsl/outcomes_spec.rb +6 -6
  55. data/spec/beaker/dsl/roles_spec.rb +27 -18
  56. data/spec/beaker/dsl/structure_spec.rb +11 -11
  57. data/spec/beaker/dsl/wrappers_spec.rb +35 -11
  58. data/spec/beaker/host/mac/group_spec.rb +124 -0
  59. data/spec/beaker/host/mac/user_spec.rb +134 -0
  60. data/spec/beaker/host/unix/pkg_spec.rb +40 -24
  61. data/spec/beaker/host/windows/group_spec.rb +1 -1
  62. data/spec/beaker/host_prebuilt_steps_spec.rb +194 -68
  63. data/spec/beaker/host_spec.rb +145 -67
  64. data/spec/beaker/hypervisor/aixer_spec.rb +6 -6
  65. data/spec/beaker/hypervisor/aws_sdk_spec.rb +22 -7
  66. data/spec/beaker/hypervisor/docker_spec.rb +71 -50
  67. data/spec/beaker/hypervisor/ec2_helper_spec.rb +25 -4
  68. data/spec/beaker/hypervisor/fusion_spec.rb +2 -2
  69. data/spec/beaker/hypervisor/hypervisor_spec.rb +20 -27
  70. data/spec/beaker/hypervisor/hypervisor_spec.rb.orig +80 -0
  71. data/spec/beaker/hypervisor/solaris_spec.rb +8 -8
  72. data/spec/beaker/hypervisor/vagrant_fusion_spec.rb +6 -8
  73. data/spec/beaker/hypervisor/vagrant_libvirt_spec.rb +34 -0
  74. data/spec/beaker/hypervisor/vagrant_spec.rb +34 -33
  75. data/spec/beaker/hypervisor/vagrant_virtualbox_spec.rb +18 -8
  76. data/spec/beaker/hypervisor/vagrant_workstation_spec.rb +6 -8
  77. data/spec/beaker/hypervisor/vcloud_pooled_spec.rb +8 -8
  78. data/spec/beaker/hypervisor/vcloud_spec.rb +10 -10
  79. data/spec/beaker/hypervisor/vsphere_helper_spec.rb +8 -8
  80. data/spec/beaker/hypervisor/vsphere_spec.rb +1 -1
  81. data/spec/beaker/logger_spec.rb +45 -31
  82. data/spec/beaker/options/command_line_parser_spec.rb +10 -2
  83. data/spec/beaker/options/hosts_file_parser_spec.rb +9 -2
  84. data/spec/beaker/options/options_hash_spec.rb +2 -2
  85. data/spec/beaker/options/parser_spec.rb +2 -2
  86. data/spec/beaker/options/pe_version_scaper_spec.rb +6 -1
  87. data/spec/beaker/options/presets_spec.rb +11 -1
  88. data/spec/beaker/shared/error_handler_spec.rb +5 -5
  89. data/spec/beaker/shared/host_manager_spec.rb +3 -2
  90. data/spec/beaker/shared/repetition_spec.rb +18 -18
  91. data/spec/beaker/ssh_connection_spec.rb +33 -4
  92. data/spec/beaker/test_case_spec.rb +9 -9
  93. data/spec/beaker/test_suite_spec.rb +14 -14
  94. data/spec/helpers.rb +4 -4
  95. data/spec/matchers.rb +4 -4
  96. data/spec/mocks.rb +5 -1
  97. data/spec/spec_helper.rb +2 -8
  98. metadata +114 -80
  99. data/lib/beaker/hypervisor/blimper.rb +0 -108
  100. data/spec/beaker/hypervisor/blimper_spec.rb +0 -42
  101. data/spec/beaker/options/data/LATEST +0 -1
  102. data/spec/beaker/puppet_command_spec.rb +0 -161
  103. data/spec/mock_blimpy.rb +0 -48
@@ -9,7 +9,7 @@ class ClassMixedWithDSLInstallUtils
9
9
  include Beaker::DSL::Patterns
10
10
 
11
11
  def logger
12
- @logger ||= RSpec::Mocks::Mock.new('logger').as_null_object
12
+ @logger ||= RSpec::Mocks::Double.new('logger').as_null_object
13
13
  end
14
14
  end
15
15
 
@@ -18,11 +18,13 @@ describe ClassMixedWithDSLInstallUtils do
18
18
  let(:opts) { presets.presets.merge(presets.env_vars) }
19
19
  let(:basic_hosts) { make_hosts( { :pe_ver => '3.0',
20
20
  :platform => 'linux',
21
- :roles => [ 'agent' ] } ) }
21
+ :roles => [ 'agent' ] }, 4 ) }
22
22
  let(:hosts) { basic_hosts[0][:roles] = ['master', 'database', 'dashboard']
23
23
  basic_hosts[1][:platform] = 'windows'
24
24
  basic_hosts[2][:platform] = 'osx-10.9-x86_64'
25
+ basic_hosts[3][:platform] = 'eos'
25
26
  basic_hosts }
27
+ let(:hosts_sorted) { [ hosts[1], hosts[0], hosts[2], hosts[3] ] }
26
28
  let(:winhost) { make_host( 'winhost', { :platform => 'windows',
27
29
  :pe_ver => '3.0',
28
30
  :working_dir => '/tmp' } ) }
@@ -33,6 +35,10 @@ describe ClassMixedWithDSLInstallUtils do
33
35
  :pe_ver => '3.0',
34
36
  :working_dir => '/tmp',
35
37
  :dist => 'puppet-enterprise-3.1.0-rc0-230-g36c9e5c-debian-7-i386' } ) }
38
+ let(:eoshost) { make_host( 'eoshost', { :platform => 'eos',
39
+ :pe_ver => '3.0',
40
+ :working_dir => '/tmp',
41
+ :dist => 'puppet-enterprise-3.7.1-rc0-78-gffc958f-eos-4-i386' } ) }
36
42
 
37
43
 
38
44
  context 'extract_repo_info_from' do
@@ -71,9 +77,9 @@ describe ClassMixedWithDSLInstallUtils do
71
77
  cmd = 'cd /path/to/repo/name && git describe || true'
72
78
  logger = double.as_null_object
73
79
 
74
- subject.should_receive( :logger ).and_return( logger )
75
- subject.should_receive( :on ).with( host, cmd ).and_yield
76
- subject.should_receive( :stdout ).and_return( '2' )
80
+ expect( subject ).to receive( :logger ).and_return( logger )
81
+ expect( subject ).to receive( :on ).with( host, cmd ).and_yield
82
+ expect( subject ).to receive( :stdout ).and_return( '2' )
77
83
 
78
84
  version = subject.find_git_repo_versions( host, path, repository )
79
85
 
@@ -90,8 +96,8 @@ describe ClassMixedWithDSLInstallUtils do
90
96
  host = { 'platform' => 'debian' }
91
97
  logger = double.as_null_object
92
98
 
93
- subject.should_receive( :logger ).exactly( 3 ).times.and_return( logger )
94
- subject.should_receive( :on ).exactly( 4 ).times
99
+ expect( subject ).to receive( :logger ).exactly( 3 ).times.and_return( logger )
100
+ expect( subject ).to receive( :on ).exactly( 4 ).times
95
101
 
96
102
  subject.install_from_git( host, path, repo )
97
103
  end
@@ -106,12 +112,12 @@ describe ClassMixedWithDSLInstallUtils do
106
112
  cmd = "test -d #{path}/#{repo[:name]} || git clone --branch #{repo[:rev]} --depth #{repo[:depth]} #{repo[:path]} #{path}/#{repo[:name]}"
107
113
  host = { 'platform' => 'debian' }
108
114
  logger = double.as_null_object
109
- subject.should_receive( :logger ).exactly( 3 ).times.and_return( logger )
110
- subject.should_receive( :on ).with( host,"test -d #{path} || mkdir -p #{path}").exactly( 1 ).times
115
+ expect( subject ).to receive( :logger ).exactly( 3 ).times.and_return( logger )
116
+ expect( subject ).to receive( :on ).with( host,"test -d #{path} || mkdir -p #{path}").exactly( 1 ).times
111
117
  # this is the the command we want to test
112
- subject.should_receive( :on ).with( host, cmd ).exactly( 1 ).times
113
- subject.should_receive( :on ).with( host, "cd #{path}/#{repo[:name]} && git remote rm origin && git remote add origin #{repo[:path]} && git fetch origin && git clean -fdx && git checkout -f #{repo[:rev]}" ).exactly( 1 ).times
114
- subject.should_receive( :on ).with( host, "cd #{path}/#{repo[:name]} && if [ -f install.rb ]; then ruby ./install.rb ; else true; fi" ).exactly( 1 ).times
118
+ expect( subject ).to receive( :on ).with( host, cmd ).exactly( 1 ).times
119
+ expect( subject ).to receive( :on ).with( host, "cd #{path}/#{repo[:name]} && git remote rm origin && git remote add origin #{repo[:path]} && git fetch origin +refs/pull/*:refs/remotes/origin/pr/* +refs/heads/*:refs/remotes/origin/* && git clean -fdx && git checkout -f #{repo[:rev]}" ).exactly( 1 ).times
120
+ expect( subject ).to receive( :on ).with( host, "cd #{path}/#{repo[:name]} && if [ -f install.rb ]; then ruby ./install.rb ; else true; fi" ).exactly( 1 ).times
115
121
 
116
122
  subject.install_from_git( host, path, repo )
117
123
  end
@@ -127,12 +133,12 @@ describe ClassMixedWithDSLInstallUtils do
127
133
  cmd = "test -d #{path}/#{repo[:name]} || git clone --branch #{repo[:depth_branch]} --depth #{repo[:depth]} #{repo[:path]} #{path}/#{repo[:name]}"
128
134
  host = { 'platform' => 'debian' }
129
135
  logger = double.as_null_object
130
- subject.should_receive( :logger ).exactly( 3 ).times.and_return( logger )
131
- subject.should_receive( :on ).with( host,"test -d #{path} || mkdir -p #{path}").exactly( 1 ).times
136
+ expect( subject ).to receive( :logger ).exactly( 3 ).times.and_return( logger )
137
+ expect( subject ).to receive( :on ).with( host,"test -d #{path} || mkdir -p #{path}").exactly( 1 ).times
132
138
  # this is the the command we want to test
133
- subject.should_receive( :on ).with( host, cmd ).exactly( 1 ).times
134
- subject.should_receive( :on ).with( host, "cd #{path}/#{repo[:name]} && git remote rm origin && git remote add origin #{repo[:path]} && git fetch origin && git clean -fdx && git checkout -f #{repo[:rev]}" ).exactly( 1 ).times
135
- subject.should_receive( :on ).with( host, "cd #{path}/#{repo[:name]} && if [ -f install.rb ]; then ruby ./install.rb ; else true; fi" ).exactly( 1 ).times
139
+ expect( subject ).to receive( :on ).with( host, cmd ).exactly( 1 ).times
140
+ expect( subject ).to receive( :on ).with( host, "cd #{path}/#{repo[:name]} && git remote rm origin && git remote add origin #{repo[:path]} && git fetch origin +refs/pull/*:refs/remotes/origin/pr/* +refs/heads/*:refs/remotes/origin/* && git clean -fdx && git checkout -f #{repo[:rev]}" ).exactly( 1 ).times
141
+ expect( subject ).to receive( :on ).with( host, "cd #{path}/#{repo[:name]} && if [ -f install.rb ]; then ruby ./install.rb ; else true; fi" ).exactly( 1 ).times
136
142
 
137
143
  subject.install_from_git( host, path, repo )
138
144
  end
@@ -140,12 +146,12 @@ describe ClassMixedWithDSLInstallUtils do
140
146
 
141
147
  describe 'sorted_hosts' do
142
148
  it 'can reorder so that the master comes first' do
143
- subject.stub( :hosts ).and_return( [ hosts[1], hosts[0], hosts[2] ] )
149
+ allow( subject ).to receive( :hosts ).and_return( hosts_sorted )
144
150
  expect( subject.sorted_hosts ).to be === hosts
145
151
  end
146
152
 
147
153
  it 'leaves correctly ordered hosts alone' do
148
- subject.stub( :hosts ).and_return( hosts )
154
+ allow( subject ).to receive( :hosts ).and_return( hosts )
149
155
  expect( subject.sorted_hosts ).to be === hosts
150
156
  end
151
157
  end
@@ -154,7 +160,7 @@ describe ClassMixedWithDSLInstallUtils do
154
160
 
155
161
  it 'generates a windows PE install command for a windows host' do
156
162
  winhost['dist'] = 'puppet-enterprise-3.0'
157
- subject.stub( :hosts ).and_return( [ hosts[1], hosts[0], hosts[2], winhost ] )
163
+ allow( subject ).to receive( :hosts ).and_return( [ hosts[1], hosts[0], hosts[2], winhost ] )
158
164
  expect( subject.installer_cmd( winhost, {} ) ).to be === "cd /tmp && cmd /C 'start /w msiexec.exe /qn /L*V tmp.log /i puppet-enterprise-3.0.msi PUPPET_MASTER_SERVER=vm1 PUPPET_AGENT_CERTNAME=winhost'"
159
165
  end
160
166
 
@@ -165,12 +171,22 @@ describe ClassMixedWithDSLInstallUtils do
165
171
  end
166
172
 
167
173
  it 'generates a unix PE frictionless install command for a unix host with role "frictionless"' do
168
- subject.stub( :version_is_less ).and_return( false )
169
- subject.stub( :master ).and_return( 'testmaster' )
174
+ allow( subject ).to receive( :version_is_less ).and_return( false )
175
+ allow( subject ).to receive( :master ).and_return( 'testmaster' )
176
+ the_host = unixhost.dup
177
+ the_host['pe_installer'] = 'puppet-enterprise-installer'
178
+ the_host['roles'] = ['frictionless']
179
+ expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp && curl --tlsv1 -kO https://testmaster:8140/packages/3.0/install.bash && bash install.bash"
180
+ end
181
+
182
+ it 'generates a unix PE frictionless install command for a unix host with role "frictionless" and "frictionless_options"' do
183
+ allow( subject ).to receive( :version_is_less ).and_return( false )
184
+ allow( subject ).to receive( :master ).and_return( 'testmaster' )
170
185
  the_host = unixhost.dup
171
186
  the_host['pe_installer'] = 'puppet-enterprise-installer'
172
187
  the_host['roles'] = ['frictionless']
173
- expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp && curl -kO https://testmaster:8140/packages/3.0/install.bash && bash install.bash"
188
+ the_host['frictionless_options'] = { 'main' => { 'dns_alt_names' => 'puppet' } }
189
+ expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp && curl --tlsv1 -kO https://testmaster:8140/packages/3.0/install.bash && bash install.bash main:dns_alt_names=puppet"
174
190
  end
175
191
 
176
192
  it 'generates a osx PE install command for a osx host' do
@@ -179,6 +195,13 @@ describe ClassMixedWithDSLInstallUtils do
179
195
  expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp && hdiutil attach .dmg && installer -pkg /Volumes/puppet-enterprise-3.0/puppet-enterprise-installer-3.0.pkg -target /"
180
196
  end
181
197
 
198
+ it 'generates an EOS PE install command for an EOS host' do
199
+ the_host = eoshost.dup
200
+ commands = ['enable', "extension puppet-enterprise-#{the_host['pe_ver']}-#{the_host['platform']}.swix"]
201
+ command = commands.join("\n")
202
+ expect( subject.installer_cmd( the_host, {} ) ).to be === "Cli -c '#{command}'"
203
+ end
204
+
182
205
  it 'generates a unix PE install command in verbose for a unix host when pe_debug is enabled' do
183
206
  the_host = unixhost.dup
184
207
  the_host['pe_installer'] = 'puppet-enterprise-installer'
@@ -194,13 +217,13 @@ describe ClassMixedWithDSLInstallUtils do
194
217
  end
195
218
 
196
219
  it 'generates a unix PE frictionless install command in verbose for a unix host with role "frictionless" and pe_debug is enabled' do
197
- subject.stub( :version_is_less ).and_return( false )
198
- subject.stub( :master ).and_return( 'testmaster' )
220
+ allow( subject ).to receive( :version_is_less ).and_return( false )
221
+ allow( subject ).to receive( :master ).and_return( 'testmaster' )
199
222
  the_host = unixhost.dup
200
223
  the_host['pe_installer'] = 'puppet-enterprise-installer'
201
224
  the_host['roles'] = ['frictionless']
202
225
  the_host[:pe_debug] = true
203
- expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp && curl -kO https://testmaster:8140/packages/3.0/install.bash && bash -x install.bash"
226
+ expect( subject.installer_cmd( the_host, {} ) ).to be === "cd /tmp && curl --tlsv1 -kO https://testmaster:8140/packages/3.0/install.bash && bash -x install.bash"
204
227
  end
205
228
 
206
229
  end
@@ -209,90 +232,99 @@ describe ClassMixedWithDSLInstallUtils do
209
232
  describe 'fetch_puppet' do
210
233
 
211
234
  it 'can push a local PE .tar.gz to a host and unpack it' do
212
- File.stub( :directory? ).and_return( true ) #is local
213
- File.stub( :exists? ).and_return( true ) #is a .tar.gz
235
+ allow( File ).to receive( :directory? ).and_return( true ) #is local
236
+ allow( File ).to receive( :exists? ).and_return( true ) #is a .tar.gz
214
237
  unixhost['pe_dir'] = '/local/file/path'
215
- subject.stub( :scp_to ).and_return( true )
238
+ allow( subject ).to receive( :scp_to ).and_return( true )
216
239
 
217
240
  path = unixhost['pe_dir']
218
241
  filename = "#{ unixhost['dist'] }"
219
242
  extension = '.tar.gz'
220
- subject.should_receive( :scp_to ).with( unixhost, "#{ path }/#{ filename }#{ extension }", "#{ unixhost['working_dir'] }/#{ filename }#{ extension }" ).once
221
- subject.should_receive( :on ).with( unixhost, /gunzip/ ).once
222
- subject.should_receive( :on ).with( unixhost, /tar -xvf/ ).once
243
+ expect( subject ).to receive( :scp_to ).with( unixhost, "#{ path }/#{ filename }#{ extension }", "#{ unixhost['working_dir'] }/#{ filename }#{ extension }" ).once
244
+ expect( subject ).to receive( :on ).with( unixhost, /gunzip/ ).once
245
+ expect( subject ).to receive( :on ).with( unixhost, /tar -xvf/ ).once
223
246
  subject.fetch_puppet( [unixhost], {} )
224
247
  end
225
248
 
226
249
  it 'can download a PE .tar from a URL to a host and unpack it' do
227
- File.stub( :directory? ).and_return( false ) #is not local
228
- unixhost['pe_dir'] = 'http://www.path.com/dir/'
229
- subject.stub( :link_exists? ) do |arg|
250
+ allow( File ).to receive( :directory? ).and_return( false ) #is not local
251
+ allow( subject ).to receive( :link_exists? ) do |arg|
230
252
  if arg =~ /.tar.gz/ #there is no .tar.gz link, only a .tar
231
253
  false
232
254
  else
233
255
  true
234
256
  end
235
257
  end
236
- subject.stub( :on ).and_return( true )
258
+ allow( subject ).to receive( :on ).and_return( true )
237
259
 
238
260
  path = unixhost['pe_dir']
239
261
  filename = "#{ unixhost['dist'] }"
240
262
  extension = '.tar'
241
- subject.should_receive( :on ).with( unixhost, "cd #{ unixhost['working_dir'] }; curl #{ path }/#{ filename }#{ extension } | tar -xvf -" ).once
263
+ expect( subject ).to receive( :on ).with( unixhost, "cd #{ unixhost['working_dir'] }; curl #{ path }/#{ filename }#{ extension } | tar -xvf -" ).once
242
264
  subject.fetch_puppet( [unixhost], {} )
243
265
  end
244
266
 
245
267
  it 'can download a PE .tar.gz from a URL to a host and unpack it' do
246
- File.stub( :directory? ).and_return( false ) #is not local
247
- unixhost['pe_dir'] = 'http://www.path.com/dir/'
248
- subject.stub( :link_exists? ).and_return( true ) #is a tar.gz
249
- subject.stub( :on ).and_return( true )
268
+ allow( File ).to receive( :directory? ).and_return( false ) #is not local
269
+ allow( subject ).to receive( :link_exists? ).and_return( true ) #is a tar.gz
270
+ allow( subject ).to receive( :on ).and_return( true )
250
271
 
251
272
  path = unixhost['pe_dir']
252
273
  filename = "#{ unixhost['dist'] }"
253
274
  extension = '.tar.gz'
254
- subject.should_receive( :on ).with( unixhost, "cd #{ unixhost['working_dir'] }; curl #{ path }/#{ filename }#{ extension } | gunzip | tar -xvf -" ).once
275
+ expect( subject ).to receive( :on ).with( unixhost, "cd #{ unixhost['working_dir'] }; curl #{ path }/#{ filename }#{ extension } | gunzip | tar -xvf -" ).once
255
276
  subject.fetch_puppet( [unixhost], {} )
256
277
  end
257
278
 
279
+ it 'can download a PE .swix from a URL to an EOS host and unpack it' do
280
+ allow( File ).to receive( :directory? ).and_return( false ) #is not local
281
+ allow( subject ).to receive( :link_exists? ).and_return( true ) #is a tar.gz
282
+ allow( subject ).to receive( :on ).and_return( true )
283
+
284
+ path = eoshost['pe_dir']
285
+ filename = "#{ eoshost['dist'] }"
286
+ extension = '.swix'
287
+ commands = ['enable', "copy #{path}/#{filename}#{extension} extension:"]
288
+ command = commands.join("\n")
289
+ expect( subject ).to receive( :on ).with( eoshost, "Cli -c '#{command}'" ).once
290
+ subject.fetch_puppet( [eoshost], {} )
291
+ end
292
+
258
293
  it 'can push a local PE package to a windows host' do
259
- File.stub( :directory? ).and_return( true ) #is local
260
- File.stub( :exists? ).and_return( true ) #is present
261
- winhost['pe_dir'] = '/local/file/path'
294
+ allow( File ).to receive( :directory? ).and_return( true ) #is local
295
+ allow( File ).to receive( :exists? ).and_return( true ) #is present
262
296
  winhost['dist'] = 'puppet-enterprise-3.0'
263
- subject.stub( :scp_to ).and_return( true )
297
+ allow( subject ).to receive( :scp_to ).and_return( true )
264
298
 
265
299
  path = winhost['pe_dir']
266
300
  filename = "puppet-enterprise-#{ winhost['pe_ver'] }"
267
301
  extension = '.msi'
268
- subject.should_receive( :scp_to ).with( winhost, "#{ path }/#{ filename }#{ extension }", "#{ winhost['working_dir'] }/#{ filename }#{ extension }" ).once
302
+ expect( subject ).to receive( :scp_to ).with( winhost, "#{ path }/#{ filename }#{ extension }", "#{ winhost['working_dir'] }/#{ filename }#{ extension }" ).once
269
303
  subject.fetch_puppet( [winhost], {} )
270
304
 
271
305
  end
272
306
 
273
307
  it 'can download a PE dmg from a URL to a mac host' do
274
- File.stub( :directory? ).and_return( false ) #is not local
275
- machost['pe_dir'] = 'http://www.path.com/dir/'
276
- subject.stub( :link_exists? ).and_return( true ) #is not local
277
- subject.stub( :on ).and_return( true )
308
+ allow( File ).to receive( :directory? ).and_return( false ) #is not local
309
+ allow( subject ).to receive( :link_exists? ).and_return( true ) #is not local
310
+ allow( subject ).to receive( :on ).and_return( true )
278
311
 
279
312
  path = machost['pe_dir']
280
313
  filename = "#{ machost['dist'] }"
281
314
  extension = '.dmg'
282
- subject.should_receive( :on ).with( machost, "cd #{ machost['working_dir'] }; curl -O #{ path }/#{ filename }#{ extension }" ).once
315
+ expect( subject ).to receive( :on ).with( machost, "cd #{ machost['working_dir'] }; curl -O #{ path }/#{ filename }#{ extension }" ).once
283
316
  subject.fetch_puppet( [machost], {} )
284
317
  end
285
318
 
286
319
  it 'can push a PE dmg to a mac host' do
287
- File.stub( :directory? ).and_return( true ) #is local
288
- machost['pe_dir'] = 'http://www.path.com/dir/'
289
- File.stub( :exists? ).and_return( true ) #is present
290
- subject.stub( :scp_to ).and_return( true )
320
+ allow( File ).to receive( :directory? ).and_return( true ) #is local
321
+ allow( File ).to receive( :exists? ).and_return( true ) #is present
322
+ allow( subject ).to receive( :scp_to ).and_return( true )
291
323
 
292
324
  path = machost['pe_dir']
293
325
  filename = "#{ machost['dist'] }"
294
326
  extension = '.dmg'
295
- subject.should_receive( :scp_to ).with( machost, "#{ path }/#{ filename }#{ extension }", "#{ machost['working_dir'] }/#{ filename }#{ extension }" ).once
327
+ expect( subject ).to receive( :scp_to ).with( machost, "#{ path }/#{ filename }#{ extension }", "#{ machost['working_dir'] }/#{ filename }#{ extension }" ).once
296
328
  subject.fetch_puppet( [machost], {} )
297
329
  end
298
330
 
@@ -300,64 +332,69 @@ describe ClassMixedWithDSLInstallUtils do
300
332
  unixhost['roles'] << 'frictionless'
301
333
  unixhost['pe_ver'] = '3.2.0'
302
334
 
303
- subject.should_not_receive(:scp_to)
304
- subject.should_not_receive(:on)
305
- subject.stub(:version_is_less).with('3.2.0', '3.2.0').and_return(false)
335
+ expect( subject).to_not receive(:scp_to)
336
+ expect( subject).to_not receive(:on)
337
+ allow( subject ).to receive(:version_is_less).with('3.2.0', '3.2.0').and_return(false)
306
338
  subject.fetch_puppet( [unixhost], {} )
307
339
  end
308
340
  end
309
341
 
310
342
  describe 'do_install' do
311
343
  it 'can perform a simple installation' do
312
- subject.stub( :on ).and_return( Beaker::Result.new( {}, '' ) )
313
- subject.stub( :fetch_puppet ).and_return( true )
314
- subject.stub( :create_remote_file ).and_return( true )
315
- subject.stub( :sign_certificate_for ).and_return( true )
316
- subject.stub( :stop_agent_on ).and_return( true )
317
- subject.stub( :sleep_until_puppetdb_started ).and_return( true )
318
- subject.stub( :version_is_less ).with('3.0', '3.4').and_return( true )
319
- subject.stub( :version_is_less ).with('3.0', '3.0').and_return( false )
320
- subject.stub( :wait_for_host_in_dashboard ).and_return( true )
321
- subject.stub( :puppet_agent ).and_return do |arg|
344
+ allow( subject ).to receive( :on ).and_return( Beaker::Result.new( {}, '' ) )
345
+ allow( subject ).to receive( :fetch_puppet ).and_return( true )
346
+ allow( subject ).to receive( :create_remote_file ).and_return( true )
347
+ allow( subject ).to receive( :sign_certificate_for ).and_return( true )
348
+ allow( subject ).to receive( :stop_agent_on ).and_return( true )
349
+ allow( subject ).to receive( :sleep_until_puppetdb_started ).and_return( true )
350
+ allow( subject ).to receive( :version_is_less ).with('3.0', '3.4').and_return( true )
351
+ allow( subject ).to receive( :version_is_less ).with('3.0', '3.0').and_return( false )
352
+ allow( subject ).to receive( :version_is_less ).with('3.0', '3.4').and_return( true )
353
+ allow( subject ).to receive( :wait_for_host_in_dashboard ).and_return( true )
354
+ allow( subject ).to receive( :puppet_agent ) do |arg|
322
355
  "puppet agent #{arg}"
323
356
  end
324
- subject.stub( :puppet ).and_return do |arg|
357
+ allow( subject ).to receive( :puppet ) do |arg|
325
358
  "puppet #{arg}"
326
359
  end
327
360
 
328
- subject.stub( :hosts ).and_return( hosts )
361
+ allow( subject ).to receive( :hosts ).and_return( hosts )
329
362
  #create answers file per-host, except windows
330
- subject.should_receive( :create_remote_file ).with( hosts[0], /answers/, /q/ ).once
363
+ expect( subject ).to receive( :create_remote_file ).with( hosts[0], /answers/, /q/ ).once
331
364
  #run installer on all hosts
332
- subject.should_receive( :on ).with( hosts[0], /puppet-enterprise-installer/ ).once
333
- subject.should_receive( :on ).with( hosts[1], /msiexec.exe/ ).once
334
- subject.should_receive( :on ).with( hosts[2], / hdiutil attach puppet-enterprise-3.0-osx-10.9-x86_64.dmg && installer -pkg \/Volumes\/puppet-enterprise-3.0\/puppet-enterprise-installer-3.0.pkg -target \// ).once
335
- #does extra mac specific commands
336
- subject.should_receive( :on ).with( hosts[2], /puppet config set server/ ).once
337
- subject.should_receive( :on ).with( hosts[2], /puppet config set certname/ ).once
338
- subject.should_receive( :on ).with( hosts[2], /puppet agent -t/, :acceptable_exit_codes => [1] ).once
365
+ expect( subject ).to receive( :on ).with( hosts[0], /puppet-enterprise-installer/ ).once
366
+ expect( subject ).to receive( :on ).with( hosts[1], /msiexec.exe/ ).once
367
+ expect( subject ).to receive( :on ).with( hosts[2], / hdiutil attach puppet-enterprise-3.0-osx-10.9-x86_64.dmg && installer -pkg \/Volumes\/puppet-enterprise-3.0\/puppet-enterprise-installer-3.0.pkg -target \// ).once
368
+ expect( subject ).to receive( :on ).with( hosts[3], /^Cli/ ).once
369
+ #does extra mac/EOS specific commands
370
+ expect( subject ).to receive( :on ).with( hosts[2], /puppet config set server/ ).once
371
+ expect( subject ).to receive( :on ).with( hosts[3], /puppet config set server/ ).once
372
+ expect( subject ).to receive( :on ).with( hosts[2], /puppet config set certname/ ).once
373
+ expect( subject ).to receive( :on ).with( hosts[3], /puppet config set certname/ ).once
374
+ expect( subject ).to receive( :on ).with( hosts[2], /puppet agent -t/, :acceptable_exit_codes => [1] ).once
375
+ expect( subject ).to receive( :on ).with( hosts[3], /puppet agent -t/, :acceptable_exit_codes => [1] ).once
339
376
  #sign certificate per-host
340
- subject.should_receive( :sign_certificate_for ).with( hosts[0] ).once
341
- subject.should_receive( :sign_certificate_for ).with( hosts[1] ).once
342
- subject.should_receive( :sign_certificate_for ).with( hosts[2] ).once
377
+ expect( subject ).to receive( :sign_certificate_for ).with( hosts[0] ).once
378
+ expect( subject ).to receive( :sign_certificate_for ).with( hosts[1] ).once
379
+ expect( subject ).to receive( :sign_certificate_for ).with( hosts[2] ).once
380
+ expect( subject ).to receive( :sign_certificate_for ).with( hosts[3] ).once
343
381
  #stop puppet agent on all hosts
344
- subject.should_receive( :stop_agent_on ).with( hosts[0] ).once
345
- subject.should_receive( :stop_agent_on ).with( hosts[1] ).once
346
- subject.should_receive( :stop_agent_on ).with( hosts[2] ).once
382
+ expect( subject ).to receive( :stop_agent_on ).with( hosts[0] ).once
383
+ expect( subject ).to receive( :stop_agent_on ).with( hosts[1] ).once
384
+ expect( subject ).to receive( :stop_agent_on ).with( hosts[2] ).once
385
+ expect( subject ).to receive( :stop_agent_on ).with( hosts[3] ).once
347
386
  #wait for puppetdb to start
348
- subject.should_receive( :sleep_until_puppetdb_started ).with( hosts[0] ).once
387
+ expect( subject ).to receive( :sleep_until_puppetdb_started ).with( hosts[0] ).once
349
388
  #run each puppet agent once
350
- subject.should_receive( :on ).with( hosts[0], /puppet agent -t/, :acceptable_exit_codes => [0,2] ).once
351
- subject.should_receive( :on ).with( hosts[1], /puppet agent -t/, :acceptable_exit_codes => [0,2] ).once
352
- subject.should_receive( :on ).with( hosts[2], /puppet agent -t/, :acceptable_exit_codes => [0,2] ).once
389
+ expect( subject ).to receive( :on ).with( hosts[0], /puppet agent -t/, :acceptable_exit_codes => [0,2] ).once
390
+ expect( subject ).to receive( :on ).with( hosts[1], /puppet agent -t/, :acceptable_exit_codes => [0,2] ).once
391
+ expect( subject ).to receive( :on ).with( hosts[2], /puppet agent -t/, :acceptable_exit_codes => [0,2] ).once
392
+ expect( subject ).to receive( :on ).with( hosts[3], /puppet agent -t/, :acceptable_exit_codes => [0,2] ).once
353
393
  #run rake task on dashboard
354
- subject.should_receive( :on ).with( hosts[0], /\/opt\/puppet\/bin\/rake -sf \/opt\/puppet\/share\/puppet-dashboard\/Rakefile .* RAILS_ENV=production/ ).once
394
+ expect( subject ).to receive( :on ).with( hosts[0], /\/opt\/puppet\/bin\/rake -sf \/opt\/puppet\/share\/puppet-dashboard\/Rakefile .* RAILS_ENV=production/ ).once
355
395
  #wait for all hosts to appear in the dashboard
356
- subject.should_receive( :wait_for_host_in_dashboard ).with( hosts[0] ).once
357
- subject.should_receive( :wait_for_host_in_dashboard ).with( hosts[1] ).once
358
- subject.should_receive( :wait_for_host_in_dashboard ).with( hosts[2] ).once
359
396
  #run puppet agent now that installation is complete
360
- subject.should_receive( :on ).with( hosts, /puppet agent/, :acceptable_exit_codes => [0,2] ).once
397
+ expect( subject ).to receive( :on ).with( hosts, /puppet agent/, :acceptable_exit_codes => [0,2] ).once
361
398
  subject.do_install( hosts, opts )
362
399
  end
363
400
  end
@@ -366,13 +403,13 @@ describe ClassMixedWithDSLInstallUtils do
366
403
 
367
404
  before :each do
368
405
  my_time = double( "time double" )
369
- my_time.stub( :strftime ).and_return( "2014-07-01_15.27.53" )
370
- Time.stub( :new ).and_return( my_time )
406
+ allow( my_time ).to receive( :strftime ).and_return( "2014-07-01_15.27.53" )
407
+ allow( Time ).to receive( :new ).and_return( my_time )
371
408
 
372
409
  hosts[0]['working_dir'] = "tmp/2014-07-01_15.27.53"
373
410
  hosts[0]['dist'] = 'dist'
374
411
  hosts[0]['pe_installer'] = 'pe-installer'
375
- hosts[0].stub( :tmpdir ).and_return( "/tmp/2014-07-01_15.27.53" )
412
+ allow( hosts[0] ).to receive( :tmpdir ).and_return( "/tmp/2014-07-01_15.27.53" )
376
413
 
377
414
  @fail_result = Beaker::Result.new( {}, '' )
378
415
  @fail_result.stdout = "No match here"
@@ -381,32 +418,32 @@ describe ClassMixedWithDSLInstallUtils do
381
418
  end
382
419
 
383
420
  it 'can perform a simple installation' do
384
- subject.stub( :fetch_puppet ).and_return( true )
385
- subject.stub( :sleep ).and_return( true )
421
+ allow( subject ).to receive( :fetch_puppet ).and_return( true )
422
+ allow( subject ).to receive( :sleep ).and_return( true )
386
423
 
387
- subject.stub( :hosts ).and_return( hosts )
424
+ allow( subject ).to receive( :hosts ).and_return( hosts )
388
425
 
389
426
  #run higgs installer command
390
- subject.should_receive( :on ).with( hosts[0],
427
+ expect( subject ).to receive( :on ).with( hosts[0],
391
428
  "cd /tmp/2014-07-01_15.27.53/puppet-enterprise-3.0-linux ; nohup ./pe-installer <<<Y > higgs_2014-07-01_15.27.53.log 2>&1 &",
392
429
  opts ).once
393
430
  #check to see if the higgs installation has proceeded correctly, works on second check
394
- subject.should_receive( :on ).with( hosts[0], /cat #{hosts[0]['higgs_file']}/, { :acceptable_exit_codes => 0..255 }).and_return( @fail_result, @success_result )
431
+ expect( subject ).to receive( :on ).with( hosts[0], /cat #{hosts[0]['higgs_file']}/, { :acceptable_exit_codes => 0..255 }).and_return( @fail_result, @success_result )
395
432
  subject.do_higgs_install( hosts[0], opts )
396
433
  end
397
434
 
398
435
  it 'fails out after checking installation log 10 times' do
399
- subject.stub( :fetch_puppet ).and_return( true )
400
- subject.stub( :sleep ).and_return( true )
436
+ allow( subject ).to receive( :fetch_puppet ).and_return( true )
437
+ allow( subject ).to receive( :sleep ).and_return( true )
401
438
 
402
- subject.stub( :hosts ).and_return( hosts )
439
+ allow( subject ).to receive( :hosts ).and_return( hosts )
403
440
 
404
441
  #run higgs installer command
405
- subject.should_receive( :on ).with( hosts[0],
442
+ expect( subject ).to receive( :on ).with( hosts[0],
406
443
  "cd /tmp/2014-07-01_15.27.53/puppet-enterprise-3.0-linux ; nohup ./pe-installer <<<Y > higgs_2014-07-01_15.27.53.log 2>&1 &",
407
444
  opts ).once
408
445
  #check to see if the higgs installation has proceeded correctly, works on second check
409
- subject.should_receive( :on ).with( hosts[0], /cat #{hosts[0]['higgs_file']}/, { :acceptable_exit_codes => 0..255 }).exactly(10).times.and_return( @fail_result )
446
+ expect( subject ).to receive( :on ).with( hosts[0], /cat #{hosts[0]['higgs_file']}/, { :acceptable_exit_codes => 0..255 }).exactly(10).times.and_return( @fail_result )
410
447
  expect{ subject.do_higgs_install( hosts[0], opts ) }.to raise_error
411
448
  end
412
449
 
@@ -418,8 +455,8 @@ describe ClassMixedWithDSLInstallUtils do
418
455
  end
419
456
 
420
457
  before do
421
- subject.stub(:hosts).and_return(hosts)
422
- subject.stub(:on).and_return(Beaker::Result.new({},''))
458
+ allow( subject ).to receive(:hosts).and_return(hosts)
459
+ allow( subject ).to receive(:on).and_return(Beaker::Result.new({},''))
423
460
  end
424
461
  context 'on el-6' do
425
462
  let(:platform) { "el-6-i386" }
@@ -475,6 +512,21 @@ describe ClassMixedWithDSLInstallUtils do
475
512
  subject.install_puppet( :version => '3000', :facter_version => '1999', :hiera_version => '2001' )
476
513
  end
477
514
  end
515
+ context 'on windows' do
516
+ let(:platform) { "windows-2008r2-i386" }
517
+ it 'installs specific version of puppet when passed :version' do
518
+ allow(subject).to receive(:link_exists?).and_return( true )
519
+ expect(subject).to receive(:on).with(hosts[0], 'curl -O http://downloads.puppetlabs.com/windows/puppet-3000.msi')
520
+ expect(subject).to receive(:on).with(hosts[0], 'msiexec /qn /i puppet-3000.msi')
521
+ subject.install_puppet(:version => '3000')
522
+ end
523
+ it 'installs from custom url when passed :win_download_url' do
524
+ allow(subject).to receive(:link_exists?).and_return( true )
525
+ expect(subject).to receive(:on).with(hosts[0], 'curl -O http://nightlies.puppetlabs.com/puppet-latest/repos/windows/puppet-3000.msi')
526
+ expect(subject).to receive(:on).with(hosts[0], 'msiexec /qn /i puppet-3000.msi')
527
+ subject.install_puppet( :version => '3000', :win_download_url => 'http://nightlies.puppetlabs.com/puppet-latest/repos/windows' )
528
+ end
529
+ end
478
530
  describe 'on unsupported platforms' do
479
531
  let(:platform) { 'solaris-11-x86_64' }
480
532
  let(:host) { make_host('henry', :platform => 'solaris-11-x86_64') }
@@ -494,13 +546,44 @@ describe ClassMixedWithDSLInstallUtils do
494
546
  end
495
547
  end
496
548
 
549
+ describe '#add_system32_hosts_entry' do
550
+ before do
551
+ allow( subject ).to receive(:on).and_return(Beaker::Result.new({},''))
552
+ end
553
+ context 'on debian' do
554
+ let(:platform) { 'debian-7-amd64' }
555
+ let(:host) { make_host('testbox.test.local', :platform => 'debian-7-amd64') }
556
+ it 'logs message - nothing to do on this host' do
557
+ expect( Beaker::Command ).to receive( :new ).never
558
+
559
+ expect {
560
+ subject.add_system32_hosts_entry(host, {})
561
+ }.to raise_error
562
+ end
563
+ end
564
+ context 'on windows' do
565
+ let(:platform) { 'windows-2008R2-amd64' }
566
+ let(:host) { make_host('testbox.test.local', :platform => 'windows-2008R2-amd64') }
567
+ it 'it add an entry into the /etc/hosts file' do
568
+ entry = { 'ip' => '23.251.154.122', 'name' => 'forge.puppetlabs.com' }
569
+ expect(subject).to receive(:on) do |host, command|
570
+ expect(command.command).to eq('powershell.exe')
571
+ expect(command.args).to eq(" -ExecutionPolicy Bypass -InputFormat None -NoLogo -NoProfile -NonInteractive -Command \"$text = \\\"23.251.154.122`t`tforge.puppetlabs.com\\\"; Add-Content -path 'C:\\Windows\\System32\\Drivers\\etc\\hosts' -value $text\"")
572
+ end
573
+
574
+
575
+ subject.add_system32_hosts_entry(host, entry)
576
+ end
577
+ end
578
+ end
579
+
497
580
  describe 'install_pe' do
498
581
 
499
582
  it 'calls do_install with sorted hosts' do
500
- subject.stub( :options ).and_return( {} )
501
- subject.stub( :hosts ).and_return( [ hosts[1], hosts[0], hosts[2] ] )
502
- subject.stub( :do_install ).and_return( true )
503
- subject.should_receive( :do_install ).with( hosts, {} )
583
+ allow( subject ).to receive( :options ).and_return( {} )
584
+ allow( subject ).to receive( :hosts ).and_return( hosts_sorted )
585
+ allow( subject ).to receive( :do_install ).and_return( true )
586
+ expect( subject ).to receive( :do_install ).with( hosts, {} )
504
587
  subject.install_pe
505
588
  end
506
589
 
@@ -508,11 +591,11 @@ describe ClassMixedWithDSLInstallUtils do
508
591
  hosts.each do |h|
509
592
  h['pe_ver'] = nil
510
593
  end
511
- Beaker::Options::PEVersionScraper.stub( :load_pe_version ).and_return( '2.8' )
512
- subject.stub( :hosts ).and_return( [ hosts[1], hosts[0], hosts[2] ] )
513
- subject.stub( :options ).and_return( {} )
514
- subject.stub( :do_install ).and_return( true )
515
- subject.should_receive( :do_install ).with( hosts, {} )
594
+ allow( Beaker::Options::PEVersionScraper ).to receive( :load_pe_version ).and_return( '2.8' )
595
+ allow( subject ).to receive( :hosts ).and_return( hosts_sorted )
596
+ allow( subject ).to receive( :options ).and_return( {} )
597
+ allow( subject ).to receive( :do_install ).and_return( true )
598
+ expect( subject ).to receive( :do_install ).with( hosts, {} )
516
599
  subject.install_pe
517
600
  hosts.each do |h|
518
601
  expect( h['pe_ver'] ).to be === '2.8'
@@ -523,11 +606,11 @@ describe ClassMixedWithDSLInstallUtils do
523
606
  describe 'install_higgs' do
524
607
  it 'fills in missing pe_ver' do
525
608
  hosts[0]['pe_ver'] = nil
526
- Beaker::Options::PEVersionScraper.stub( :load_pe_version ).and_return( '2.8' )
527
- subject.stub( :hosts ).and_return( [ hosts[1], hosts[0], hosts[2] ] )
528
- subject.stub( :options ).and_return( {} )
529
- subject.stub( :do_higgs_install ).and_return( true )
530
- subject.should_receive( :do_higgs_install ).with( hosts[0], {} )
609
+ allow( Beaker::Options::PEVersionScraper ).to receive( :load_pe_version ).and_return( '2.8' )
610
+ allow( subject ).to receive( :hosts ).and_return( [ hosts[1], hosts[0], hosts[2] ] )
611
+ allow( subject ).to receive( :options ).and_return( {} )
612
+ allow( subject ).to receive( :do_higgs_install ).and_return( true )
613
+ expect( subject ).to receive( :do_higgs_install ).with( hosts[0], {} )
531
614
  subject.install_higgs
532
615
  expect( hosts[0]['pe_ver'] ).to be === '2.8'
533
616
  end
@@ -537,15 +620,15 @@ describe ClassMixedWithDSLInstallUtils do
537
620
  describe 'upgrade_pe' do
538
621
 
539
622
  it 'calls puppet-enterprise-upgrader for pre 3.0 upgrades' do
540
- Beaker::Options::PEVersionScraper.stub( :load_pe_version ).and_return( '2.8' )
541
- Beaker::Options::PEVersionScraper.stub( :load_pe_version_win ).and_return( '2.8' )
623
+ allow( Beaker::Options::PEVersionScraper ).to receive( :load_pe_version ).and_return( '2.8' )
624
+ allow( Beaker::Options::PEVersionScraper ).to receive( :load_pe_version_win ).and_return( '2.8' )
542
625
  the_hosts = [ hosts[0].dup, hosts[1].dup, hosts[2].dup ]
543
- subject.stub( :hosts ).and_return( the_hosts )
544
- subject.stub( :options ).and_return( {} )
545
- subject.stub( :version_is_less ).with('2.8', '3.0').and_return( true )
626
+ allow( subject ).to receive( :hosts ).and_return( the_hosts )
627
+ allow( subject ).to receive( :options ).and_return( {} )
628
+ allow( subject ).to receive( :version_is_less ).with('2.8', '3.0').and_return( true )
546
629
  version = version_win = '2.8'
547
630
  path = "/path/to/upgradepkg"
548
- subject.should_receive( :do_install ).with( the_hosts, { :type => :upgrade } )
631
+ expect( subject ).to receive( :do_install ).with( the_hosts, { :type => :upgrade } )
549
632
  subject.upgrade_pe( path )
550
633
  the_hosts.each do |h|
551
634
  expect( h['pe_installer'] ).to be === 'puppet-enterprise-upgrader'
@@ -553,15 +636,15 @@ describe ClassMixedWithDSLInstallUtils do
553
636
  end
554
637
 
555
638
  it 'uses standard upgrader for post 3.0 upgrades' do
556
- Beaker::Options::PEVersionScraper.stub( :load_pe_version ).and_return( '3.1' )
557
- Beaker::Options::PEVersionScraper.stub( :load_pe_version_win ).and_return( '3.1' )
639
+ allow( Beaker::Options::PEVersionScraper ).to receive( :load_pe_version ).and_return( '3.1' )
640
+ allow( Beaker::Options::PEVersionScraper ).to receive( :load_pe_version_win ).and_return( '3.1' )
558
641
  the_hosts = [ hosts[0].dup, hosts[1].dup, hosts[2].dup ]
559
- subject.stub( :hosts ).and_return( the_hosts )
560
- subject.stub( :options ).and_return( {} )
561
- subject.stub( :version_is_less ).with('3.1', '3.0').and_return( false )
642
+ allow( subject ).to receive( :hosts ).and_return( the_hosts )
643
+ allow( subject ).to receive( :options ).and_return( {} )
644
+ allow( subject ).to receive( :version_is_less ).with('3.1', '3.0').and_return( false )
562
645
  version = version_win = '3.1'
563
646
  path = "/path/to/upgradepkg"
564
- subject.should_receive( :do_install ).with( the_hosts, { :type => :upgrade } )
647
+ expect( subject ).to receive( :do_install ).with( the_hosts, { :type => :upgrade } )
565
648
  subject.upgrade_pe( path )
566
649
  the_hosts.each do |h|
567
650
  expect( h['pe_installer'] ).to be nil
@@ -569,15 +652,15 @@ describe ClassMixedWithDSLInstallUtils do
569
652
  end
570
653
 
571
654
  it 'updates pe_ver post upgrade' do
572
- Beaker::Options::PEVersionScraper.stub( :load_pe_version ).and_return( '2.8' )
573
- Beaker::Options::PEVersionScraper.stub( :load_pe_version_win ).and_return( '2.8' )
655
+ allow( Beaker::Options::PEVersionScraper ).to receive( :load_pe_version ).and_return( '2.8' )
656
+ allow( Beaker::Options::PEVersionScraper ).to receive( :load_pe_version_win ).and_return( '2.8' )
574
657
  the_hosts = [ hosts[0].dup, hosts[1].dup, hosts[2].dup ]
575
- subject.stub( :hosts ).and_return( the_hosts )
576
- subject.stub( :options ).and_return( {} )
577
- subject.stub( :version_is_less ).with('2.8', '3.0').and_return( true )
658
+ allow( subject ).to receive( :hosts ).and_return( the_hosts )
659
+ allow( subject ).to receive( :options ).and_return( {} )
660
+ allow( subject ).to receive( :version_is_less ).with('2.8', '3.0').and_return( true )
578
661
  version = version_win = '2.8'
579
662
  path = "/path/to/upgradepkg"
580
- subject.should_receive( :do_install ).with( the_hosts, { :type => :upgrade } )
663
+ expect( subject ).to receive( :do_install ).with( the_hosts, { :type => :upgrade } )
581
664
  subject.upgrade_pe( path )
582
665
  the_hosts.each do |h|
583
666
  expect( h['pe_ver'] ).to be === '2.8'
@@ -588,8 +671,6 @@ describe ClassMixedWithDSLInstallUtils do
588
671
 
589
672
 
590
673
  def fetch_allows
591
- allow(File).to receive( :exists? ) { true }
592
- allow(File).to receive( :open ).and_yield()
593
674
  allow(subject).to receive( :logger ) { logger }
594
675
  end
595
676
 
@@ -603,6 +684,7 @@ describe ClassMixedWithDSLInstallUtils do
603
684
  describe "given valid arguments" do
604
685
 
605
686
  it "returns its second and third arguments concatenated." do
687
+ create_files(['destdir/name'])
606
688
  result = subject.fetch_http_file "http://beaker.tool/", "name", "destdir"
607
689
  expect(result).to eq("destdir/name")
608
690
  end
@@ -623,6 +705,7 @@ describe ClassMixedWithDSLInstallUtils do
623
705
 
624
706
  it "returns basename of first argument concatenated to second." do
625
707
  expect(subject).to receive(:`).with(/^wget.*/).ordered { result }
708
+ expect($?).to receive(:to_i).and_return(0)
626
709
  result = subject.fetch_http_dir "http://beaker.tool/beep", "destdir"
627
710
  expect(result).to eq("destdir/beep")
628
711
  end
@@ -730,32 +813,32 @@ describe ClassMixedWithDSLInstallUtils do
730
813
  end
731
814
 
732
815
  describe '#install_dev_puppet_module_on' do
733
- context 'having set a stub forge' do
816
+ context 'having set allow( a ).to receive forge' do
734
817
  it 'stubs the forge on the host' do
735
818
  master = hosts.first
736
- subject.stub( :options ).and_return( {:forge_host => 'ahost.com'} )
819
+ allow( subject ).to receive( :options ).and_return( {:forge_host => 'ahost.com'} )
737
820
 
738
- subject.should_receive( :with_forge_stubbed_on )
821
+ expect( subject ).to receive( :with_forge_stubbed_on )
739
822
 
740
823
  subject.install_dev_puppet_module_on( master, {:source => '/module', :module_name => 'test'} )
741
824
  end
742
825
 
743
826
  it 'installs via #install_puppet_module_via_pmt' do
744
827
  master = hosts.first
745
- subject.stub( :options ).and_return( {:forge_host => 'ahost.com'} )
746
- subject.stub( :with_forge_stubbed_on ).and_yield
828
+ allow( subject ).to receive( :options ).and_return( {:forge_host => 'ahost.com'} )
829
+ allow( subject ).to receive( :with_forge_stubbed_on ).and_yield
747
830
 
748
- subject.should_receive( :install_puppet_module_via_pmt_on )
831
+ expect( subject ).to receive( :install_puppet_module_via_pmt_on )
749
832
 
750
833
  subject.install_dev_puppet_module_on( master, {:source => '/module', :module_name => 'test'} )
751
834
  end
752
835
  end
753
- context 'without a stub forge (default)' do
836
+ context 'without allow( a ).to receive forge (default)' do
754
837
  it 'calls copy_module_to to get the module on the SUT' do
755
838
  master = hosts.first
756
- subject.stub( :options ).and_return( {} )
839
+ allow( subject ).to receive( :options ).and_return( {} )
757
840
 
758
- subject.should_receive( :copy_module_to )
841
+ expect( subject ).to receive( :copy_module_to )
759
842
 
760
843
  subject.install_dev_puppet_module_on( master, {:source => '/module', :module_name => 'test'} )
761
844
  end
@@ -764,11 +847,11 @@ describe ClassMixedWithDSLInstallUtils do
764
847
 
765
848
  describe '#install_dev_puppet_module' do
766
849
  it 'delegates to #install_dev_puppet_module_on with the hosts list' do
767
- subject.stub( :hosts ).and_return( hosts )
768
- subject.stub( :options ).and_return( {} )
850
+ allow( subject ).to receive( :hosts ).and_return( hosts )
851
+ allow( subject ).to receive( :options ).and_return( {} )
769
852
 
770
853
  hosts.each do |host|
771
- subject.should_receive( :install_dev_puppet_module_on ).
854
+ expect( subject ).to receive( :install_dev_puppet_module_on ).
772
855
  with( host, {:source => '/module', :module_name => 'test'})
773
856
  end
774
857
 
@@ -778,10 +861,22 @@ describe ClassMixedWithDSLInstallUtils do
778
861
 
779
862
  describe '#install_puppet_module_via_pmt_on' do
780
863
  it 'installs module via puppet module tool' do
781
- subject.stub( :hosts ).and_return( hosts )
864
+ allow( subject ).to receive( :hosts ).and_return( hosts )
865
+ master = hosts.first
866
+
867
+
868
+ expect( subject ).to receive( :puppet ).with('module install test ', {}).once
869
+
870
+ subject.install_puppet_module_via_pmt_on( master, {:module_name => 'test'} )
871
+ end
872
+
873
+ it 'takes the trace option and passes it down correctly' do
874
+ allow( subject ).to receive( :hosts ).and_return( hosts )
782
875
  master = hosts.first
876
+ trace_opts = { :trace => nil }
877
+ master['default_module_install_opts'] = trace_opts
783
878
 
784
- subject.should_receive( :puppet ).with('module install test ' ).once
879
+ expect( subject ).to receive( :puppet ).with('module install test ', trace_opts).once
785
880
 
786
881
  subject.install_puppet_module_via_pmt_on( master, {:module_name => 'test'} )
787
882
  end
@@ -789,9 +884,9 @@ describe ClassMixedWithDSLInstallUtils do
789
884
 
790
885
  describe '#install_puppet_module_via_pmt' do
791
886
  it 'delegates to #install_puppet_module_via_pmt with the hosts list' do
792
- subject.stub( :hosts ).and_return( hosts )
887
+ allow( subject ).to receive( :hosts ).and_return( hosts )
793
888
 
794
- subject.should_receive( :install_puppet_module_via_pmt_on ).with( hosts, {:source => '/module', :module_name => 'test'}).once
889
+ expect( subject ).to receive( :install_puppet_module_via_pmt_on ).with( hosts, {:source => '/module', :module_name => 'test'}).once
795
890
 
796
891
  subject.install_puppet_module_via_pmt( {:source => '/module', :module_name => 'test'} )
797
892
  end
@@ -806,24 +901,24 @@ describe ClassMixedWithDSLInstallUtils do
806
901
  shared_examples 'copy_module_to' do |opts|
807
902
  it{
808
903
  host = double("host")
809
- host.stub(:[]).with('distmoduledir').and_return('/etc/puppetlabs/puppet/modules')
904
+ allow( host ).to receive(:[]).with('distmoduledir').and_return('/etc/puppetlabs/puppet/modules')
810
905
  result = double
811
906
  stdout = target.split('/')[0..-2].join('/') + "\n"
812
- result.stub(:stdout).and_return( stdout )
813
- host.stub(:exec).with( any_args ).and_return( result )
814
- Dir.stub(:getpwd).and_return(source)
907
+ allow( result ).to receive(:stdout).and_return( stdout )
908
+ allow( host ).to receive(:exec).with( any_args ).and_return( result )
909
+ allow( Dir ).to receive(:getpwd).and_return(source)
815
910
 
816
- subject.stub(:parse_for_moduleroot).and_return(source)
911
+ allow( subject ).to receive(:parse_for_moduleroot).and_return(source)
817
912
  if module_parse_name
818
- subject.stub(:parse_for_modulename).with(any_args()).and_return(module_parse_name)
913
+ allow( subject ).to receive(:parse_for_modulename).with(any_args()).and_return(module_parse_name)
819
914
  else
820
- subject.should_not_receive(:parse_for_modulename)
915
+ expect( subject).to_not receive(:parse_for_modulename)
821
916
  end
822
917
 
823
- File.stub(:exists?).with(any_args()).and_return(false)
824
- File.stub(:directory?).with(any_args()).and_return(false)
918
+ allow( File ).to receive(:exists?).with(any_args()).and_return(false)
919
+ allow( File ).to receive(:directory?).with(any_args()).and_return(false)
825
920
 
826
- subject.should_receive(:scp_to).with(host,source, target, {:ignore => ignore_list})
921
+ expect( subject ).to receive(:scp_to).with(host,source, target, {:ignore => ignore_list})
827
922
  if opts.nil?
828
923
  subject.copy_module_to(host)
829
924
  else
@@ -831,21 +926,36 @@ describe ClassMixedWithDSLInstallUtils do
831
926
  end
832
927
  }
833
928
  end
929
+
834
930
  describe 'should call scp with the correct info, with only providing host' do
835
931
  let(:target){'/etc/puppetlabs/puppet/modules/testmodule'}
836
932
 
837
933
  it_should_behave_like 'copy_module_to', :module_name => 'testmodule'
838
934
  end
935
+
839
936
  describe 'should call scp with the correct info, when specifying the modulename' do
840
937
  let(:target){'/etc/puppetlabs/puppet/modules/bogusmodule'}
841
938
  let(:module_parse_name){false}
842
939
  it_should_behave_like 'copy_module_to', {:module_name =>'bogusmodule'}
843
940
  end
941
+
844
942
  describe 'should call scp with the correct info, when specifying the target to a different path' do
845
943
  target = '/opt/shared/puppet/modules'
846
944
  let(:target){"#{target}/testmodule"}
847
945
  it_should_behave_like 'copy_module_to', {:target_module_path => target, :module_name => 'testmodule'}
848
946
  end
947
+
948
+ describe 'should accept multiple hosts when' do
949
+ it 'used in a default manner' do
950
+ allow( subject ).to receive( :build_ignore_list ).and_return( [] )
951
+ allow( subject ).to receive( :parse_for_modulename ).and_return( [nil, 'modulename'] )
952
+ allow( subject ).to receive( :on ).and_return( double.as_null_object )
953
+ hosts = [{}, {}]
954
+
955
+ expect( subject ).to receive( :scp_to ).twice
956
+ subject.copy_module_to( hosts )
957
+ end
958
+ end
849
959
  end
850
960
 
851
961
  describe 'split_author_modulename' do
@@ -868,35 +978,46 @@ describe ClassMixedWithDSLInstallUtils do
868
978
  describe 'parse_for_modulename' do
869
979
  directory = '/testfilepath/myname-testmodule'
870
980
  it 'should return name from metadata.json' do
871
- File.stub(:exists?).with("#{directory}/metadata.json").and_return(true)
872
- File.stub(:read).with("#{directory}/metadata.json").and_return(" {\"name\":\"myname-testmodule\"} ")
873
- subject.logger.should_receive(:debug).with("Attempting to parse Modulename from metadata.json")
874
- subject.logger.should_not_receive(:debug).with('Unable to determine name, returning null')
875
- subject.parse_for_modulename(directory).should eq(['myname', 'testmodule'])
981
+ allow( File ).to receive(:exists?).with("#{directory}/metadata.json").and_return(true)
982
+ allow( File ).to receive(:read).with("#{directory}/metadata.json").and_return(" {\"name\":\"myname-testmodule\"} ")
983
+ expect( subject.logger ).to receive(:debug).with("Attempting to parse Modulename from metadata.json")
984
+ expect(subject.logger).to_not receive(:debug).with('Unable to determine name, returning null')
985
+ expect(subject.parse_for_modulename(directory)).to eq(['myname', 'testmodule'])
876
986
  end
877
987
  it 'should return name from Modulefile' do
878
- File.stub(:exists?).with("#{directory}/metadata.json").and_return(false)
879
- File.stub(:exists?).with("#{directory}/Modulefile").and_return(true)
880
- File.stub(:read).with("#{directory}/Modulefile").and_return("name 'myname-testmodule' \nauthor 'myname'")
881
- subject.logger.should_receive(:debug).with("Attempting to parse Modulename from Modulefile")
882
- subject.logger.should_not_receive(:debug).with("Unable to determine name, returning null")
988
+ allow( File ).to receive(:exists?).with("#{directory}/metadata.json").and_return(false)
989
+ allow( File ).to receive(:exists?).with("#{directory}/Modulefile").and_return(true)
990
+ allow( File ).to receive(:read).with("#{directory}/Modulefile").and_return("name 'myname-testmodule' \nauthor 'myname'")
991
+ expect( subject.logger ).to receive(:debug).with("Attempting to parse Modulename from Modulefile")
992
+ expect(subject.logger).to_not receive(:debug).with("Unable to determine name, returning null")
883
993
  expect(subject.parse_for_modulename(directory)).to eq(['myname', 'testmodule'])
884
994
  end
885
995
  end
886
996
 
887
997
  describe 'parse_for_module_root' do
888
998
  directory = '/testfilepath/myname-testmodule'
889
- it 'should recersively go up the directory to find the module files' do
890
- File.stub(:exists?).with("#{directory}/acceptance/Modulefile").and_return(false)
891
- File.stub(:exists?).with("#{directory}/Modulefile").and_return(true)
892
- subject.logger.should_not_receive(:debug).with("At root, can't parse for another directory")
893
- subject.logger.should_receive(:debug).with("No Modulefile found at #{directory}/acceptance, moving up")
894
- expect(subject.parse_for_moduleroot("#{directory}/acceptance")).to eq(directory)
999
+ describe 'stops searching when either' do
1000
+ it 'finds a Modulefile' do
1001
+ allow( File ).to receive(:exists?).and_return(false)
1002
+ allow( File ).to receive(:exists?).with("#{directory}/Modulefile").and_return(true)
1003
+
1004
+ expect( subject.logger ).to_not receive(:debug).with("At root, can't parse for another directory")
1005
+ expect( subject.logger ).to receive(:debug).with("No Modulefile or metadata.json found at #{directory}/acceptance, moving up")
1006
+ expect(subject.parse_for_moduleroot("#{directory}/acceptance")).to eq(directory)
1007
+ end
1008
+ it 'finds a metadata.json file' do
1009
+ allow( File ).to receive(:exists?).and_return(false)
1010
+ allow( File ).to receive(:exists?).with("#{directory}/metadata.json").and_return(true)
1011
+
1012
+ expect( subject.logger ).to_not receive(:debug).with("At root, can't parse for another directory")
1013
+ expect( subject.logger ).to receive(:debug).with("No Modulefile or metadata.json found at #{directory}/acceptance, moving up")
1014
+ expect(subject.parse_for_moduleroot("#{directory}/acceptance")).to eq(directory)
1015
+ end
895
1016
  end
896
1017
  it 'should recersively go up the directory to find the module files' do
897
- File.stub(:exists?).and_return(false)
898
- subject.logger.should_receive(:debug).with("No Modulefile found at #{directory}, moving up")
899
- subject.logger.should_receive(:error).with("At root, can't parse for another directory")
1018
+ allow( File ).to receive(:exists?).and_return(false)
1019
+ expect( subject.logger ).to receive(:debug).with("No Modulefile or metadata.json found at #{directory}, moving up")
1020
+ expect( subject.logger ).to receive(:error).with("At root, can't parse for another directory")
900
1021
  expect(subject.parse_for_moduleroot(directory)).to eq(nil)
901
1022
  end
902
1023
  end