This repository has been archived by the owner on Feb 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathrakefile
710 lines (622 loc) · 27.8 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
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
require 'rototiller'
require 'rubocop/rake_task'
require './setup/helpers/abs_helper'
include AbsHelper
require './tests/helpers/perf_results_helper'
include PerfResultsHelper
require "./lib/beaker_dsl"
REF_ARCH_STD, REF_ARCH_LARGE = ["S","L"]
def master_from_beaker_hosts_hash(hosts)
master = nil
hosts.each_key do |name|
host = hosts[name]
master = host if host[:roles].include?("master")
end
master
end
def fetch_pe_for_master(beaker_obj, master, ver, dir, dest = "/tmp")
local = File.directory?(dir)
filename = "puppet-enterprise-#{ver}-#{master['packaging_platform']}"
non_exist_msg = "PE #{filename} does not exist at #{dir}"
if local
extension = File.exist?("#{dir}/#{filename}.tar.gz") ? ".tar.gz" : ".tar"
raise non_exist_msg unless File.exist?("#{dir}/#{filename}#{extension}")
else
# ensure that package exists at remote location
extension = beaker_obj.link_exists?("#{dir}/#{filename}.tar.gz") ? ".tar.gz" : ".tar"
raise non_exist_msg unless beaker_obj.link_exists?("#{dir}/#{filename}#{extension}")
beaker_obj.fetch_http_file(dir, "#{filename}#{extension}", dest)
end
local_file = File.join(dest, filename) + extension
raise "failed to retrieve #{filename}#{extenstion}" unless File.exist?(local_file)
return if extension == ".tar.gz" || File.exist?("#{local_file}.gz")
Zlib::GzipWriter.open("#{local_file}.gz") do |gz|
gz.write IO.binread(local_file)
end
end
task :default => :performance
desc 'Provision systems using ABS (or use already set ABS_RESOURCE_HOSTS) and then execute beaker performance setup and tests'
rototiller_task :performance => "validate:performance_env_vars" do
ENV['REF_ARCH'] ||= REF_ARCH_STD
if ENV['PUPPET_GATLING_REPORTS_ONLY'] == 'true' && (!ENV['PUPPET_GATLING_REPORTS_TARGET'] || ENV['PUPPET_GATLING_REPORTS_TARGET'] == '')
abort 'A valid result folder (i.e. PerfTestLarge-1524848074511) must be specified for PUPPET_GATLING_REPORTS_TARGET if PUPPET_GATLING_REPORTS_ONLY=true'
end
if ENV['REF_ARCH'] == REF_ARCH_LARGE
Rake::Task["pe_xl:deploy"].invoke
else
Rake::Task["performance_provision_with_abs"].invoke unless ENV['ABS_RESOURCE_HOSTS'] ||
(ENV['BEAKER_HOSTS'] &&
ENV['BEAKER_HOSTS'] != 'config/beaker_hosts/pe-perf-test.cfg' &&
ENV['BEAKER_HOSTS'] != 'config/beaker_hosts/foss-perf-test.cfg' &&
ENV['BEAKER_HOSTS'] != 'config/beaker_hosts/opsworks-perf-test.cfg')
end
Rake::Task["performance_without_provision"].invoke
Rake::Task["performance_deprovision_with_abs"].execute unless ENV['BEAKER_PRESERVE_HOSTS'] == 'always' ||
((@beaker_cmd.nil? || @beaker_cmd.result.exit_code != 0)&&
ENV['BEAKER_PRESERVE_HOSTS'] == 'onfail')
end
desc 'Provision systems using ABS (or use already set ABS_RESOURCE_HOSTS) and then execute beaker performance setup ' +
'and tests for opsworks'
rototiller_task :opsworks_performance do
# If BEAKER_TESTS is not set at all, default it to tests/OpsWorks.rb
ENV["BEAKER_TESTS"] = "tests/OpsWorks.rb" if ENV["BEAKER_TESTS"].nil?
# If the test is anything other than OpsWorks.rb OR empty string so it can be executed later then raise
raise "The test must be Opsworks.rb, or '' if you plan to execute tests later" unless
["", "tests/OpsWorks.rb"].include? ENV["BEAKER_TESTS"]
configure_opsworks
Rake::Task["performance"].invoke
end
def configure_opsworks
ENV['BEAKER_HOSTS'] = 'config/beaker_hosts/opsworks-perf-test.cfg'
# sizes can be any of the 3 below, specifying nothing defaults to c5.2xlarge so that is ok too
opsworks_instance_sizes = ["m5.large", "c5.xlarge", "c5.2xlarge", ""]
if ["c5.2xlarge", ""].include? ENV['ABS_AWS_MASTER_SIZE']
opsworks_size = "Large"
elsif "c5.xlarge" == ENV['ABS_AWS_MASTER_SIZE']
opsworks_size = "Med"
elsif "m5.large" == ENV['ABS_AWS_MASTER_SIZE']
opsworks_size = "Small"
else
raise "Env var ABS_AWS_MASTER_SIZE must be one of #{opsworks_instance_sizes.to_s}"
end
scale_classes = ["role::by_size::small", "role::by_size::medium", "role::by_size::large", ""]
if ["role::by_size::large", ""].include? ENV["PUPPET_SCALE_CLASS"]
catalog_size = "Large"
elsif "role::by_size::medium" == ENV["PUPPET_SCALE_CLASS"]
catalog_size = "Med"
elsif "role::by_size::small" == ENV["PUPPET_SCALE_CLASS"]
catalog_size = "Small"
else
raise "Env var PUPPET_SCALE_CLASS must be one of #{scale_classes.to_s}"
end
ENV["OPSWORKS_SCENARIO"] = "OpsWorks#{opsworks_size}Catalog#{catalog_size}.json"
end
desc 'Provision systems for the performance task with ABS - included in the performance task'
# validate the BEAKER_INSTALL_TYPE (and dependent env vars) to prevent provisioning if incorrectly specified
rototiller_task :performance_provision_with_abs => "validate:beaker_install_type" do |t|
t.add_env({:name => 'BEAKER_PE_DIR', :message => 'The PE download directory, example: https://artifactory.delivery.puppetlabs.net/artifactory/generic_enterprise__local/archives/releases/2017.2.4'}) if ENV['BEAKER_INSTALL_TYPE'] == 'pe'
t.add_env({:name => 'BEAKER_PE_VER', :message => 'The PE version to install on hosts, example: 2017.2.4'}) if ENV['BEAKER_INSTALL_TYPE'] == 'pe'
t.add_env({:name => 'ABS_OS', :default => 'centos-7-x86-64-west', :message => 'The OS to provision with ABS: centos-7-x86-64-west (for AWS), or centos-7-x86_64 (for vmpooler)'})
t.add_env({:name => 'ABS_AWS_METRICS_SIZE', :default => 'c5.2xlarge', :message => 'The AWS instance size for the Metrics host'})
t.add_env({:name => 'ABS_AWS_MASTER_SIZE', :default => 'c5.2xlarge', :message => 'The AWS instance size for the Master host'})
abs_resource_hosts = get_abs_resource_hosts(get_a2a_hosts)
raise 'Unable to provision hosts via ABS' unless abs_resource_hosts
end
desc 'Task to de-provision systems that were provisioned with ABS - included in the performance task following the rules of BEAKER_PRESERVE_HOSTS env var.'
rototiller_task :performance_deprovision_with_abs do
abs_resource_hosts = ENV['ABS_RESOURCE_HOSTS'].nil? ? get_last_abs_resource_hosts : ENV['ABS_RESOURCE_HOSTS']
raise 'This task requires an array of hostnames to be specified via the ABS_RESOURCE_HOSTS environment variable or the last_abs_resource_hosts.log file' unless abs_resource_hosts
returned_hosts = return_abs_resource_hosts(abs_resource_hosts)
raise 'Failed to de-provision ABS hosts' unless returned_hosts == abs_resource_hosts
end
desc 'Setup Agent for recordings'
rototiller_task :setup_recording_agent do
ENV['BEAKER_HOSTS'] ||= "log/latest/hosts_preserved.yml"
ENV['ABS_RESOURCE_HOSTS'] = File.open("last_abs_resource_hosts.log").readlines[0] if File.exist? "last_abs_resource_hosts.log"
ENV['BEAKER_PRE_SUITE'] = "setup/install_gatling/00_pre_install/05_initialize_helpers.rb,setup/install_gatling/setup_metrics_as_agent.rb"
ENV['BEAKER_TESTS'] = ""
Rake::Task["performance_without_provision"].invoke
end
desc 'Run Performance tests using previously provisioned hosts'
rototiller_task :performance_against_already_provisioned do
ENV['BEAKER_HOSTS'] ||= "log/latest/hosts_preserved.yml"
ENV['ABS_RESOURCE_HOSTS'] = File.open("last_abs_resource_hosts.log").readlines[0] if File.exist? "last_abs_resource_hosts.log"
ENV['BEAKER_PRE_SUITE'] = ""
Rake::Task["performance_without_provision"].invoke
end
desc 'Execute beaker performance setup and tests against existing hosts specified by ABS_RESOURCE_HOSTS env var, intended to be used in CI - use task "performance" for local/dev execution'
rototiller_task :performance_without_provision => "validate:performance_env_vars" do |t|
ENV['REF_ARCH'] ||= REF_ARCH_STD
if ENV['REF_ARCH'] == REF_ARCH_LARGE
generated_hosts = "build/pe_xl/beaker.cfg"
unless File.file? ENV['BEAKER_HOSTS'].to_s
raise "No valid BEAKER_HOSTS file available" unless File.file? generated_hosts
ENV['BEAKER_HOSTS'] = generated_hosts
end
ENV['BEAKER_INSTALL_TYPE'] = "pe"
ENV['BEAKER_OPTIONS_FILE'] = "setup/options/options_pe_xl.rb"
end
t.add_env({:name => 'ABS_RESOURCE_HOSTS', :message => 'The string returned from the ABS service describing your hosts'}) if ENV['BEAKER_HOSTS'] == 'config/beaker_hosts/pe-perf-test.cfg' ||
ENV['BEAKER_HOSTS'] == 'config/beaker_hosts/foss-perf-test.cfg'
t.add_env({:name => 'ENVIRONMENT_TYPE', :message => 'Either gatling or clamps', :default => 'gatling'})
t.add_env({:name => 'PUPPET_GATLING_R10K_CONTROL_REPO', :default => 'https://github.com/puppetlabs/puppetlabs-pe_perf_control_repo.git'})
if ENV['BEAKER_INSTALL_TYPE'] == 'foss'
t.add_env({:name => 'PUPPET_GATLING_R10K_BASEDIR', :default => '/etc/puppetlabs/code/environments'})
else
t.add_env({:name => 'PUPPET_GATLING_R10K_BASEDIR', :default => '/etc/puppetlabs/code-staging/environments'})
end
t.add_env({:name => 'PUPPET_GATLING_R10K_ENVIRONMENTS', :default => 'production'})
t.add_env({:name => 'PUPPET_BIN_DIR', :default => '/opt/puppetlabs/puppet/bin'})
t.add_env({:name => 'PUPPET_R10K_VERSION', :default => '2.3.0'})
t.add_env({:name => 'PUPPET_SCALE_CLASS', :default => 'role::by_size::large'})
t.add_env({:name => 'PUPPET_GATLING_SCENARIO', :default => 'ApplesToApples.json'})
t.add_env({:name => 'BEAKER_TESTS', :default => 'tests/ApplesToApples.rb'})
t.add_env({:name => 'BEAKER_POST_SUITE', :default => ''})
t.add_env({:name => 'SUT_ARCHIVE_FILES', :default => ''})
t.add_env({:name => 'PACKAGE_BUILD_VERSION', :default => 'latest'}) if ENV['BEAKER_INSTALL_TYPE'] == 'foss'
t.add_env({:name => 'PUPPET_AGENT_VERSION', :default => 'latest'}) if ENV['BEAKER_INSTALL_TYPE'] == 'foss'
t.add_env({:name => 'PUSH_TO_BIGQUERY', :default => 'false',
:message => 'True if you want to store a new set of results as a baseline value'})
configure_opsworks if ENV["BEAKER_TESTS"] == 'tests/OpsWorks.rb'
# env vars needed for Beaker
@beaker_cmd = t.add_command do |command|
command.name = "bundle exec beaker"
command.add_env({:name => 'BEAKER_EXECUTABLE'})
command.add_option do |option|
option.name = '--hosts'
option.message = 'The configuration file that Beaker will use'
option.add_argument do |arg|
arg.name = "config/beaker_hosts/pe-perf-test.cfg" if ENV['BEAKER_INSTALL_TYPE'] == 'pe'
arg.name = "config/beaker_hosts/foss-perf-test.cfg" if ENV['BEAKER_INSTALL_TYPE'] == 'foss'
arg.add_env({:name => 'BEAKER_HOSTS'})
end
end
# this is specified in the options file
# this is here so it can be overridden in the rake task
# there is no beaker built-in env var for this
unless (!ENV['BEAKER_KEYFILE'] || ENV['BEAKER_KEYFILE'] == '') #unless nil or empty
command.add_option do |option|
option.name = '--keyfile'
option.message = 'The SSH key used to access a SUT'
option.add_argument do |arg|
arg.name = "#{ENV['HOME']}/.ssh/id_rsa-acceptance"
arg.add_env({:name => 'BEAKER_KEYFILE'})
end
end
end
command.add_option do |option|
option.name = '--log-level'
option.message = 'The log level under which you want beaker to run'
option.add_argument do |arg|
arg.name = 'debug'
arg.add_env({:name => 'BEAKER_LOG_LEVEL'})
end
end
unless ENV['BEAKER_OPTIONS_FILE'] == ''
command.add_option do |option|
option.name = '--options'
option.message = 'Beaker options file'
option.add_argument do |arg|
unless ENV['BEAKER_INSTALL_TYPE'] == 'foss'
if ENV['ENVIRONMENT_TYPE'] == 'clamps'
arg.name = 'setup/options/options_pe_clamps.rb'
else
arg.name = 'setup/options/options_pe.rb'
end
else
arg.name = 'setup/options/options_foss.rb'
end
arg.add_env({:name => 'BEAKER_OPTIONS_FILE'})
end
end
end
#FIXME this disallows rototiller from showing this env, when it doesn't exist
unless (!ENV['BEAKER_PRE_SUITE'] || ENV['BEAKER_PRE_SUITE'] == '') #unless nil or empty
command.add_option do |option|
option.name = '--pre-suite'
option.message = 'Beaker pre-suite'
option.add_argument do |arg|
arg.name = ''
arg.add_env({:name => 'BEAKER_PRE_SUITE'})
end
end
end
unless ENV['BEAKER_POST_SUITE'] == ''
command.add_option do |option|
option.name = '--post-suite'
option.message = 'Beaker post-suite'
option.add_argument do |arg|
arg.name = 'post/zzz_copy_sut_archive_files.rb'
arg.add_env({:name => 'BEAKER_POST_SUITE'})
end
end
end
unless ENV['BEAKER_TESTS'] == ''
command.add_option do |option|
option.name = '--tests'
option.message = 'Beaker tests'
option.add_argument do |arg|
arg.name = 'tests/'
arg.add_env({:name => 'BEAKER_TESTS'})
end
end
end
unless (!ENV['BEAKER_HELPER'] || ENV['BEAKER_HELPER'] == '') #unless nil or empty
command.add_option do |option|
option.name = '--helper'
option.message = 'Setup helper ruby scripts, comma separated'
option.add_argument do |arg|
arg.add_env({:name => 'BEAKER_HELPER'})
end
end
end
command.add_option do |option|
option.name = '--preserve-hosts'
option.message = 'Whether to preserve hosts or not.'
option.add_argument do |arg|
arg.name = 'always'
arg.add_env({:name => 'BEAKER_PRESERVE_HOSTS'})
end
end
command.add_option do |option|
option.name = '--type'
option.message = 'pe or foss'
option.add_argument do |arg|
arg.name = 'pe'
arg.add_env({:name => 'BEAKER_INSTALL_TYPE'})
end
end
puts command.to_str
# Default:
# "bundle exec beaker --hosts --keyfile /Users/samwoods/.ssh/id_rsa-acceptance --log-level debug
# --pre-suite setup/install_gatling --helper
# setup/helpers/classification_helper.rb,setup/helpers/ldap_helper.rb,setup/helpers/gatling_config_helper.rb
# --preserve-hosts always --type pe"
end
end
desc 'Run Performance setup for clamps'
rototiller_task :performance_clamps do |t|
ENV['ENVIRONMENT_TYPE'] = 'clamps'
Rake::Task["performance"].invoke
end
desc 'Run Performance setup for gatling'
rototiller_task :performance_gatling do |t|
ENV['ENVIRONMENT_TYPE'] = 'gatling'
Rake::Task["performance"].invoke
end
desc 'Run Performance setup and a very short iteration of gatling tests'
rototiller_task :acceptance do |t|
ENV['ENVIRONMENT_TYPE'] = 'gatling'
ENV['PUPPET_GATLING_SCENARIO'] = 'acceptance.json'
ENV['BEAKER_HOSTS'] ||= 'config/beaker_hosts/pe-vmpooler.cfg'
ENV['BEAKER_TESTS'] ||= 'tests/acceptance.rb'
ENV['BEAKER_POST_SUITE'] = ''
# Need to change this from an AWS OS image to a vmpooler OS image
ENV['ABS_OS'] ||= 'centos-7-x86_64'
Rake::Task["performance"].invoke
end
desc 'Run Performance setup for gatling'
rototiller_task :performance_setup do
ENV['BEAKER_PRESERVE_HOSTS'] = ENV['BEAKER_PRESERVE_HOSTS'] || 'always'
ENV['ENVIRONMENT_TYPE'] = 'gatling'
ENV['BEAKER_TESTS'] = ''
Rake::Task["performance"].invoke
end
desc 'Run Soak setup and test for gatling'
rototiller_task :soak do
ENV['ENVIRONMENT_TYPE'] = 'gatling'
ENV['BEAKER_TESTS'] = ENV['BEAKER_TESTS'] || 'tests/Soak.rb'
ENV['BEAKER_PRESERVE_HOSTS'] = ENV['BEAKER_PRESERVE_HOSTS'] || 'always'
ENV['PUPPET_SCALE_CLASS'] = ENV['PUPPET_SCALE_CLASS'] || 'role::by_size::large'
ENV['PUPPET_GATLING_SCALE_TUNE'] = ENV['PUPPET_GATLING_SCALE_TUNE'] || 'true'
ENV['ABS_AWS_REAP_DAYS'] = ENV['ABS_AWS_REAP_DAYS'] || '30'
Rake::Task["performance"].invoke
end
desc 'Run Soak setup for gatling'
rototiller_task :soak_setup do
ENV['BEAKER_TESTS'] = ''
Rake::Task["soak"].invoke
end
desc 'Run Soak test for gatling on previously provisioned hosts'
rototiller_task :soak_provisioned do
ENV['ENVIRONMENT_TYPE'] = 'gatling'
ENV['BEAKER_TESTS'] = ENV['BEAKER_TESTS'] || 'tests/Soak.rb'
ENV['BEAKER_PRESERVE_HOSTS'] = ENV['BEAKER_PRESERVE_HOSTS'] || 'always'
ENV['PUPPET_SCALE_CLASS'] = ENV['PUPPET_SCALE_CLASS'] || 'role::by_size::large'
Rake::Task["performance_against_already_provisioned"].invoke
end
desc 'Run Scale setup and test for gatling'
rototiller_task :autoscale do
ENV['ENVIRONMENT_TYPE'] = 'gatling'
ENV['BEAKER_TESTS'] = ENV['BEAKER_TESTS'] || 'tests/Scale.rb'
ENV['BEAKER_PRESERVE_HOSTS'] = ENV['BEAKER_PRESERVE_HOSTS'] || 'always'
ENV['PUPPET_SCALE_CLASS'] = ENV['PUPPET_SCALE_CLASS'] || 'role::by_size::small'
ENV['PUPPET_GATLING_SCALE_TUNE'] = ENV['PUPPET_GATLING_SCALE_TUNE'] || 'true'
Rake::Task["performance"].invoke
Rake::Task["autoscale_handle_latest_results"].invoke unless ENV['BEAKER_TESTS'] == ''
end
desc 'Run Scale setup and test for gatling restarting pe-puppetserver with each iteration'
rototiller_task :autoscale_cold do
ENV['PUPPET_GATLING_SCALE_RESTART_PUPPETSERVER'] = 'true'
Rake::Task["autoscale"].invoke
end
desc 'Run Scale setup for gatling without restarting pe-puppetserver'
rototiller_task :autoscale_warm do
ENV['PUPPET_GATLING_SCALE_RESTART_PUPPETSERVER'] = 'false'
Rake::Task["autoscale"].invoke
end
desc 'Run Scale setup for gatling'
rototiller_task :autoscale_setup do
ENV['BEAKER_TESTS'] = ''
Rake::Task["autoscale"].invoke
end
desc 'Run puppet infrastructure tune setup for gatling on a previously provisioned master'
rototiller_task :autoscale_tune do
ENV['ENVIRONMENT_TYPE'] = 'gatling'
ENV['BEAKER_TESTS'] = 'setup/install_gatling/50_tune/10_puppet_infrastructure_tune.rb'
ENV['BEAKER_PRESERVE_HOSTS'] = 'always'
ENV['PUPPET_GATLING_SCALE_TUNE'] = 'true'
Rake::Task["performance_against_already_provisioned"].invoke
end
desc 'Run Scale test for gatling on previously provisioned hosts'
rototiller_task :autoscale_provisioned do
ENV['ENVIRONMENT_TYPE'] = 'gatling'
ENV['BEAKER_TESTS'] = ENV['BEAKER_TESTS'] || 'tests/Scale.rb'
ENV['BEAKER_PRESERVE_HOSTS'] = ENV['BEAKER_PRESERVE_HOSTS'] || 'always'
ENV['PUPPET_SCALE_CLASS'] = ENV['PUPPET_SCALE_CLASS'] || 'role::by_size::small'
Rake::Task["performance_against_already_provisioned"].invoke
Rake::Task["autoscale_handle_latest_results"].invoke
end
desc 'Run Scale setup for gatling'
rototiller_task :autoscale_provisioned_cold do
ENV['PUPPET_GATLING_SCALE_RESTART_PUPPETSERVER'] = 'true'
Rake::Task["autoscale_provisioned"].invoke
end
desc 'Run Scale setup for gatling'
rototiller_task :autoscale_provisioned_warm do
ENV['PUPPET_GATLING_SCALE_RESTART_PUPPETSERVER'] = 'false'
Rake::Task["autoscale_provisioned"].invoke
end
desc 'Run perf simulation for CD4PE testing on previously provisioned hosts'
rototiller_task :autoscale_provisioned_cd4pe do
# the cd4pe test uses the autoscale test type which provides additional reporting functionality
# however, it doesn't actually scale the scenario
# setting the following variables will disable the scaling functionality
# TODO: update to use a standard perf run when the reporting has been updated
# just run one iteration of the scenario
ENV['PUPPET_GATLING_SCALE_ITERATIONS'] = '1'
# don't scale the scenario
ENV['PUPPET_GATLING_SCALE_INCREMENT'] = '0'
# this scenario performs two repetitions
ENV['PUPPET_GATLING_SCALE_SCENARIO'] = 'cd4pe.json'
# use the autoscale test type using previously provisioned hosts with no restart
Rake::Task["autoscale_provisioned_warm"].invoke
end
desc 'Run tiny Scale test for gatling on previously provisioned hosts'
rototiller_task :autoscale_provisioned_tiny do
ENV['PUPPET_GATLING_SCALE_ITERATIONS'] = '3'
ENV['PUPPET_GATLING_SCALE_INCREMENT'] = '1'
ENV['PUPPET_GATLING_SCALE_SCENARIO'] = 'Scale_tiny.json'
Rake::Task["autoscale_provisioned"].invoke
end
desc 'Run small Scale test for gatling on previously provisioned hosts'
rototiller_task :autoscale_provisioned_sm do
ENV['PUPPET_GATLING_SCALE_ITERATIONS'] = '10'
ENV['PUPPET_GATLING_SCALE_INCREMENT'] = '10'
ENV['PUPPET_GATLING_SCALE_SCENARIO'] = 'Scale_sm.json'
Rake::Task["autoscale_provisioned"].invoke
end
desc 'Run medium Scale test for gatling on previously provisioned hosts'
rototiller_task :autoscale_provisioned_med do |t|
ENV['PUPPET_GATLING_SCALE_ITERATIONS'] = '10'
ENV['PUPPET_GATLING_SCALE_INCREMENT'] = '100'
ENV['PUPPET_GATLING_SCALE_SCENARIO'] = 'Scale_med.json'
Rake::Task["autoscale_provisioned"].invoke
end
desc 'Handle the latest scale results after the run has completed'
task :autoscale_handle_latest_results do
Rake::Task["autoscale_copy_log"].invoke
Rake::Task["autoscale_csv2html"].invoke
end
desc 'Copy latest log to latest scale results after the run has completed'
task :autoscale_copy_log do
source = File.realpath("log/latest")
dest = File.realpath("results/scale/latest/log")
puts "Copying from #{source} to #{dest}..."
puts
FileUtils.copy_entry source, dest
end
desc 'Generate HTML table from results CSV files'
task :autoscale_csv2html do
scale_results_dir = File.realpath("results/scale/latest")
csv2html_directory(scale_results_dir)
end
# TODO: determine optimal instance types and volume sizes
desc 'Provision the hosts for a cd4pe test environment via ABS'
task :abs_provision_environment_cd4pe do
Rake::Task["abs_provision_host_cd4pe"].execute
Rake::Task["abs_provision_host_gitlab"].execute
Rake::Task["abs_provision_host_agent"].execute
Rake::Task["abs_provision_host_worker"].execute
end
desc 'Provision a cd4pe host via ABS'
rototiller_task :abs_provision_host_cd4pe do
host_to_provision = get_host_to_provision("cd4pe", "c5.2xlarge", "80")
abs_resource_hosts = get_abs_resource_hosts(host_to_provision)
raise 'Unable to provision hosts via ABS' unless abs_resource_hosts
end
desc 'Provision a gitlab host via ABS'
rototiller_task :abs_provision_host_gitlab do
host_to_provision = get_host_to_provision("gitlab", "c5.xlarge", "80")
abs_resource_hosts = get_abs_resource_hosts(host_to_provision)
raise 'Unable to provision hosts via ABS' unless abs_resource_hosts
end
desc 'Provision an agent host via ABS'
rototiller_task :abs_provision_host_agent do
host_to_provision = get_host_to_provision("agent", "c5.large", "40")
abs_resource_hosts = get_abs_resource_hosts(host_to_provision)
raise 'Unable to provision hosts via ABS' unless abs_resource_hosts
end
desc 'Provision a worker host via ABS'
rototiller_task :abs_provision_host_worker do
host_to_provision = get_host_to_provision("worker", "c5.xlarge", "80")
abs_resource_hosts = get_abs_resource_hosts(host_to_provision)
raise 'Unable to provision hosts via ABS' unless abs_resource_hosts
end
namespace :test do
begin
# this will produce the 'test:spec' task
require "rspec/core/rake_task"
desc "Run unit tests"
RSpec::Core::RakeTask.new do |t|
t.rspec_opts = ["--color"]
t.pattern = 'spec/**/*_spec.rb'
end
# if rspec isn't available, we can still use this Rakefile
# rubocop:disable Lint/HandleExceptions
rescue LoadError
end
end
namespace :lint do
RuboCop::RakeTask.new
end
namespace :pr do
desc "Run the lint and test tasks for pull requests"
task :check do
puts "Running GPLT PR checks"
tasks = ["lint:rubocop", "test:spec"]
failed_tasks = []
tasks.each do |task_name|
puts "#{task_name}"
begin
Rake::Task[task_name].execute
rescue SystemExit => e
puts "rescued #{e}"
failed_tasks << task_name
end
end
unless failed_tasks.empty?
puts "\nERROR: The following PR tasks failed: #{failed_tasks.join(", ")}\n\n"
raise
end
end
end
desc 'Clean up artifacts created by performance runs'
task :clean do
rm_rf "simulation-runner/cache"
rm_rf "simulation-runner/config/tmp"
rm_rf "gatling-recorder.log"
rm_rf "cache"
rm_rf "log"
rm_rf "junit"
rm_rf "last_abs_resource_hosts.log"
rm_rf "log"
rm_rf Dir.glob('results/perf/PERF_*').grep(/PERF_[0-9]+.*$/)
rm_rf Dir.glob('results/scale/PERF_SCALE_*')
rm_rf "simulation-runner/target"
rm_rf "tmp"
rm_rf Dir.glob('*.tgz')
end
namespace :git do
namespace :submodules do
desc "Initialize git submodules"
task :init do
system "git submodule init"
system "git submodule update"
end
end
end
namespace :pe_xl do
# Set location for artifacts
BUILD_DIR = File.join(File.expand_path(File.dirname(__FILE__)), "build", "pe_xl")
desc "Delete pe_xl local file artifacts"
task :clean do
puts "Removing pe_xl file artifacts"
rm_rf BUILD_DIR
end
desc "Delete pe_xl_plan_result"
task :clean_plan_result do
puts "Removing pe_xl_plan_result file"
rm "#{BUILD_DIR}/pe_xl_plan_result"
end
file "#{BUILD_DIR}/params.json" do
puts "Provisioning nodes for pe_xl"
raise KeyError, 'key not found: "BEAKER_PE_VER"' unless ENV["BEAKER_PE_VER"].is_a? String
# validate that BEAKER_PE_VER looks like a PE version
pe_pattern = /(^\d{4}\.\d+)\.(\d+)(.*$)/i
err_msg = "BEAKER_PE_VER: #{ENV['BEAKER_PE_VER']} does not match the pattern '#{pe_pattern}'"
match_data = ENV["BEAKER_PE_VER"].match(pe_pattern)
raise err_msg unless match_data
pe_dir = if !match_data[3]&.empty?
"https://artifactory.delivery.puppetlabs.net/artifactory/generic_enterprise__local/#{match_data[1]}/ci-ready/"
else
"https://artifactory.delivery.puppetlabs.net/artifactory/generic_enterprise__local/archives/releases/#{match_data[1]}.#{match_data[2]}/"
end
mkdir_p BUILD_DIR
system "bundle exec ruby util/abs/provision_pe_xl_nodes.rb --output_dir #{BUILD_DIR} --pe_version #{ENV['BEAKER_PE_VER']}"
puts "Retrieving PE package"
cfg_hash = Beaker::Options::HostsFileParser.parse_hosts_file "#{BUILD_DIR}/beaker.cfg"
master = master_from_beaker_hosts_hash(cfg_hash[:HOSTS])
bkr = BeakerDSL.new
fetch_pe_for_master(bkr, master, ENV["BEAKER_PE_VER"], pe_dir)
end
desc "Provision pe_xl nodes"
task :provision => "#{BUILD_DIR}/params.json" do
end
file "#{BUILD_DIR}/pe_xl_plan_result" do
puts "Running bolt plan"
cmd = %W[
bolt plan run pe_xl
--debug
--inventory #{BUILD_DIR}/nodes.yaml
--params @#{BUILD_DIR}/params.json
].join(" ")
res = system cmd
res_str = "#{$?.to_i}\n#{res}\n"
File.write("#{BUILD_DIR}/pe_xl_plan_result", res_str)
raise "Plan for pe_xl failed: #{res_str}" if $?.to_i != 0
end
desc "Run pe_xl plan"
task :run_plan => ["git:submodules:init", :provision, "#{BUILD_DIR}/pe_xl_plan_result"] do
end
desc "Re-run pe_xl plan"
task :rerun_plan => [:clean_plan_result, "#{BUILD_DIR}/pe_xl_plan_result"] do
end
desc "Deploy pe_xl arch"
task :deploy => [:clean, :provision, :run_plan] do
puts "Deploying a pe_xl architecture"
end
end
namespace :validate do
desc "Validate the environment variables for the 'performance' rake tasks"
task :performance_env_vars do
Rake::Task["validate:baseline_pe_version"].invoke if ENV["BASELINE_PE_VER"]
end
desc "Verifies that the BEAKER_INSTALL_TYPE environment variable and dependencies have been specified"
task :beaker_install_type do
# TODO: extract to a helper and spec test
# TODO: validate the specified values
raise "The BEAKER_INSTALL_TYPE env var must be set to either 'pe' or 'foss' to continue" unless
ENV['BEAKER_INSTALL_TYPE'] == 'pe' || ENV['BEAKER_INSTALL_TYPE'] == 'foss'
if ENV['BEAKER_INSTALL_TYPE'] == 'pe'
raise "The BEAKER_PE_VER and BEAKER_PE_DIR environment variables must be specified when BEAKER_INSTALL_TYPE == 'pe'" if
ENV['BEAKER_PE_VER'].nil? || ENV['BEAKER_PE_DIR'].nil?
else
raise "The PACKAGE_BUILD_VERSION and PUPPET_AGENT_VERSION environment variables must be specified when BEAKER_INSTALL_TYPE == 'foss'" if
ENV['PACKAGE_BUILD_VERSION'].nil? || ENV['PUPPET_AGENT_VERSION'].nil?
end
end
desc "Verify that the specified baseline PE version exists in BigQuery"
task :baseline_pe_version do
# if BASELINE_PE_VER is specified verify that it exists before proceeding
verify_baseline_pe_version ENV["BASELINE_PE_VER"]
end
end
namespace :bigquery do
desc "List the baseline PE versions in BigQuery"
task :list_baseline_pe_versions do
versions = baseline_pe_versions
puts "Baseline versions:"
puts versions
end
end