-
Notifications
You must be signed in to change notification settings - Fork 3
/
Rakefile
157 lines (141 loc) · 5.29 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
require 'chef/role'
require 'chef/environment'
require 'json'
require 'pp'
require 'fileutils'
require 'rake'
TOPDIR = File.dirname(__FILE__)
ROLE_DIR = File.expand_path(File.join(TOPDIR, "./roles"))
ENVI_DIR = File.expand_path(File.join(TOPDIR, "./environments"))
FileUtils.mkdir_p File.expand_path(File.join(TOPDIR, '.json/environments'))
FileUtils.mkdir_p File.expand_path(File.join(TOPDIR, '.json/roles'))
namespace :convert do
desc "Convert ruby roles from ruby to json, creating/overwriting json files."
task :roles4rb2json do
Dir.glob(File.join(ROLE_DIR, '*.rb')) do |rb_file|
role = Chef::Role.new
role.from_file(rb_file)
json_file = rb_file.sub(/\.rb$/,'.json')
File.open(json_file, 'w'){|f| f.write(JSON.pretty_generate(JSON.parse(role.to_json)))}
end
end
desc "Convert ruby env from ruby to json, creating/overwriting json files."
task :envi4rb2json do
Dir.glob(File.join(ENVI_DIR, '*.rb')) do |rb_file|
environ = Chef::Environment.new
environ.from_file(rb_file)
json_file = rb_file.sub(/\.rb$/,'.json')
File.open(json_file, 'w'){|f| f.write(JSON.pretty_generate(JSON.parse(environ.to_json)))}
end
end
desc "Convert ruby roles from json to ruby, creating/overwriting rb files."
task :roles4json2rb do
Dir.glob(File.join(ROLE_DIR, '*.json')) do |json_file|
rb_file = json_file.sub(/\.json$/,'.rb')
File.open(rb_file, 'w'){|f| PP.pp(JSON.parse(IO.read(json_file)), f)}
end
end
desc "Convert ruby env from json to ruby, creating/overwriting rb files."
task :envi4json2rb do
Dir.glob(File.join(ENVI_DIR, '*.json')) do |json_file|
rb_file = json_file.sub(/\.json$/,'.rb')
File.open(rb_file, 'w'){|f| PP.pp(JSON.parse(IO.read(json_file)), f)}
end
end
desc "Convert DSL from ruby to json, creating/overwriting json files."
task :rb2json4kfield do
Dir.glob(File.join(ENVI_DIR, '*.rb')) do |rb_file|
environ = Chef::Environment.new
environ.from_file(rb_file)
json_file = rb_file.sub(/\.rb$/,'.json')
json_file = json_file.sub(/environments/,'.json/environments')
File.open(json_file, 'w'){|f| f.write(JSON.pretty_generate(JSON.parse(environ.to_json)))}
end
Dir.glob(File.join(ROLE_DIR, '*.rb')) do |rb_file|
role = Chef::Role.new
role.from_file(rb_file)
json_file = rb_file.sub(/\.rb$/,'.json')
json_file = json_file.sub(/roles/,'.json/roles')
File.open(json_file, 'w'){|f| f.write(JSON.pretty_generate(JSON.parse(role.to_json)))}
end
end
end
namespace :ci do
task :_worker, :arg1 do |t, args|
pid = fork {exec(args['arg1']) }
_, status = Process.waitpid2(pid)
if !status.success?
@error = "task failed"
exit 1
end
end
desc "create vm for vlan "
task :create_vlan do
cmd = "KITCHEN_YAML=./.kitchen.yml kitchen create default-ubuntu-1404 -p && sleep 5"
Rake::Task['ci:_worker'].invoke(cmd)
end
desc "create vm for 32bit test"
task :create_32bit do
cmd = "KITCHEN_YAML=./.kitchen.yml kitchen create 32bit-ubuntu-1404 -p && sleep 5"
Rake::Task['ci:_worker'].invoke(cmd)
end
desc "verify_vlan"
task :verify_vlan do
puts("About to run Test kitchen ")
cmd = "KITCHEN_YAML=./.kitchen.yml kitchen converge default-ubuntu-1404"
cmd << "&& KITCHEN_YAML=./.kitchen.yml kitchen verify default-ubuntu-1404"
Rake::Task['ci:_worker'].reenable
Rake::Task['ci:_worker'].invoke(cmd)
end
desc "verify_32bit"
task :verify_32bit do
puts("About to run Test kitchen ")
cmd = "KITCHEN_YAML=./.kitchen.yml kitchen converge 32bit-ubuntu-1404"
cmd << "&& KITCHEN_YAML=./.kitchen.yml kitchen verify 32bit-ubuntu-1404"
Rake::Task['ci:_worker'].reenable
Rake::Task['ci:_worker'].invoke(cmd)
end
desc "verify vlan system"
task :verify_vlan_system=>['convert:rb2json4kfield','ci:create_vlan','ci:verify_vlan' ] do
puts "System configured"
end
desc "verify 32bit system"
task :verify_32bit_system=>['convert:rb2json4kfield','ci:create_32bit','ci:verify_32bit' ] do
puts "System configured"
end
desc "create every vm "
task :create_vm do
cmd = "KITCHEN_YAML=./.kitchen_distribute.yml kitchen create 1404 -p "
Rake::Task['ci:_worker'].reenable
Rake::Task['ci:_worker'].invoke(cmd)
end
desc "converge database"
task :converge_db do
puts("About to run Test kitchen ")
cmd = "KITCHEN_YAML=./.kitchen_distribute.yml kitchen converge db-ubuntu-1404"
Rake::Task['ci:_worker'].reenable
Rake::Task['ci:_worker'].invoke(cmd)
end
task :converge_control do
puts("About to run Test kitchen ")
cmd = "KITCHEN_YAML=./.kitchen_distribute.yml kitchen verify control-ubuntu-1404"
Rake::Task['ci:_worker'].reenable
Rake::Task['ci:_worker'].invoke(cmd)
end
task :converge_compute do
puts("About to run Test kitchen ")
cmd = "KITCHEN_YAML=./.kitchen_distribute.yml kitchen verify compute-ubuntu-1404"
Rake::Task['ci:_worker'].reenable
Rake::Task['ci:_worker'].invoke(cmd)
end
desc "verify system"
task :verify_system =>['ci:converge_db','ci:converge_control','ci:converge_compute' ] do
puts "System configured"
end
desc "destroy system"
task :destroy_system do
cmd = "KITCHEN_YAML=./.kitchen_distribute.yml kitchen destroy"
Rake::Task['ci:_worker'].reenable
Rake::Task['ci:_worker'].invoke(cmd)
end
end