forked from puppetlabs/puppetlabs-puppet_agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
65 lines (55 loc) · 1.82 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
def beaker(command)
debug_flag = ''
if ENV['BEAKER_debug'] || ENV['DEBUG']
debug_flag = '--debug'
end
sh(%(beaker #{command} #{debug_flag}))
end
desc 'Prepare for running tests: Run beaker init, provision, and pre-suite all at once.'
task :prepare do
errors = []
if !ENV['MASTER_PACKAGE_VERSION'] && !ENV['MASTER_COLLECTION']
errors << 'You must set a starting version of puppet-agent using ' +
'$MASTER_PACKAGE_VERSION or $MASTER_COLLECTION'
end
if ENV['HOSTS']
hosts_file = File.expand_path(ENV['HOSTS'])
errors << "Couldn't find $HOSTS file at #{hosts_file}" unless File.exist?(hosts_file)
elsif File.exist?('hosts.yml')
hosts_file = './hosts.yml'
elsif File.exist?('hosts.yaml')
hosts_file = './hosts.yaml'
else
errors << 'Unable to find a hosts file in $HOSTS or at ./hosts.yml or at ./hosts.yaml'
end
unless errors.empty?
raise errors.join("\n")
end
puts "Using beaker hosts file #{hosts_file}"
# Log the contents of the host file if running in Jenkins
if ENV['JENKINS_HOME']
pp File.read(hosts_file)
end
beaker("init -h #{hosts_file} -o options.rb")
beaker("provision")
beaker("exec ./pre_suite")
# Don't print these human instructions if running in Jenkins
unless ENV['JENKINS_HOME']
puts 'You can run individual test(s) with `bundle exec beaker exec <path-to-test(s)>`'
puts "You can destroy your provisioned hosts with `bundle exec beaker destroy` when you're ready"
end
end
desc 'Run all the tests and destroy the hosts afterward'
task :ci do
begin
Rake.application['prepare'].invoke
case ENV['MASTER_COLLECTION']
when /puppet7/
beaker('exec ./tests/test_upgrade_puppet6_to_puppet7.rb')
when /puppet8/
beaker('exec ./tests/test_upgrade_puppet7_to_puppet8.rb')
end
ensure
beaker('destroy')
end
end