1 require 'rubygems' |
1 require 'rubygems' |
2 require 'puppetlabs_spec_helper/rake_tasks' |
2 require 'puppetlabs_spec_helper/rake_tasks' |
|
3 require 'net/http' |
|
4 require 'uri' |
|
5 require 'fileutils' |
|
6 require 'rspec/core/rake_task' |
|
7 require 'puppet-doc-lint/rake_task' |
|
8 |
|
9 module TempFixForRakeLastComment |
|
10 def last_comment |
|
11 last_description |
|
12 end |
|
13 end |
|
14 Rake::Application.send :include, TempFixForRakeLastComment |
3 |
15 |
4 exclude_paths = [ |
16 exclude_paths = [ |
5 "pkg/**/*", |
17 'pkg/**/*', |
6 "vendor/**/*", |
18 'vendor/**/*', |
7 "spec/**/*", |
19 'spec/**/*' |
8 ] |
20 ] |
9 |
|
10 require 'puppet-doc-lint/rake_task' |
|
11 PuppetDocLint.configuration.ignore_paths = exclude_paths |
|
12 |
21 |
13 require 'puppet-lint/tasks/puppet-lint' |
22 require 'puppet-lint/tasks/puppet-lint' |
14 require 'puppet-syntax/tasks/puppet-syntax' |
23 require 'puppet-syntax/tasks/puppet-syntax' |
15 |
24 |
16 PuppetSyntax.exclude_paths = exclude_paths |
25 PuppetSyntax.exclude_paths = exclude_paths |
17 PuppetSyntax.future_parser = true if ENV['FUTURE_PARSER'] == 'true' |
26 PuppetSyntax.future_parser = true if ENV['FUTURE_PARSER'] == 'true' |
18 |
27 |
19 disable_checks = [ |
28 [ |
20 '80chars', |
29 '80chars', |
21 'class_inherits_from_params_class', |
30 'class_inherits_from_params_class', |
22 'class_parameter_defaults', |
31 'class_parameter_defaults', |
23 'documentation', |
32 'documentation', |
24 'single_quote_string_with_variables' |
33 'single_quote_string_with_variables' |
25 ].each { |check| PuppetLint.configuration.send("disable_#{check}") } |
34 ].each do |check| |
|
35 PuppetLint.configuration.send("disable_#{check}") |
|
36 end |
26 |
37 |
27 PuppetLint.configuration.ignore_paths = exclude_paths |
38 PuppetLint.configuration.ignore_paths = exclude_paths |
28 PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}" |
39 PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}" |
|
40 |
|
41 desc 'Run documentation tests' |
|
42 task :spec_docs do |
|
43 results = PuppetDocLint::Runner.new.run( |
|
44 FileList['**/*.pp'].exclude(*exclude_paths) |
|
45 ) |
|
46 |
|
47 results.each { |result| result.result_report } |
|
48 if results.map(&:percent_documented).any?{|n| n < 100} |
|
49 abort 'Issues found!' |
|
50 end |
|
51 end |
|
52 |
|
53 RSpec::Core::RakeTask.new(:spec_verbose) do |t| |
|
54 t.pattern = 'spec/{classes,defines,unit,functions,templates}/**/*_spec.rb' |
|
55 t.rspec_opts = [ |
|
56 '--format documentation', |
|
57 '--require "ci/reporter/rspec"', |
|
58 '--format CI::Reporter::RSpecFormatter', |
|
59 '--color' |
|
60 ] |
|
61 end |
|
62 task :spec_verbose => :spec_prep |
|
63 |
|
64 RSpec::Core::RakeTask.new(:spec_unit) do |t| |
|
65 t.pattern = 'spec/{classes,defines,unit,functions,templates}/**/*_spec.rb' |
|
66 t.rspec_opts = ['--color'] |
|
67 end |
|
68 task :spec_unit => :spec_prep |
|
69 |
|
70 task :beaker => [:spec_prep, 'artifacts:prep'] |
|
71 |
|
72 desc 'Run integration tests' |
|
73 RSpec::Core::RakeTask.new('beaker:integration') do |c| |
|
74 c.pattern = 'spec/integration/integration*.rb' |
|
75 end |
|
76 task 'beaker:integration' => [:spec_prep, 'artifacts:prep'] |
|
77 |
|
78 desc 'Run acceptance tests' |
|
79 RSpec::Core::RakeTask.new('beaker:acceptance') do |c| |
|
80 c.pattern = 'spec/acceptance/0*_spec.rb' |
|
81 end |
|
82 task 'beaker:acceptance' => [:spec_prep, 'artifacts:prep'] |
|
83 |
|
84 |
|
85 if not ENV['BEAKER_IS_PE'].nil? and ENV['BEAKER_IS_PE'] == 'true' |
|
86 task :beaker => 'artifacts:pe' |
|
87 task 'beaker:integration' => 'artifacts:pe' |
|
88 task 'beaker:acceptance' => 'artifacts:pe' |
|
89 end |
|
90 |
|
91 |
|
92 namespace :artifacts do |
|
93 desc "Fetch artifacts for tests" |
|
94 task :prep do |
|
95 fetch_archives({ |
|
96 'https://github.com/lmenezes/elasticsearch-kopf/archive/v2.1.1.zip' => 'elasticsearch-kopf.zip', |
|
97 'https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.3.1.deb' => 'elasticsearch-1.3.1.deb', |
|
98 'https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.1.0.deb' => 'elasticsearch-1.1.0.deb', |
|
99 'https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.3.1.noarch.rpm' => 'elasticsearch-1.3.1.noarch.rpm', |
|
100 'https://github.com/lukas-vlcek/bigdesk/zipball/v2.4.0' => 'elasticsearch-bigdesk.zip', |
|
101 }) |
|
102 end |
|
103 |
|
104 desc "Retrieve PE archives" |
|
105 task :pe do |
|
106 if not ENV['BEAKER_set'].nil? |
|
107 case ENV['BEAKER_set'] |
|
108 when /centos-(\d)/ |
|
109 distro = 'el' |
|
110 version = $1 |
|
111 arch = "x86_64" |
|
112 when /(debian)-(\d)/ |
|
113 distro = $1 |
|
114 version = $2 |
|
115 arch = "amd64" |
|
116 when /(sles)-(\d+)/ |
|
117 distro = $1 |
|
118 version = $2 |
|
119 arch = "x86_64" |
|
120 when /(ubuntu)-server-(12|14)/ |
|
121 distro = $1 |
|
122 version = "#{$2}.04" |
|
123 arch = "amd64" |
|
124 else |
|
125 puts "Could not find PE version for #{ENV['BEAKER_set']}" |
|
126 return |
|
127 end |
|
128 pe_version = ENV['BEAKER_PE_VER'] |
|
129 file = "puppet-enterprise-#{pe_version}-#{distro}-#{version}-#{arch}.tar.gz" |
|
130 fetch_archives({ |
|
131 "https://s3.amazonaws.com/pe-builds/released/#{pe_version}/#{file}" => file |
|
132 }) |
|
133 else |
|
134 puts "No nodeset set, skipping PE artifact retrieval" |
|
135 end |
|
136 end |
|
137 |
|
138 desc "Purge fetched artifacts" |
|
139 task :clean do |
|
140 FileUtils.rm_rf(Dir.glob('spec/fixtures/artifacts/*')) |
|
141 end |
|
142 end |
|
143 |
|
144 def fetch_archives archives |
|
145 archives.each do |url, fp| |
|
146 fp.replace "spec/fixtures/artifacts/#{fp}" |
|
147 if File.exists? fp |
|
148 if fp.end_with? 'tar.gz' and \ |
|
149 not system("tar -tzf #{fp} &>/dev/null") |
|
150 puts "Archive #{fp} corrupt, re-fetching..." |
|
151 File.delete fp |
|
152 else |
|
153 puts "Already retrieved intact archive #{fp}..." |
|
154 next |
|
155 end |
|
156 end |
|
157 get url, fp |
|
158 end |
|
159 end |
|
160 |
|
161 def get url, file_path |
|
162 puts "Fetching #{url}..." |
|
163 found = false |
|
164 until found |
|
165 uri = URI::parse(url) |
|
166 conn = Net::HTTP.new(uri.host, uri.port) |
|
167 conn.use_ssl = true |
|
168 res = conn.get(uri.path) |
|
169 if res.header['location'] |
|
170 url = res.header['location'] |
|
171 else |
|
172 found = true |
|
173 end |
|
174 end |
|
175 File.open(file_path, 'w+') { |fh| fh.write res.body } |
|
176 end |