beaker-answers 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,49 @@
1
+ require 'beaker-answers/versions/version30'
2
+ module BeakerAnswers
3
+ # This class provides answer file information for PE version 3.2
4
+ #
5
+ # @api private
6
+ class Version32 < Version30
7
+
8
+ # The version of PE that this set of answers is appropriate for
9
+ def self.pe_version_matcher
10
+ /\A3\.(2|3)/
11
+ end
12
+
13
+ # Return answer data for all hosts.
14
+ #
15
+ # @return [Hash] A hash (keyed from hosts) containing hashes of answer file
16
+ # data.
17
+ def generate_answers
18
+ masterless = @options[:masterless]
19
+ return super if masterless
20
+
21
+ dashboard = only_host_with_role(@hosts, 'dashboard')
22
+ database = only_host_with_role(@hosts, 'database')
23
+ master = only_host_with_role(@hosts, 'master')
24
+
25
+ the_answers = super
26
+ if dashboard != master
27
+ # in 3.2, dashboard needs the master certname
28
+ the_answers[dashboard.name][:q_puppetmaster_certname] = master.to_s
29
+ end
30
+
31
+ # do we want to check for updates?
32
+ pe_check_for_updates = answer_for(@options, :q_pe_check_for_updates, 'n')
33
+ the_answers[dashboard.name][:q_pe_check_for_updates] = pe_check_for_updates
34
+ the_answers[master.name][:q_pe_check_for_updates] = pe_check_for_updates
35
+
36
+ if @options[:type] == :upgrade && dashboard != database
37
+ # In a split configuration, there is no way for the upgrader
38
+ # to know how much disk space is available for the database
39
+ # migration. We tell it to continue on, because we're
40
+ # awesome.
41
+ the_answers[dashboard.name][:q_upgrade_with_unknown_disk_space] = 'y'
42
+ end
43
+ @hosts.each do |h|
44
+ h[:answers] = the_answers[h.name]
45
+ end
46
+ return the_answers
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,56 @@
1
+ require 'beaker-answers/versions/version32'
2
+ module BeakerAnswers
3
+ # This class provides answer file information for PE version 3.4
4
+ #
5
+ # @api private
6
+ class Version34 < Version32
7
+
8
+ # The version of PE that this set of answers is appropriate for
9
+ def self.pe_version_matcher
10
+ /\A3\.(4|7)/
11
+ end
12
+
13
+ def generate_answers
14
+ masterless = @options[:masterless]
15
+ return super if masterless
16
+
17
+ dashboard = only_host_with_role(@hosts, 'dashboard')
18
+ database = only_host_with_role(@hosts, 'database')
19
+
20
+ the_answers = super
21
+
22
+ classifier_database_user = answer_for(@options, :q_classifier_database_user, 'DFGhjlkj')
23
+ classifier_database_name = answer_for(@options, :q_database_name, 'pe-classifier')
24
+ classifier_database_password = "'#{answer_for(@options, :q_classifier_database_password)}'"
25
+ activity_database_user = answer_for(@options, :q_activity_database_user, 'adsfglkj')
26
+ activity_database_name = answer_for(@options, :q_activity_database_name, 'pe-activity')
27
+ activity_database_password = "'#{answer_for(@options, :q_activity_database_password)}'"
28
+ rbac_database_user = answer_for(@options, :q_rbac_database_user, 'RbhNBklm')
29
+ rbac_database_name = answer_for(@options, :q_rbac_database_name, 'pe-rbac')
30
+ rbac_database_password = "'#{answer_for(@options, :q_rbac_database_password)}'"
31
+
32
+ console_services_hash = {
33
+ :q_classifier_database_user => classifier_database_user,
34
+ :q_classifier_database_name => classifier_database_name,
35
+ :q_classifier_database_password => classifier_database_password,
36
+ :q_activity_database_user => activity_database_user,
37
+ :q_activity_database_name => activity_database_name,
38
+ :q_activity_database_password => activity_database_password,
39
+ :q_rbac_database_user => rbac_database_user,
40
+ :q_rbac_database_name => rbac_database_name,
41
+ :q_rbac_database_password => rbac_database_password,
42
+ }
43
+
44
+ # If we're installing or upgrading from a non-RBAC version, set the 'admin' password
45
+ if @options[:type] == :upgrade && @options[:set_console_password]
46
+ dashboard_password = "'#{answer_for(@options, :q_puppet_enterpriseconsole_auth_password)}'"
47
+ the_answers[dashboard.name][:q_puppet_enterpriseconsole_auth_password] = dashboard_password
48
+ end
49
+
50
+ the_answers[dashboard.name].merge!(console_services_hash)
51
+ the_answers[database.name].merge!(console_services_hash)
52
+
53
+ return the_answers
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,34 @@
1
+ require 'beaker-answers/versions/version34'
2
+ module BeakerAnswers
3
+ # This class provides answer file information for PE version 4.0
4
+ #
5
+ # @api private
6
+ class Version38 < Version34
7
+
8
+ # The version of PE that this set of answers is appropriate for
9
+ def self.pe_version_matcher
10
+ /\A3\.8/
11
+ end
12
+
13
+ def generate_answers
14
+ masterless = @options[:masterless]
15
+ return super if masterless
16
+
17
+ the_answers = super
18
+
19
+ # add new answers
20
+ exit_for_nc_migrate = answer_for(@options, :q_exit_for_nc_migrate, 'n')
21
+ enable_future_parser = answer_for(@options, :q_enable_future_parser, 'n')
22
+
23
+ the_answers.map do |key, value|
24
+ # there may not be answers in the case of a windows host
25
+ if the_answers[key]
26
+ the_answers[key][:q_exit_for_nc_migrate] = exit_for_nc_migrate
27
+ the_answers[key][:q_enable_future_parser] = enable_future_parser
28
+ end
29
+ end
30
+
31
+ return the_answers
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,49 @@
1
+ require 'beaker-answers/versions/version38'
2
+ module BeakerAnswers
3
+ # This class provides answer file information for PE version 4.0
4
+ #
5
+ # @api private
6
+ class Version40 < Version38
7
+
8
+ # The version of PE that this set of answers is appropriate for
9
+ def self.pe_version_matcher
10
+ /(\A3\.99)|(\A4\.0)|(\A2015)/
11
+ end
12
+
13
+ def generate_answers
14
+ masterless = @options[:masterless]
15
+ return super if masterless
16
+
17
+ master = only_host_with_role(@hosts, 'master')
18
+
19
+ the_answers = super
20
+
21
+ # remove some old answers
22
+ # - q_puppet_cloud_install
23
+ # - q_puppet_enterpriseconsole_database_name
24
+ # - q_puppet_enterpriseconsole_database_password
25
+ # - q_puppet_enterpriseconsole_database_user
26
+
27
+ the_answers.map do |vm, as|
28
+ if as
29
+ as.delete_if do |key, value|
30
+ key =~ /q_puppet_cloud_install/
31
+ #to be deleted in the future
32
+ #|q_puppet_enterpriseconsole_database_name|q_puppet_enterpriseconsole_database_password|q_puppet_enterpriseconsole_database_user/
33
+ end
34
+ end
35
+ end
36
+
37
+ # add some new answers
38
+ update_server_host = answer_for(@options, :q_update_server_host, master.to_s)
39
+ install_update_server = answer_for(@options, :q_install_update_server, 'y')
40
+
41
+ the_answers.map do |key, value|
42
+ the_answers[key][:q_update_server_host] = update_server_host if the_answers[key]
43
+ end
44
+ the_answers[master.name][:q_install_update_server] = install_update_server
45
+
46
+ return the_answers
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,532 @@
1
+ require 'spec_helper'
2
+
3
+ describe BeakerAnswers do
4
+ let( :basic_hosts ) { make_hosts( { 'pe_ver' => @ver } ) }
5
+ let( :options ) { @options || StringifyHash.new }
6
+ let( :hosts ) { basic_hosts[0]['roles'] = ['master', 'database', 'dashboard']
7
+ basic_hosts[1]['platform'] = 'windows'
8
+ basic_hosts }
9
+ let( :answers ) { BeakerAnswers::Answers.create(@ver, hosts, options) }
10
+
11
+ after :each do
12
+ ENV.delete('q_puppet_cloud_install')
13
+ end
14
+
15
+ it 'uses options[:answers] if they are set (override q_puppet_cloud_install for 3.8' do
16
+ @ver = '3.8'
17
+ options[:answers] = StringifyHash.new
18
+ options[:answers]['q_puppet_cloud_install'] = 'n'
19
+ opts = answers.instance_variable_get(:@options)
20
+ @answers = answers.answers
21
+ # confirm that the answers were correctly added to the answers object
22
+ expect(opts).to be_a_kind_of StringifyHash
23
+ expect(opts[:answers]['q_puppet_cloud_install']).to be == 'n'
24
+ expect(opts[:answers][:q_puppet_cloud_install]).to be == 'n'
25
+ hosts.each do |host|
26
+ if @answers[host.name]
27
+ expect( @answers[host.name][:q_puppet_cloud_install] ).to be == 'n'
28
+ end
29
+ end
30
+ end
31
+
32
+ it 'generates 4.0 answers for 2015 hosts' do
33
+ @ver = '2015.1.2'
34
+ expect( answers ).to be_a_kind_of BeakerAnswers::Version40
35
+ end
36
+
37
+ it 'generates 4.0 answers for 4.0 hosts' do
38
+ @ver = '4.0'
39
+ expect( answers ).to be_a_kind_of BeakerAnswers::Version40
40
+ end
41
+
42
+ it 'generates 4.0 answers for 3.99 hosts' do
43
+ @ver = '3.99'
44
+ expect( answers ).to be_a_kind_of BeakerAnswers::Version40
45
+ end
46
+
47
+ it 'generates 3.8 answers for 3.8 hosts' do
48
+ @ver = '3.8'
49
+ expect( answers ).to be_a_kind_of BeakerAnswers::Version38
50
+ end
51
+
52
+ it 'generates 3.4 answers for 3.4 hosts' do
53
+ @ver = '3.4'
54
+ expect( answers ).to be_a_kind_of BeakerAnswers::Version34
55
+ end
56
+
57
+ it 'generates 3.2 answers for 3.3 hosts' do
58
+ @ver = '3.3'
59
+ expect( answers ).to be_a_kind_of BeakerAnswers::Version32
60
+ end
61
+
62
+ it 'generates 3.2 answers for 3.2 hosts' do
63
+ @ver = '3.2'
64
+ expect( answers ).to be_a_kind_of BeakerAnswers::Version32
65
+ end
66
+
67
+ it 'generates 3.0 answers for 3.1 hosts' do
68
+ @ver = '3.1'
69
+ expect( answers ).to be_a_kind_of BeakerAnswers::Version30
70
+ end
71
+
72
+ it 'generates 3.0 answers for 3.0 hosts' do
73
+ @ver = '3.0'
74
+ expect( answers ).to be_a_kind_of BeakerAnswers::Version30
75
+ end
76
+
77
+ it 'generates 2.8 answers for 2.8 hosts' do
78
+ @ver = '2.8'
79
+ expect( answers ).to be_a_kind_of BeakerAnswers::Version28
80
+ end
81
+
82
+ it 'generates 2.0 answers for 2.0 hosts' do
83
+ @ver = '2.0'
84
+ expect( answers ).to be_a_kind_of BeakerAnswers::Version20
85
+ end
86
+
87
+ it 'raises an error for an unknown version' do
88
+ @ver = 'x.x'
89
+ expect{ answers }.to raise_error( NotImplementedError )
90
+ end
91
+ end
92
+
93
+ describe "Masterless Setup" do
94
+ let( :ver ) { @ver || '3.0' }
95
+ let( :options ) { options = StringifyHash.new
96
+ options[:masterless] = true
97
+ options }
98
+ let( :hosts ) { make_hosts({}, 1) }
99
+ let( :host ) { hosts[0] }
100
+ let( :answers ) { BeakerAnswers::Answers.create(ver, hosts, options) }
101
+ let( :host_answers ) { answers.answers[host.name] }
102
+
103
+
104
+ it 'adds the correct answers' do
105
+ expect( host_answers[:q_puppetagent_server] ).to be === host_answers[:q_puppetagent_certname]
106
+ expect( host_answers[:q_continue_or_reenter_master_hostname]).to be === 'c'
107
+ end
108
+
109
+ it 'skips the correct answers' do
110
+ expect( host_answers[:q_puppetmaster_install]).to be === 'n'
111
+ expect( host_answers[:q_puppet_enterpriseconsole_install] ).to be === 'n'
112
+ expect( host_answers[:q_puppetdb_install] ).to be === 'n'
113
+ end
114
+
115
+ it '3.0: never calls #only_host_with_role in #generate_answers' do
116
+ expect( answers.generate_answers ).to_not receive( :only_host_with_role )
117
+ end
118
+
119
+ it '3.2: never calls #only_host_with_role in #generate_answers' do
120
+ @ver = '3.2'
121
+ expect( answers.generate_answers ).to_not receive( :only_host_with_role )
122
+ end
123
+
124
+ it '3.4: never calls #only_host_with_role in #generate_answers' do
125
+ @ver = '3.4'
126
+ expect( answers.generate_answers ).to_not receive( :only_host_with_role )
127
+ end
128
+
129
+ end
130
+
131
+ describe BeakerAnswers::Version34 do
132
+ let( :options ) { StringifyHash.new }
133
+ let( :basic_hosts ) { make_hosts( {'pe_ver' => @ver } ) }
134
+ let( :hosts ) { basic_hosts[0]['roles'] = ['master', 'agent']
135
+ basic_hosts[0][:custom_answers] = { :q_custom => 'LOOKYHERE' }
136
+ basic_hosts[1]['roles'] = ['dashboard', 'agent']
137
+ basic_hosts[2]['roles'] = ['database', 'agent']
138
+ basic_hosts }
139
+ let( :answers ) { BeakerAnswers::Answers.create(@ver, hosts, options) }
140
+
141
+ before :each do
142
+ @ver = '3.4'
143
+ @answers = answers.answers
144
+ end
145
+
146
+ it 'should add console services answers to dashboard answers' do
147
+ @ver = '3.4'
148
+ answers = @answers
149
+ expect( @answers['vm2'] ).to include :q_classifier_database_user => 'DFGhjlkj'
150
+ expect( @answers['vm2'] ).to include :q_classifier_database_name => 'pe-classifier'
151
+ expect( @answers['vm2'] ).to include :q_classifier_database_password => "'~!@\#$%^*-/ aZ'"
152
+ expect( @answers['vm2'] ).to include :q_activity_database_user => 'adsfglkj'
153
+ expect( @answers['vm2'] ).to include :q_activity_database_name => 'pe-activity'
154
+ expect( @answers['vm2'] ).to include :q_activity_database_password => "'~!@\#$%^*-/ aZ'"
155
+ expect( @answers['vm2'] ).to include :q_rbac_database_user => 'RbhNBklm'
156
+ expect( @answers['vm2'] ).to include :q_rbac_database_name => 'pe-rbac'
157
+ expect( @answers['vm2'] ).to include :q_rbac_database_password => "'~!@\#$%^*-/ aZ'"
158
+ end
159
+
160
+ it 'should add console services answers to database answers' do
161
+ @ver = '3.4'
162
+ answers = @answers
163
+ expect( @answers['vm3'] ).to include :q_classifier_database_user => 'DFGhjlkj'
164
+ expect( @answers['vm3'] ).to include :q_classifier_database_name => 'pe-classifier'
165
+ expect( @answers['vm3'] ).to include :q_classifier_database_password => "'~!@\#$%^*-/ aZ'"
166
+ expect( @answers['vm3'] ).to include :q_activity_database_user => 'adsfglkj'
167
+ expect( @answers['vm3'] ).to include :q_activity_database_name => 'pe-activity'
168
+ expect( @answers['vm3'] ).to include :q_activity_database_password => "'~!@\#$%^*-/ aZ'"
169
+ expect( @answers['vm3'] ).to include :q_rbac_database_user => 'RbhNBklm'
170
+ expect( @answers['vm3'] ).to include :q_rbac_database_name => 'pe-rbac'
171
+ expect( @answers['vm3'] ).to include :q_rbac_database_password => "'~!@\#$%^*-/ aZ'"
172
+ end
173
+
174
+ it 'should add answers to the host objects' do
175
+ @ver = '3.4'
176
+ answers = @answers
177
+ hosts.each do |host|
178
+ puts "checking #{host.name}"
179
+ expect( host[:answers] ).to be === answers[host.name]
180
+ end
181
+ end
182
+
183
+ it 'should add answers to the host objects' do
184
+ hosts.each do |host|
185
+ expect( host[:answers] ).to be === @answers[host.name]
186
+ end
187
+ end
188
+
189
+ it 'appends custom answers to generated answers' do
190
+ expect( hosts[0][:custom_answers] ).to be == { :q_custom => 'LOOKYHERE' }
191
+ expect( @answers['vm1'] ).to include :q_custom
192
+ expect( hosts[0][:answers] ).to include :q_custom
193
+ end
194
+
195
+ end
196
+
197
+ describe BeakerAnswers::Version38 do
198
+ let( :options ) { StringifyHash.new }
199
+ let( :basic_hosts ) { make_hosts( {'pe_ver' => @ver } ) }
200
+ let( :hosts ) { basic_hosts[0]['roles'] = ['master', 'agent']
201
+ basic_hosts[1]['roles'] = ['dashboard', 'database', 'agent']
202
+ basic_hosts[2]['roles'] = ['agent']
203
+ basic_hosts[2]['platform'] = 'windows2008r2'
204
+ basic_hosts }
205
+ let( :answers ) { BeakerAnswers::Answers.create(@ver, hosts, options) }
206
+ let( :upgrade_answers ) { BeakerAnswers::Answers.create(@ver, hosts, options.merge( {:type => :upgrade}) ) }
207
+
208
+ before :each do
209
+ @ver = '3.8'
210
+ @answers = answers.answers
211
+ end
212
+
213
+ it 'should add q_pe_check_for_updates to master' do
214
+ expect( @answers['vm1'][:q_pe_check_for_updates] ).to be === 'n'
215
+ end
216
+
217
+ it 'should add q_pe_check_for_updates to dashboard' do
218
+ expect( @answers['vm2'][:q_pe_check_for_updates] ).to be === 'n'
219
+ end
220
+
221
+ it 'adds :q_enable_future_parser to all hosts, default to "n"' do
222
+ hosts.each do |host|
223
+ expect( basic_hosts[0][:answers][:q_enable_future_parser] ).to be == 'n'
224
+ expect( basic_hosts[1][:answers][:q_enable_future_parser] ).to be == 'n'
225
+ end
226
+ end
227
+
228
+ it 'adds :q_exit_for_nc_migrate to all hosts, default to "n"' do
229
+ expect( basic_hosts[0][:answers][:q_exit_for_nc_migrate] ).to be == 'n'
230
+ expect( basic_hosts[1][:answers][:q_exit_for_nc_migrate] ).to be == 'n'
231
+ end
232
+
233
+ it 'should add answers to the host objects' do
234
+ answers = @answers
235
+ hosts.each do |host|
236
+ expect( host[:answers] ).to be === @answers[host.name]
237
+ end
238
+ end
239
+ end
240
+
241
+ describe BeakerAnswers::Version40 do
242
+ let( :options ) { StringifyHash.new }
243
+ let( :basic_hosts ) { make_hosts( {'pe_ver' => @ver } ) }
244
+ let( :hosts ) { basic_hosts[0]['roles'] = ['master', 'agent']
245
+ basic_hosts[1]['roles'] = ['dashboard', 'agent']
246
+ basic_hosts[2]['roles'] = ['database', 'agent']
247
+ basic_hosts }
248
+ let( :answers ) { BeakerAnswers::Answers.create(@ver, hosts, options) }
249
+ let( :upgrade_answers ) { BeakerAnswers::Answers.create(@ver, hosts, options.merge( {:type => :upgrade}) ) }
250
+
251
+ before :each do
252
+ @ver = '3.99'
253
+ @answers = answers.answers
254
+ end
255
+
256
+ it 'should not have q_puppet_cloud_install key' do
257
+ hosts.each do |host|
258
+ expect( host[:answers] ).to_not include :q_puppet_cloud_install
259
+ end
260
+ end
261
+
262
+ it 'should add q_pe_check_for_updates to master' do
263
+ expect( @answers['vm1'][:q_pe_check_for_updates] ).to be === 'n'
264
+ end
265
+
266
+ it 'should add q_pe_check_for_updates to dashboard' do
267
+ expect( @answers['vm2'][:q_pe_check_for_updates] ).to be === 'n'
268
+ end
269
+
270
+ it 'should not add q_pe_check_for_updates to agent/database' do
271
+ expect( @answers['vm3']).to_not include :q_pe_check_for_updates
272
+ end
273
+
274
+ # re-enable these tests once these keys are eliminated
275
+ #
276
+ # it 'should not have q_puppet_enterpriseconsole_database_name key' do
277
+ # hosts.each do |host|
278
+ # expect( host[:answers] ).to_not include :q_puppet_enterpriseconsole_database_name
279
+ # end
280
+ # end
281
+ #
282
+ # it 'should not have q_puppet_enterpriseconsole_database_password key' do
283
+ # hosts.each do |host|
284
+ # expect( host[:answers] ).to_not include :q_puppet_enterpriseconsole_database_password
285
+ # end
286
+ # end
287
+ #
288
+ # it 'should not have q_puppet_enterpriseconsole_database_user key' do
289
+ # hosts.each do |host|
290
+ # expect( host[:answers] ).to_not include :q_puppet_enterpriseconsole_database_user
291
+ # end
292
+ # end
293
+
294
+ it ':q_update_server_host should default to the master' do
295
+ hosts.each do |host|
296
+ expect( host[:answers][:q_update_server_host] ).to be == hosts[0].to_s
297
+ end
298
+ end
299
+
300
+ it 'only the master should have :q_install_update_server' do
301
+ hosts.each do |host|
302
+ if host[:roles].include? 'master'
303
+ expect( host[:answers][:q_install_update_server] ).to be == 'y'
304
+ else
305
+ expect( host[:answers] ).to_not include :q_install_update_server
306
+ end
307
+ end
308
+ end
309
+
310
+ it 'should add answers to the host objects' do
311
+ hosts.each do |host|
312
+ expect( host[:answers] ).to be === @answers[host.name]
313
+ end
314
+ end
315
+ end
316
+
317
+ describe BeakerAnswers::Version32 do
318
+ let( :options ) { StringifyHash.new }
319
+ let( :basic_hosts ) { make_hosts( {'pe_ver' => @ver } ) }
320
+ let( :hosts ) { basic_hosts[0]['roles'] = ['master', 'agent']
321
+ basic_hosts[1]['roles'] = ['dashboard', 'agent']
322
+ basic_hosts[2]['roles'] = ['database', 'agent']
323
+ basic_hosts }
324
+ let( :answers ) { BeakerAnswers::Answers.create(@ver, hosts, options) }
325
+ let( :upgrade_answers ) { BeakerAnswers::Answers.create(@ver, hosts, options.merge( {:type => :upgrade}) ) }
326
+
327
+ before :each do
328
+ @ver = '3.2'
329
+ @answers = answers.answers
330
+ end
331
+
332
+ it 'should add q_pe_check_for_updates to master' do
333
+ expect( @answers['vm1'][:q_pe_check_for_updates] ).to be === 'n'
334
+ end
335
+
336
+ it 'should add q_pe_check_for_updates to dashboard' do
337
+ expect( @answers['vm2'][:q_pe_check_for_updates] ).to be === 'n'
338
+ end
339
+
340
+ it 'should not add q_pe_check_for_updates to agent/database' do
341
+ expect( @answers['vm3']).to_not include :q_pe_check_for_updates
342
+ end
343
+
344
+ # The only difference between 3.2 and 3.0 is the addition of the
345
+ # master certname to the dashboard answers
346
+ it 'should add q_puppetmaster_certname to the dashboard answers' do
347
+ expect( @answers['vm2']).to include :q_puppetmaster_certname
348
+ end
349
+
350
+ it 'should add q_upgrade_with_unknown_disk_space to the dashboard on upgrade' do
351
+ @upgrade_answers = upgrade_answers.answers
352
+ expect( @upgrade_answers['vm2']).to include :q_upgrade_with_unknown_disk_space
353
+ end
354
+
355
+ it 'should add answers to the host objects' do
356
+ hosts.each do |host|
357
+ expect( host[:answers] ).to be === @answers[host.name]
358
+ end
359
+ end
360
+ end
361
+
362
+ describe BeakerAnswers::Version30 do
363
+ let( :options ) { StringifyHash.new }
364
+ let( :basic_hosts ) { make_hosts( { 'pe_ver' => @ver } ) }
365
+ let( :hosts ) { basic_hosts[0]['roles'] = ['master', 'database', 'dashboard']
366
+ basic_hosts[1]['platform'] = 'windows'
367
+ basic_hosts[2][:custom_answers] = { :q_custom => 'LOOKLOOKLOOK' }
368
+ basic_hosts }
369
+ let( :answers ) { BeakerAnswers::Answers.create(@ver, hosts, options) }
370
+ let( :upgrade_answers ) { BeakerAnswers::Answers.create(@ver, hosts, options.merge( {:type => :upgrade}) ) }
371
+
372
+ before :each do
373
+ @ver = '3.0'
374
+ @answers = answers.answers
375
+ end
376
+
377
+ it 'uses simple answers for upgrade from 3.0.x to 3.0.x' do
378
+ @upgrade_answers = upgrade_answers.answers
379
+ expect( @upgrade_answers ).to be === { "vm2"=>{ :q_install=>"y", :q_install_vendor_packages=>"y" }, "vm1"=>{ :q_install=>"y", :q_install_vendor_packages=>"y" }, "vm3"=>{ :q_install=>"y", :q_install_vendor_packages=>"y", :q_custom=>"LOOKLOOKLOOK" } }
380
+ end
381
+
382
+ it 'sets correct answers for an agent' do
383
+ @ver = '3.0'
384
+ expect( @answers['vm3'] ).to be === { :q_install=>"y", :q_vendor_packages_install=>"y", :q_puppetagent_install=>"y", :q_puppet_cloud_install=>"y", :q_verify_packages=>"y", :q_puppet_symlinks_install=>"y", :q_puppetagent_certname=>hosts[2].to_s, :q_puppetagent_server=>hosts[0].to_s, :q_puppetmaster_install=>"n", :q_all_in_one_install=>"n", :q_puppet_enterpriseconsole_install=>"n", :q_puppetdb_install=>"n", :q_database_install=>"n", :q_custom=>"LOOKLOOKLOOK" }
385
+ end
386
+
387
+ it 'sets correct answers for a master' do
388
+ @ver = '3.0'
389
+ expect( @answers['vm1'] ).to be === { :q_install=>"y", :q_vendor_packages_install=>"y", :q_puppetagent_install=>"y", :q_puppet_cloud_install=>"y", :q_verify_packages=>"y", :q_puppet_symlinks_install=>"y", :q_puppetagent_certname=>hosts[0].to_s, :q_puppetagent_server=>hosts[0].to_s, :q_puppetmaster_install=>"y", :q_all_in_one_install=>"y", :q_puppet_enterpriseconsole_install=>"y", :q_puppetdb_install=>"y", :q_database_install=>"y", :q_puppetdb_hostname=>hosts[0].to_s, :q_puppetdb_port=>8081, :q_puppetmaster_dnsaltnames=>"#{hosts[0].to_s},#{hosts[0][:ip]},puppet", :q_puppetmaster_enterpriseconsole_hostname=>hosts[0].to_s, :q_puppetmaster_enterpriseconsole_port=>443, :q_puppetmaster_certname=>hosts[0].to_s, :q_puppetdb_database_name=>"pe-puppetdb", :q_puppetdb_database_user=>"mYpdBu3r", :q_puppetdb_database_password=>"'~!@\#$%^*-/ aZ'", :q_puppet_enterpriseconsole_auth_database_name=>"console_auth", :q_puppet_enterpriseconsole_auth_database_user=>"mYu7hu3r", :q_puppet_enterpriseconsole_auth_database_password=>"'~!@\#$%^*-/ aZ'", :q_puppet_enterpriseconsole_database_name=>"console", :q_puppet_enterpriseconsole_database_user=>"mYc0nS03u3r", :q_puppet_enterpriseconsole_database_password=>"'~!@\#$%^*-/ aZ'", :q_database_host=>hosts[0].to_s, :q_database_port=>5432, :q_pe_database=>"y", :q_puppet_enterpriseconsole_inventory_hostname=>hosts[0].to_s, :q_puppet_enterpriseconsole_inventory_certname=>hosts[0].to_s, :q_puppet_enterpriseconsole_inventory_dnsaltnames=>hosts[0].to_s, :q_puppet_enterpriseconsole_inventory_port=>8140, :q_puppet_enterpriseconsole_master_hostname=>hosts[0].to_s, :q_puppet_enterpriseconsole_auth_user_email=>"'admin@example.com'", :q_puppet_enterpriseconsole_auth_password=>"'~!@\#$%^*-/ aZ'", :q_puppet_enterpriseconsole_httpd_port=>443, :q_puppet_enterpriseconsole_smtp_host=>"'vm1'", :q_puppet_enterpriseconsole_smtp_use_tls=>"'n'", :q_puppet_enterpriseconsole_smtp_port=>"'25'", :q_database_root_password=>"'=ZYdjiP3jCwV5eo9s1MBd'", :q_database_root_user=>"pe-postgres" }
390
+ end
391
+
392
+ it 'generates nil answers for a windows host' do
393
+ @ver = '3.0'
394
+ expect( @answers['vm2'] ).to be === nil
395
+ end
396
+
397
+ it 'should add answers to the host objects' do
398
+ @ver = '3.0'
399
+ a = answers.answers
400
+ hosts.each do |host|
401
+ expect( host[:answers] ).to be === @answers[host.name]
402
+ end
403
+ end
404
+
405
+ it 'appends custom answers to generated answers' do
406
+ expect( hosts[2][:custom_answers] ).to be == { :q_custom => 'LOOKLOOKLOOK' }
407
+ expect( @answers['vm3'] ).to include :q_custom
408
+ expect( hosts[2][:answers] ).to include :q_custom
409
+ end
410
+ end
411
+
412
+ describe BeakerAnswers::Version28 do
413
+ let( :options ) { StringifyHash.new }
414
+ let( :basic_hosts ) { make_hosts( { 'pe_ver' => @ver } ) }
415
+ let( :hosts ) { basic_hosts[0]['roles'] = ['master', 'database', 'dashboard']
416
+ basic_hosts[1]['platform'] = 'windows'
417
+ basic_hosts }
418
+ let( :answers ) { BeakerAnswers::Answers.create(@ver, hosts, options) }
419
+
420
+ before :each do
421
+ @ver = '2.8'
422
+ @answers = answers.answers
423
+ end
424
+
425
+ it 'sets correct answers for an agent' do
426
+ expect( @answers['vm3'] ).to be === { :q_install=>"y", :q_puppetagent_install=>"y", :q_puppet_cloud_install=>"y", :q_puppet_symlinks_install=>"y", :q_vendor_packages_install=>"y", :q_puppetagent_certname=>hosts[2].to_s, :q_puppetagent_server=>hosts[0].to_s, :q_puppetmaster_install=>"n", :q_puppet_enterpriseconsole_install=>"n" }
427
+ end
428
+
429
+ it 'sets correct answers for a master' do
430
+ expect( @answers['vm1'] ).to be === { :q_install=>"y", :q_puppetagent_install=>"y", :q_puppet_cloud_install=>"y", :q_puppet_symlinks_install=>"y", :q_vendor_packages_install=>"y", :q_puppetagent_certname=>hosts[0].to_s, :q_puppetagent_server=>hosts[0].to_s, :q_puppetmaster_install=>"y", :q_puppet_enterpriseconsole_install=>"y", :q_puppetmaster_certname=>hosts[0].to_s, :q_puppetmaster_dnsaltnames=>"#{hosts[0].to_s},#{hosts[0][:ip]},puppet", :q_puppetmaster_enterpriseconsole_hostname=>hosts[0].to_s, :q_puppetmaster_enterpriseconsole_port=>443, :q_puppetmaster_forward_facts=>"y", :q_puppet_enterpriseconsole_database_install=>"y", :q_puppet_enterpriseconsole_auth_database_name=>"console_auth", :q_puppet_enterpriseconsole_auth_database_user=>"mYu7hu3r", :q_puppet_enterpriseconsole_auth_database_password=>"'~!@\#$%^*-/ aZ'", :q_puppet_enterpriseconsole_database_name=>"console", :q_puppet_enterpriseconsole_database_user=>"mYc0nS03u3r", :q_puppet_enterpriseconsole_database_password=>"'~!@\#$%^*-/ aZ'", :q_puppet_enterpriseconsole_inventory_hostname=>hosts[0].to_s, :q_puppet_enterpriseconsole_inventory_certname=>hosts[0].to_s, :q_puppet_enterpriseconsole_inventory_dnsaltnames=>hosts[0].to_s, :q_puppet_enterpriseconsole_inventory_port=>8140, :q_puppet_enterpriseconsole_master_hostname=>hosts[0].to_s, :q_puppet_enterpriseconsole_auth_user_email=>"'admin@example.com'", :q_puppet_enterpriseconsole_auth_password=>"'~!@\#$%^*-/ aZ'", :q_puppet_enterpriseconsole_httpd_port=>443, :q_puppet_enterpriseconsole_smtp_host=>"'vm1'", :q_puppet_enterpriseconsole_smtp_use_tls=>"'n'", :q_puppet_enterpriseconsole_smtp_port=>"'25'", :q_puppet_enterpriseconsole_auth_user=>"'admin@example.com'" }
431
+ end
432
+
433
+ it 'generates nil answers for a windows host' do
434
+ expect( @answers['vm2'] ).to be === nil
435
+ end
436
+
437
+ it 'should add answers to the host objects' do
438
+ hosts.each do |host|
439
+ expect( host[:answers] ).to be === @answers[host.name]
440
+ end
441
+ end
442
+
443
+ end
444
+ describe BeakerAnswers::Version20 do
445
+ let( :options ) { StringifyHash.new }
446
+ let( :basic_hosts ) { make_hosts( { 'pe_ver' => @ver } ) }
447
+ let( :hosts ) { basic_hosts[0]['roles'] = ['master', 'database', 'dashboard']
448
+ basic_hosts[1]['platform'] = 'windows'
449
+ basic_hosts }
450
+
451
+ let( :answers ) { BeakerAnswers::Answers.create(@ver, hosts, options) }
452
+
453
+ before :each do
454
+ @ver = '2.0'
455
+ @answers = answers.answers
456
+ end
457
+
458
+ it 'sets correct answers for an agent' do
459
+ expect( @answers['vm3'] ).to be === { :q_install=>"y", :q_puppetagent_install=>"y", :q_puppet_cloud_install=>"y", :q_puppet_symlinks_install=>"y", :q_vendor_packages_install=>"y", :q_puppetagent_certname=>hosts[2].to_s, :q_puppetagent_server=>hosts[0].to_s, :q_puppetmaster_install=>"n", :q_puppet_enterpriseconsole_install=>"n" }
460
+ end
461
+
462
+ it 'sets correct answers for a master' do
463
+ expect( @answers['vm1'] ).to be === { :q_install=>"y", :q_puppetagent_install=>"y", :q_puppet_cloud_install=>"y", :q_puppet_symlinks_install=>"y", :q_vendor_packages_install=>"y", :q_puppetagent_certname=>hosts[0].to_s, :q_puppetagent_server=>hosts[0].to_s, :q_puppetmaster_install=>"y", :q_puppet_enterpriseconsole_install=>"y", :q_puppetmaster_certname=>hosts[0].to_s, :q_puppetmaster_dnsaltnames=>"#{hosts[0].to_s},#{hosts[0][:ip]},puppet", :q_puppetmaster_enterpriseconsole_hostname=>hosts[0].to_s, :q_puppetmaster_enterpriseconsole_port=>443, :q_puppetmaster_forward_facts=>"y", :q_puppet_enterpriseconsole_database_install=>"y", :q_puppet_enterpriseconsole_auth_database_name=>"console_auth", :q_puppet_enterpriseconsole_auth_database_user=>"mYu7hu3r", :q_puppet_enterpriseconsole_auth_database_password=>"'~!@\#$%^*-/ aZ'", :q_puppet_enterpriseconsole_database_name=>"console", :q_puppet_enterpriseconsole_database_user=>"mYc0nS03u3r", :q_puppet_enterpriseconsole_database_root_password=>"'~!@\#$%^*-/ aZ'", :q_puppet_enterpriseconsole_database_password=>"'~!@\#$%^*-/ aZ'", :q_puppet_enterpriseconsole_inventory_hostname=>hosts[0].to_s, :q_puppet_enterpriseconsole_inventory_certname=>hosts[0].to_s, :q_puppet_enterpriseconsole_inventory_dnsaltnames=>hosts[0].to_s, :q_puppet_enterpriseconsole_inventory_port=>8140, :q_puppet_enterpriseconsole_master_hostname=>hosts[0].to_s, :q_puppet_enterpriseconsole_auth_user_email=>"'admin@example.com'", :q_puppet_enterpriseconsole_auth_password=>"'~!@\#$%^*-/ aZ'", :q_puppet_enterpriseconsole_httpd_port=>443, :q_puppet_enterpriseconsole_smtp_host=>"'vm1'", :q_puppet_enterpriseconsole_smtp_use_tls=>"'n'", :q_puppet_enterpriseconsole_smtp_port=>"'25'", :q_puppet_enterpriseconsole_auth_user=>"'admin@example.com'" }
464
+ end
465
+
466
+ it 'generates nil answers for a windows host' do
467
+ expect( @answers['vm2'] ).to be === nil
468
+ end
469
+
470
+ it 'should add answers to the host objects' do
471
+ hosts.each do |host|
472
+ expect( host[:answers] ).to be === @answers[host.name]
473
+ end
474
+ end
475
+ end
476
+
477
+ describe 'Customization' do
478
+ let( :basic_hosts ) { make_hosts( { 'pe_ver' => @ver } ) }
479
+ let( :options ) { StringifyHash.new }
480
+ let( :hosts ) { basic_hosts[0]['roles'] = ['master', 'database', 'dashboard']
481
+ basic_hosts[1]['platform'] = 'windows'
482
+ basic_hosts }
483
+ let( :answers ) { BeakerAnswers::Answers.create(@ver, hosts, options) }
484
+
485
+ def test_answer_customization(answer_key, value_to_set)
486
+ @ver = '3.0'
487
+ options[:answers] ||= StringifyHash.new
488
+ options[:answers][answer_key] = value_to_set
489
+ host_answers = answers.answers['vm1']
490
+ expect( host_answers[answer_key] ).to be === value_to_set
491
+ end
492
+
493
+ it 'sets :q_puppetdb_hostname' do
494
+ test_answer_customization(:q_puppetdb_hostname, 'q_puppetdb_hostname_custom01')
495
+ end
496
+
497
+ it 'sets :q_puppetdb_database_user' do
498
+ test_answer_customization(:q_puppetdb_database_user, 'q_puppetdb_database_user_custom02')
499
+ end
500
+
501
+ it 'sets :q_puppetdb_database_password' do
502
+ test_answer_customization(:q_puppetdb_database_password, 'q_puppetdb_database_password_custom03')
503
+ end
504
+
505
+ it 'sets :q_puppet_enterpriseconsole_auth_database_password' do
506
+ answer = 'q_puppet_enterpriseconsole_auth_database_password_custom04'
507
+ test_answer_customization(:q_puppet_enterpriseconsole_auth_database_password, answer)
508
+ end
509
+
510
+ it 'sets :q_puppet_enterpriseconsole_database_user' do
511
+ answer = 'q_puppet_enterpriseconsole_database_user_custom05'
512
+ test_answer_customization(:q_puppet_enterpriseconsole_database_user, answer)
513
+ end
514
+
515
+ it 'sets :q_puppet_enterpriseconsole_database_password' do
516
+ answer = 'q_puppet_enterpriseconsole_database_password_custom06'
517
+ test_answer_customization(:q_puppet_enterpriseconsole_database_password, answer)
518
+ end
519
+
520
+ it 'sets :q_database_host' do
521
+ test_answer_customization(:q_database_host, 'q_database_host_custom07')
522
+ end
523
+
524
+ it 'sets :q_database_install' do
525
+ test_answer_customization(:q_database_install, 'q_database_install_custom08')
526
+ end
527
+
528
+ it 'sets :q_pe_database' do
529
+ test_answer_customization(:q_pe_database, 'q_pe_database_custom08')
530
+ end
531
+
532
+ end