-
Notifications
You must be signed in to change notification settings - Fork 225
Expand file tree
/
Copy pathRakefile
More file actions
253 lines (238 loc) · 8.04 KB
/
Rakefile
File metadata and controls
253 lines (238 loc) · 8.04 KB
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
# frozen_string_literal: true
require 'rototiller'
require 'json'
require 'open3'
require 'beaker-hostgenerator'
require 'fileutils'
require 'securerandom'
require_relative 'lib/acceptance/bolt_setup_helper'
# rubocop:disable Style/MixinUsage
extend Acceptance::BoltSetupHelper
# rubocop:enable Style/MixinUsage
desc "Generate Beaker Host config"
rototiller_task :host_config do |task|
unless ENV['BEAKER_HOSTS']
task.add_env(name: 'BOLT_CONTROLLER', default: 'debian12-64')
task.add_env(name: 'BOLT_NODES',
default: 'redhat9-64,fedora40-64,windows10ent-64')
ns = [ENV.fetch('BOLT_CONTROLLER', nil), ENV.fetch('BOLT_NODES', nil)].join(',')
n = ns.split(',')
n_new = []
n.each_with_index do |node, i|
roles = []
roles << if i.zero?
'bolt'
elsif /win/ =~ node
'winrm'
else
'ssh'
end
node = node + roles.join(',') + '.{type=aio}'
n_new << node
end
nodes_final = n_new.join('-')
generate = "bundle exec beaker-hostgenerator --hypervisor abs"
generate += " #{nodes_final}"
generate += " > hosts.yaml"
sh generate
sh "cat hosts.yaml"
end
end
beaker_options = [
{ name: '--log-level',
add_argument: {
name: 'debug',
add_env: {
name: 'BEAKER_LOG_LEVEL',
message: 'Beaker log level'
}
} },
{ name: '--tests',
add_argument: {
name: 'tests',
add_env: {
name: 'BEAKER_TESTS',
message: 'Beaker test path(s)'
}
} },
{ name: '--hosts',
add_argument: {
name: 'hosts.yaml',
add_env: {
name: 'BEAKER_HOSTS',
message: 'Beaker hosts file'
}
} },
{ name: '--preserve-hosts',
add_argument: {
name: 'never',
add_env: {
name: 'BEAKER_PRESERVE_HOSTS',
message: 'When should beaker keep hosts alive'
}
} },
{ name: '--keyfile',
add_argument: {
name: '~/.ssh/id_rsa-acceptance',
add_env: {
name: 'BEAKER_KEYFILE',
message: 'The private SSH key beaker will use to connect to SUTs'
}
} }
]
beaker_env = [
{ name: 'SSH_USER', default: ssh_user },
{ name: 'SSH_PASSWORD', default: ssh_password },
{ name: 'WINRM_USER', default: winrm_user },
{ name: 'WINRM_PASSWORD', default: winrm_password }
]
def test_targets
# TODO: make this compatable with BOLT_CONTROLER and BOLT_NODES
ENV['LAYOUT'] || 'fedora32-64bolt.{type=aio}-ubuntu2004-64ssh.{type=aio}-windows10ent-64winrm.{type=aio}'
end
# Use beaker-hostgenerator to get a list of platform names used by ABS based on
# the test targets for this run. Then use the list of platform names to create
# a string usable in the floaty API to check out hosts
def abs_targets
cli = BeakerHostGenerator::CLI.new([test_targets, '--disable-default-role', '--hypervisor=abs'])
output = cli.execute.to_s
FileUtils.mkdir_p('tmp') # -p ignores when dir already exists
File.open("hosts.yaml", 'w') do |fh|
fh.print(cli.execute)
end
raw_targets = YAML.safe_load(output)
abs_platforms = Hash.new(0)
raw_targets['HOSTS'].each_value do |raw_target|
abs_platforms[raw_target['template']] += 1
end
abs_platforms.map { |platform, num| "#{platform}=#{num}" }.join(' ')
end
def provision_abs_hosts
abs_hosts = abs_targets
priority = ENV['PRIORITY'] || 1
token_str = if ENV['ABS_TOKEN']
"--token #{ENV['ABS_TOKEN']}"
else
''
end
floaty_cmd = "floaty get --force --priority #{priority} --json #{abs_hosts} #{token_str}"
puts("Requesting resources from ABS, this depends on floaty and assumes you have the proper configuration")
puts(floaty_cmd)
floaty_response, stderr, status = Open3.capture3(floaty_cmd)
raise "Failed to provision hosts with error: #{stderr}" unless status.exitstatus.zero?
host_hash = JSON.parse(floaty_response)
puts 'Job ID:', host_hash['job_id']
host_hash.delete('job_id')
transform_floaty_to_beaker_abs(host_hash)
end
def transform_floaty_to_beaker_abs(floaty_hash)
abs_array = floaty_hash.each_with_object([]) do |(host_type, vm_array), arr|
vm_array.each do |hostname|
arr << {
'hostname' => hostname,
'type' => host_type,
'engine' => 'abs'
}
end
end
abs_array.to_json
end
namespace :test do
desc "Run bolt acceptance tests against a published gem"
task gem: :host_config
rototiller_task :gem do |task|
beaker_options << {
name: '--options',
add_argument: { name: 'config/gem/options.rb' }
}
beaker_env.each { |env| task.add_env(env) }
task.add_env(name: 'GEM_VERSION', default: gem_version)
task.add_env(name: 'GEM_SOURCE', default: gem_source)
task.add_command do |cmd|
# without 'bundle exec' testing in jenkins fails
# with 'beaker not found'. We do not know why so
# for now use bundle exec to keep things working
# - Sean P. McDonald 4/24/18
cmd.name = 'bundle exec beaker'
cmd.add_option(*beaker_options)
end
end
desc "Run bolt acceptance tests against a git repo"
task git: :host_config
rototiller_task :git do |task|
beaker_options << {
name: '--options',
add_argument: { name: 'config/git/options.rb' }
}
beaker_env.each { |env| task.add_env(env) }
task.add_env(name: 'GIT_SERVER', default: git_server)
task.add_env(name: 'GIT_FORK', default: git_fork)
task.add_env(name: 'GIT_BRANCH', default: git_branch)
task.add_env(name: 'GIT_SHA', default: git_sha)
task.add_command do |cmd|
# without 'bundle exec' testing in jenkins fails
# with 'beaker not found'. We do not know why so
# for now use bundle exec to keep things working
# - Sean P. McDonald 4/24/18
cmd.name = 'bundle exec beaker'
cmd.add_option(*beaker_options)
end
end
desc "Run bolt acceptance tests against a package"
task package: :host_config
rototiller_task :package do |task|
beaker_options << {
name: '--options',
add_argument: { name: 'config/package/options.rb' }
}
beaker_env.each { |env| task.add_env(env) }
task.add_env(name: 'SHA')
task.add_command do |cmd|
# without 'bundle exec' testing in jenkins fails
# with 'beaker not found'. We do not know why so
# for now use bundle exec to keep things working
# - Sean P. McDonald 4/24/18
cmd.name = 'bundle exec beaker'
cmd.add_option(*beaker_options)
end
end
desc "Run bolt acceptance tests against git sha on hosts provisioned from ABS"
task :preserve
rototiller_task :preserve do |task|
beaker_options << {
name: '--options',
add_argument: { name: 'config/git/options.rb' }
}
beaker_env.each { |env| task.add_env(env) }
task.add_env(name: 'GIT_SERVER', default: git_server)
task.add_env(name: 'GIT_FORK', default: git_fork)
task.add_env(name: 'GIT_BRANCH', default: git_branch)
task.add_env(name: 'GIT_SHA', default: git_sha)
task.add_env(name: 'BEAKER_PRESERVE_HOSTS', default: 'always')
task.add_env(name: 'ABS_RESOURCE_HOSTS', default: provision_abs_hosts)
task.add_command do |cmd|
cmd.name = 'bundle exec beaker'
cmd.add_option(*beaker_options)
end
end
desc "Run bolt acceptance tests against git sha on preserved hosts"
task :preserved
rototiller_task :preserved do |task|
beaker_options << {
name: '--options',
add_argument: { name: 'config/git/options.rb' }
}
beaker_env.each { |env| task.add_env(env) }
task.add_env(name: 'GIT_SERVER', default: git_server)
task.add_env(name: 'GIT_FORK', default: git_fork)
task.add_env(name: 'GIT_BRANCH', default: git_branch)
task.add_env(name: 'GIT_SHA', default: git_sha)
task.add_env(name: 'BEAKER_PRESERVE_HOSTS', default: 'always')
task.add_env(name: 'BEAKER_HOSTS', default: 'log/latest/hosts_preserved.yml')
task.add_env(name: 'ABS_RESOURCE_HOSTS', default: '[]')
task.add_command do |cmd|
cmd.name = 'bundle exec beaker'
cmd.add_option(*beaker_options)
end
end
end