forked from puppetlabs/puppetserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
158 lines (136 loc) · 5.41 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
PROJECT_ROOT = File.dirname(__FILE__)
ACCEPTANCE_ROOT = ENV['ACCEPTANCE_ROOT'] ||
File.join(PROJECT_ROOT, 'acceptance')
PUPPET_SRC = File.join(PROJECT_ROOT, 'ruby', 'puppet')
PUPPET_LIB = File.join(PROJECT_ROOT, 'ruby', 'puppet', 'lib')
PUPPET_SPEC = File.join(PROJECT_ROOT, 'ruby', 'puppet', 'spec')
FACTER_LIB = File.join(PROJECT_ROOT, 'ruby', 'facter', 'lib')
PUPPET_SERVER_RUBY_SRC = File.join(PROJECT_ROOT, 'src', 'ruby', 'puppetserver-lib')
TEST_GEMS_DIR = File.join(PROJECT_ROOT, 'vendor', 'test_gems')
TEST_BUNDLE_DIR = File.join(PROJECT_ROOT, 'vendor', 'test_bundle')
RAKE_ROOT = File.expand_path(File.dirname(__FILE__))
def assemble_default_beaker_config
if ENV["BEAKER_CONFIG"]
return ENV["BEAKER_CONFIG"]
end
platform = ENV['PLATFORM']
layout = ENV['LAYOUT']
if platform and layout
beaker_config = "#{ACCEPTANCE_ROOT}/config/beaker/jenkins/"
beaker_config += "#{platform}-#{layout}.cfg"
else
abort "Must specify an appropriate value for BEAKER_CONFIG. See acceptance/README.md"
end
return beaker_config
end
namespace :spec do
task :init do
if ! Dir.exists? TEST_GEMS_DIR
## Install bundler
## Line 1 launches the JRuby that we depend on via leiningen
## Line 2 programmatically runs 'gem install bundler' via the gem command that comes with JRuby
gem_install_bundler = <<-CMD
lein run -m org.jruby.Main \
-e 'load "META-INF/jruby.home/bin/gem"' install -i '#{TEST_GEMS_DIR}' --no-rdoc --no-ri bundler
CMD
sh gem_install_bundler
path = ENV['PATH']
## Install gems via bundler
## Line 1 makes sure that our local bundler script is on the path first
## Line 2 tells bundler to use puppet's Gemfile
## Line 3 tells JRuby where to look for gems
## Line 4 launches the JRuby that we depend on via leiningen
## Line 5 runs our bundle install script
bundle_install = <<-CMD
PATH='#{TEST_GEMS_DIR}/bin:#{path}' \
BUNDLE_GEMFILE='#{PUPPET_SRC}/Gemfile' \
GEM_HOME='#{TEST_GEMS_DIR}' GEM_PATH='#{TEST_GEMS_DIR}' \
lein run -m org.jruby.Main \
-S bundle install --path='#{TEST_BUNDLE_DIR}'
CMD
sh bundle_install
end
end
end
desc "Run rspec tests"
task :spec => ["spec:init"] do
## Run RSpec via our JRuby dependency
## Line 1 tells bundler to use puppet's Gemfile
## Line 2 tells JRuby where to look for gems
## Line 3 launches the JRuby that we depend on via leiningen
## Line 4 adds all our Ruby source to the JRuby LOAD_PATH
## Line 5 runs our rspec wrapper script
## <sarcasm-font>dang ole real easy man</sarcasm-font>
run_rspec_with_jruby = <<-CMD
BUNDLE_GEMFILE='#{PUPPET_SRC}/Gemfile' \
GEM_HOME='#{TEST_GEMS_DIR}' GEM_PATH='#{TEST_GEMS_DIR}' \
lein run -m org.jruby.Main \
-I'#{PUPPET_LIB}' -I'#{PUPPET_SPEC}' -I'#{FACTER_LIB}' -I'#{PUPPET_SERVER_RUBY_SRC}' \
./spec/run_specs.rb
CMD
sh run_rspec_with_jruby
end
namespace :test do
namespace :acceptance do
desc "Run beaker based acceptance tests"
task :beaker do |t, args|
# variables that take a limited set of acceptable strings
type = ENV["BEAKER_TYPE"] || "pe"
# variables that take pathnames
beakeropts = ENV["BEAKER_OPTS"] || ""
presuite = ENV["BEAKER_PRESUITE"] || "#{ACCEPTANCE_ROOT}/suites/pre_suite/#{type}"
postsuite = ENV["BEAKER_POSTSUITE"] || ""
helper = ENV["BEAKER_HELPER"] || "#{ACCEPTANCE_ROOT}/lib/helper.rb"
testsuite = ENV["BEAKER_TESTSUITE"] || "#{ACCEPTANCE_ROOT}/suites/tests"
loadpath = ENV["BEAKER_LOADPATH"] || ""
options = ENV["BEAKER_OPTIONSFILE"] || "#{ACCEPTANCE_ROOT}/config/beaker/options.rb"
# variables requiring some assembly
config = assemble_default_beaker_config
beaker = "beaker "
beaker += " -c #{config}"
beaker += " --helper #{helper}"
beaker += " --type #{type}"
beaker += " --options-file #{options}" if options != ''
beaker += " --load-path #{loadpath}" if loadpath != ''
beaker += " --pre-suite #{presuite}" if presuite != ''
beaker += " --post-suite #{postsuite}" if postsuite != ''
beaker += " --tests " + testsuite if testsuite != ''
beaker += " " + beakeropts
sh beaker
end
end
end
build_defs_file = File.join(RAKE_ROOT, 'ext', 'build_defaults.yaml')
if File.exist?(build_defs_file)
begin
require 'yaml'
@build_defaults ||= YAML.load_file(build_defs_file)
rescue Exception => e
STDERR.puts "Unable to load yaml from #{build_defs_file}:"
raise e
end
@packaging_url = @build_defaults['packaging_url']
@packaging_repo = @build_defaults['packaging_repo']
raise "Could not find packaging url in #{build_defs_file}" if @packaging_url.nil?
raise "Could not find packaging repo in #{build_defs_file}" if @packaging_repo.nil?
namespace :package do
desc "Bootstrap packaging automation, e.g. clone into packaging repo"
task :bootstrap do
if File.exist?(File.join(RAKE_ROOT, "ext", @packaging_repo))
puts "It looks like you already have ext/#{@packaging_repo}. If you don't like it, blow it away with package:implode."
else
cd File.join(RAKE_ROOT, 'ext') do
%x{git clone #{@packaging_url}}
end
end
end
desc "Remove all cloned packaging automation"
task :implode do
rm_rf File.join(RAKE_ROOT, "ext", @packaging_repo)
end
end
end
begin
load File.join(RAKE_ROOT, 'ext', 'packaging', 'packaging.rake')
rescue LoadError
end