-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
174 lines (137 loc) · 4.23 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
require "rake"
require "rspec/core/rake_task"
require_relative "spec/lib/environments"
namespace :environment do
upTasks = []
downTasks = []
destroyTasks = []
provisionTasks = []
AnsibleHelper.each do |vm|
namespace vm.name.to_sym do
upTasks << :"#{vm.name}:up"
downTasks << :"#{vm.name}:down"
destroyTasks << :"#{vm.name}:destroy"
provisionTasks << :"#{vm.name}:provision"
desc "Boot #{vm.name} test environment"
task :up do
puts "Booting #{vm.name} test environment"
begin
vm.up
rescue ExecError => e
puts e.message
puts e.output.join("\n")
exit 1
end
end
desc "Shut down #{vm.name} test environment"
task :down do
puts "Shutting down #{vm.name} test environment"
begin
vm.down
rescue ExecError => e
puts e.message
puts e.output.join("\n")
exit 1
end
end
desc "Destroy #{vm.name} test environment"
task :destroy => :down do
puts "Destroying #{vm.name} test environment"
begin
vm.destroy
rescue ExecError => e
puts e.message
puts e.output.join("\n")
exit 1
end
end
desc "Provision #{vm.name} test environment"
task :provision => :up do
puts "Provisioning #{vm.name} test environment"
begin
vm.provision
rescue ExecError => e
puts e.message
puts e.output.join("\n")
exit 1
end
end
end
end
task :"up:all" => upTasks
task :"down:all" => downTasks
task :"destroy:all" => destroyTasks
task :"provision:all" => provisionTasks
desc "Boot all test environments"
task :up => :"up:all"
desc "Shut down all test environments"
task :down => :"down:all"
desc "Destroy all test environments"
task :destroy => :"destroy:all"
desc "Provision all test environments"
task :provision => :"provision:all"
end
namespace :spec do
specTasks = []
AnsibleHelper.each do |vm|
namespace vm.name.to_sym do
vmTasks = []
Dir.glob("./spec/*-spec.rb").each do |file|
spec = File.basename file
# Trim off "-spec.rb" and add to list
taskName = spec[0..-9]
vmTasks << :"#{vm.name}:#{taskName}"
desc "Run #{taskName} spec in #{vm.name}"
RSpec::Core::RakeTask.new(taskName.to_sym => [:init]) do |task|
ENV["TARGET_HOST"] = vm.name
task.pattern = file
end
end
task :all => vmTasks
specTasks << :"#{vm.name}:all"
end
desc "Run all specs for #{vm.name}"
task vm.name.to_sym => "#{vm.name}:all"
end
task :all => specTasks
end
namespace :init do
desc "Symbolic link files and templates into the spec/playbooks directory"
task :links do
["files", "library", "templates", "filter_plugins"].each do |f|
path = "spec/playbooks/#{f}"
next if File.symlink? path or !File.exist? f
raise "File #{path} exists and is not a symlink! Don't know what to do" if File.exist? path
File.symlink "../../#{f}", path
end
end
task :default => [:links]
end
namespace :ansible do
playbookTasks = []
AnsibleHelper.each do |vm|
playbookTasks << "playbook:#{vm.name}"
desc "Run an Ansible module in the #{vm.name} environment"
task vm.name.to_sym, [:module, :args] do |t, args|
args.with_defaults :args => ""
AnsibleHelper.module(args.module, vm.name, args.args)
end
namespace :playbook do
desc "Run an Ansible playbook in the #{vm.name} environment"
task vm.name.to_sym, [:filename] do |t, args|
filename = File.expand_path(args.filename, File.dirname(__FILE__))
AnsibleHelper.playbook(filename, vm.name)
end
end
end
desc "Run an Ansible playbook in all environments"
task :playbook, [:filename] do |t, args|
filename = File.expand_path(args.filename, File.dirname(__FILE__))
AnsibleHelper.playbook filename
end
end
desc "Run all specs"
task :spec => "spec:all"
desc "Initialize test environment files"
task :init => "init:default"
task :default => ["environment:up", "environment:provision", "spec:all", "environment:destroy"]