-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
531 lines (454 loc) · 14 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
#
# Author:: Adam Jacob (<[email protected]>)
# Author:: Daniel DeLeo (<[email protected]>)
# Copyright:: Copyright (c) 2008, 2010 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
gems = %w[chef chef-server-api chef-server-webui chef-solr chef-expander chef-server]
require 'rubygems'
desc "Build the chef gems"
task :gem do
gems.each do |dir|
Dir.chdir(dir) { sh "rake gem" }
end
end
desc "Install the chef gems"
task :install do
gems.each do |dir|
Dir.chdir(dir) { sh "rake install" }
end
end
desc "Uninstall the chef gems"
task :uninstall do
gems.reverse.each do |dir|
Dir.chdir(dir) { sh "rake uninstall" }
end
end
desc "Run the rspec tests"
task :spec do
Dir.chdir("chef") { sh "rake spec" }
end
task :default => :spec
def start_couchdb(type="normal")
@couchdb_server_pid = nil
cid = fork
if cid
@couchdb_server_pid = cid
else
exec("couchdb")
end
end
def start_rabbitmq(type="normal")
@rabbitmq_server_pid = nil
cid = fork
if cid
@rabbitmq_server_pid = cid
else
exec("rabbitmq-server")
end
end
def configure_rabbitmq(type="normal")
# hack. wait for rabbit to come up.
sleep 2
puts `rabbitmqctl add_vhost /chef`
# create 'chef' user, give it the password 'testing'
puts `rabbitmqctl add_user chef testing`
# the three regexes map to config, write, read permissions respectively
puts `rabbitmqctl set_permissions -p /chef chef ".*" ".*" ".*"`
puts `rabbitmqctl list_users`
puts `rabbitmqctl list_vhosts`
puts `rabbitmqctl list_permissions -p /chef`
end
def start_chef_solr(type="normal")
@chef_solr_pid = nil
cid = fork
if cid
@chef_solr_pid = cid
else
case type
when "normal"
exec("./chef-solr/bin/chef-solr -l debug")
when "features"
p = fork { exec("./chef-solr/bin/chef-solr-installer -p /tmp/chef_solr_for_features --force") }
Process.wait(p)
exec("./chef-solr/bin/chef-solr -c #{File.join(File.dirname(__FILE__), "features", "data", "config", "server.rb")} -l debug")
end
end
end
def start_chef_expander(type="normal")
@chef_solr_indexer = nil
@chef_solr_indexer_pid = fork do
case type
when "normal"
exec("./chef-expander/bin/chef-expander -n 1 -i 1 -l debug")
when "features"
exec("./chef-expander/bin/chef-expander -c #{File.join(File.dirname(__FILE__), "features", "data", "config", "server.rb")} -l debug -n 1 -i 1")
end
end
end
def start_chef_server(type="normal")
puts "Starting #{type} chef development server"
@chef_server_pid = nil
mcid = fork
if mcid # parent
@chef_server_pid = mcid
else # child
case type
when "normal"
puts "Starting chef server for development with './chef-server-api/bin/chef-server -a thin -l debug -N'"
exec("./chef-server-api/bin/chef-server -a thin -l debug -N")
when "features"
puts "Starting chef server for features with #{["./chef-server/bin/chef-server -a thin -C #{File.join(File.dirname(__FILE__), "features", "data", "config", "server.rb")} -l debug -N"].join(' ')}"
exec("./chef-server-api/bin/chef-server -a thin -C #{File.join(File.dirname(__FILE__), "features", "data", "config", "server.rb")} -l debug -N")
end
end
end
def start_chef_webui(type="normal")
puts "Starting #{type} chef development server webui"
@chef_webui_pid = nil
mcid = fork
if mcid # parent
@chef_webui_pid = mcid
else # child
case type
when "normal"
puts "Starting chef webui for development with './chef-server/bin/chef-server-webui -a thin -l debug -N'"
exec("./chef-server-webui/bin/chef-server-webui -a thin -l debug -N")
when "features"
puts "Starting chef server webui for features with #{["./chef-server/bin/chef-server-webui -a thin -C #{File.join(File.dirname(__FILE__), "features", "data", "config", "server.rb")} -l debug -N"].join(' ')}"
exec("./chef-server-webui/bin/chef-server-webui -a thin -C #{File.join(File.dirname(__FILE__), "features", "data", "config", "server.rb")} -l debug -N")
end
end
end
def start_dev_environment(type="normal")
start_couchdb(type)
start_rabbitmq(type)
sleep 2
configure_rabbitmq(type)
start_chef_solr(type)
start_chef_solr_indexer(type)
start_chef_server(type)
start_chef_webui(type)
puts "Running CouchDB at #{@couchdb_server_pid}"
puts "Running RabbitMQ at #{@rabbitmq_server_pid}"
puts "Running Chef Solr at #{@chef_solr_pid}"
puts "Running Chef Solr Indexer at #{@chef_solr_indexer_pid}"
puts "Running Chef at #{@chef_server_pid}"
puts "Running Chef Web UI at #{@chef_webui_pid}"
end
def stop_dev_environment
if @chef_webui_pid
puts "Stopping Chef Web UI"
Process.kill("KILL", @chef_webui_pid)
end
if @chef_server_pid
puts "Stopping Chef"
Process.kill("KILL", @chef_server_pid)
end
if @chef_solr_pid
puts "Stopping Chef Solr"
Process.kill("INT", @chef_solr_pid)
end
if @chef_solr_indexer_pid
puts "Stopping Chef Solr Indexer"
Process.kill("INT", @chef_solr_indexer_pid)
end
if @couchdb_server_pid
puts "Stopping CouchDB"
Process.kill("KILL", @couchdb_server_pid)
end
if @rabbitmq_server_pid
puts "Stopping RabbitMQ"
Process.kill("KILL", @rabbitmq_server_pid)
end
puts "Have a nice day!"
end
def wait_for_ctrlc
puts "Hit CTRL-C to destroy development environment"
trap("CHLD", "IGNORE")
trap("INT") do
stop_dev_environment
exit 1
end
while true
sleep 10
end
end
desc "Run a development instance of Chef"
task :dev do
start_dev_environment
wait_for_ctrlc
end
namespace :dev do
desc "Run a test instance of Chef suitable for cucumber tests"
task :features do
start_dev_environment("features")
wait_for_ctrlc
end
namespace :features do
namespace :start do
desc "Start CouchDB for testing"
task :couchdb do
start_couchdb("features")
wait_for_ctrlc
end
desc "Start RabbitMQ for testing"
task :rabbitmq do
start_rabbitmq("features")
configure_rabbitmq("features")
wait_for_ctrlc
end
desc "Start Chef Solr for testing"
task :chef_solr do
start_chef_solr("features")
wait_for_ctrlc
end
desc "Start Chef Solr Indexer for testing"
task :chef_expander do
start_chef_expander("features")
wait_for_ctrlc
end
desc "Start Chef Server for testing"
task :chef_server do
start_chef_server("features")
wait_for_ctrlc
end
desc "Start Chef Web UI for testing"
task :chef_webui do
start_chef_webui("features")
wait_for_ctrlc
end
end
end
namespace :start do
desc "Start CouchDB"
task :couchdb do
start_couchdb
wait_for_ctrlc
end
desc "Start RabbitMQ"
task :rabbitmq do
start_rabbitmq
configure_rabbitmq
wait_for_ctrlc
end
desc "Start Chef Solr"
task :chef_solr do
start_chef_solr
wait_for_ctrlc
end
desc "Start Chef Solr Indexer"
task :chef_solr_indexer do
start_chef_expander
wait_for_ctrlc
end
desc "Start Chef Server"
task :chef_server do
start_chef_server
wait_for_ctrlc
end
desc "Start Chef Web UI"
task :chef_webui do
start_chef_webui
wait_for_ctrlc
end
end
end
begin
require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:features) do |t|
t.profile = "default"
end
namespace :features do
desc "Run cucumber tests for the REST API"
Cucumber::Rake::Task.new(:api) do |t|
t.profile = "api"
end
namespace :api do
[ :nodes, :roles, :clients, :environments ].each do |api|
Cucumber::Rake::Task.new(api) do |apitask|
apitask.profile = "api_#{api.to_s}"
end
namespace api do
%w{create delete list show update}.each do |action|
Cucumber::Rake::Task.new("#{action}") do |t|
t.profile = "api_#{api.to_s}_#{action}"
end
end
end
end
namespace :environments do
Cucumber::Rake::Task.new("cookbooks") do |t|
t.profile = "api_environments_cookbook_list"
end
Cucumber::Rake::Task.new("nodes") do |t|
t.profile = "api_environments_node_list"
end
end
namespace :nodes do
Cucumber::Rake::Task.new("sync") do |t|
t.profile = "api_nodes_sync"
end
end
desc "Run cucumber tests for the cookbooks portion of the REST API"
Cucumber::Rake::Task.new(:cookbooks) do |t|
t.profile = "api_cookbooks"
end
namespace :cookbooks do
%w{list show upload download delete}.each do |action|
Cucumber::Rake::Task.new(action) do |t|
t.profile = "api_cookbooks_#{action}"
end
end
Cucumber::Rake::Task.new(:cookbook_tarballs) do |t|
t.profile = "api_cookbooks_tarballs"
end
end
namespace :data do
desc "Run cucumber tests for the data portion of the REST API"
Cucumber::Rake::Task.new(:data) do |t|
t.profile = "api_data"
end
desc "Run cucumber tests for deleting data via the REST API"
Cucumber::Rake::Task.new(:delete) do |t|
t.profile = "api_data_delete"
end
desc "Run cucumber tests for adding items via the REST API"
Cucumber::Rake::Task.new(:item) do |t|
t.profile = "api_data_item"
end
end
namespace :search do
desc "Run cucumber tests for searching via the REST API"
Cucumber::Rake::Task.new(:search) do |t|
t.profile = "api_search"
end
desc "Run cucumber tests for listing search endpoints via the REST API"
Cucumber::Rake::Task.new(:list) do |t|
t.profile = "api_search_list"
end
desc "Run cucumber tests for searching via the REST API"
Cucumber::Rake::Task.new(:show) do |t|
t.profile = "api_search_show"
end
desc "Run cucumber tests for searching via the REST API"
Cucumber::Rake::Task.new(:reindex) do |t|
t.profile = "api_search_reindex"
end
end
end
desc "Run cucumber tests for the chef client"
Cucumber::Rake::Task.new(:client) do |t|
t.profile = "client"
end
namespace :client do
Cucumber::Rake::Task.new(:roles) do |t|
t.profile = "client_roles"
end
Cucumber::Rake::Task.new(:run_interval) do |t|
t.profile = "client_run_interval"
end
Cucumber::Rake::Task.new(:cookbook_sync) do |t|
t.profile = "client_cookbook_sync"
end
end
desc "Run cucumber tests for the cookbooks"
Cucumber::Rake::Task.new(:cookbooks) do |t|
t.profile = "cookbooks"
end
namespace :cookbook do
desc "Run cucumber tests for the cookbook metadata"
Cucumber::Rake::Task.new(:metadata) do |t|
t.profile = "cookbook_metadata"
end
end
desc "Run cucumber tests for the recipe language"
Cucumber::Rake::Task.new(:language) do |t|
t.profile = "language"
end
Cucumber::Rake::Task.new(:attribute_settings) do |t|
t.profile = "attribute_settings"
end
desc "Run cucumber tests for searching in recipes"
Cucumber::Rake::Task.new(:search) do |t|
t.profile = "search"
end
Cucumber::Rake::Task.new(:language) do |t|
t.profile = "language"
end
namespace :language do
Cucumber::Rake::Task.new(:recipe_include) do |t|
t.profile = "recipe_inclusion"
end
Cucumber::Rake::Task.new(:attribute_include) do |t|
t.profile = "attribute_inclusion"
end
end
Cucumber::Rake::Task.new(:lwrp) do |t|
t.profile = "lwrp"
end
desc "Run cucumber tests for providers"
Cucumber::Rake::Task.new(:provider) do |t|
t.profile = "provider"
end
namespace :provider do
desc "Run cucumber tests for deploy resources"
Cucumber::Rake::Task.new(:deploy) do |t|
t.profile = "provider_deploy"
end
desc "Run cucumber tests for directory resources"
Cucumber::Rake::Task.new(:directory) do |t|
t.profile = "provider_directory"
end
desc "Run cucumber tests for execute resources"
Cucumber::Rake::Task.new(:execute) do |t|
t.profile = "provider_execute"
end
desc "Run cucumber tests for file resources"
Cucumber::Rake::Task.new(:file) do |t|
t.profile = "provider_file"
end
desc "Run cucumber tests for remote_file resources"
Cucumber::Rake::Task.new(:remote_file) do |t|
t.profile = "provider_remote_file"
end
desc "Run cucumber tests for template resources"
Cucumber::Rake::Task.new(:template) do |t|
t.profile = "provider_template"
end
Cucumber::Rake::Task.new(:remote_directory) do |t|
t.profile = "provider_remote_directory"
end
Cucumber::Rake::Task.new(:git) do |t|
t.profile = "provider_git"
end
namespace :package do
desc "Run cucumber tests for macports packages"
Cucumber::Rake::Task.new(:macports) do |t|
t.profile = "provider_package_macports"
end
Cucumber::Rake::Task.new(:gems) do |g|
g.profile = "provider_package_rubygems"
end
end
desc "Run cucumber tests for knife"
Cucumber::Rake::Task.new(:knife) do |t|
t.profile = "knife"
end
end
end
rescue LoadError
STDERR.puts "\n*** Cucumber is missing. (sudo) gem install cucumber to run integration tests. ***\n\n"
end