forked from bbatsche/Ansible-PostgreSQL-Role
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
118 lines (88 loc) · 2.99 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
require "rake"
require "yaml"
require "rspec/core/rake_task"
require_relative "spec/lib/ansible_helper"
require_relative "spec/lib/vagrant_helper"
desc "Run an arbitrary vagrant command for the test environment"
task :vagrant, [:cmd] => [:"vagrant:up"] do |t, args|
exec "vagrant #{args.cmd} default"
end
namespace :vagrant do
desc "Boot the test environment (w/o provisioning)"
task :up do
VagrantHelper.instance.cmd("Booting", "up --provider=virtualbox --no-color --no-provision")
end
desc "Provision the test environment"
task :provision do
VagrantHelper.instance.cmd("Provisioning", "provision")
end
desc "Destroy the test environment"
task :destroy do
VagrantHelper.instance.cmd("Destroying", "destroy --force")
end
end
task :spec => "spec:all"
namespace :spec do
tasks = []
Dir.glob('./spec/*-spec.rb').each do |file|
spec = File.basename file
# Trim off "-spec.rb" and add to list
tasks << spec[0..-9]
end
task :all => tasks
task :default => :all
tasks.each do |taskName|
desc "Run serverspec tests for #{taskName}"
RSpec::Core::RakeTask.new(taskName.to_sym => [:init]) do |t|
t.pattern = "./spec/#{taskName}-spec.rb"
end
end
end
desc "Run an arbitrary Ansible module in the test environment"
task :ansible, [:module, :args] do |t, args|
args.with_defaults :args => ""
AnsibleHelper.instance.cmd args.module, args.args
end
namespace :ansible do
desc "Run an arbitrary Ansible playbook in the test environment"
task :playbook, [:filename] do |t, args|
filename = File.expand_path(args.filename, File.dirname(__FILE__))
AnsibleHelper.instance.playbook filename
end
end
task :init => "init:default"
namespace :init do
desc "Symbolic link files and templates into the spec/playbooks directory"
task :links do
["files", "library", "templates"].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
desc "Copy handlers into spec and Travis playbooks"
task :handlers do
playbooks = Dir.glob "spec/playbooks/*.yml"
playbooks << "travis-playbook.yml"
playbooks.each do |file|
dir = File.dirname file
book = YAML.load(File.read(file))
next unless book[0].has_key? "handlers"
new_includes = []
new_handlers = []
book[0]["handlers"].each do |handler|
next unless handler.has_key? "include"
new_includes << handler
handler_path = File.expand_path dir + "/" + handler["include"]
handler_content = YAML.load(File.read(handler_path))
next if handler_content.nil?
new_handlers += handler_content
end
book[0]["handlers"] = new_includes + new_handlers
File.write file, book.to_yaml
end
end
task :default => [:links, :handlers]
end
task :default => [:"vagrant:up", :"vagrant:provision", :"spec:all", :"vagrant:destroy"]