This repository was archived by the owner on Mar 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRakefile
More file actions
162 lines (139 loc) · 4.56 KB
/
Rakefile
File metadata and controls
162 lines (139 loc) · 4.56 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
#
# Rake tasks to test your Puppet module
#
# Written by Mathias Lafeldt <mathias.lafeldt@gmail.com>
#
# Copyright (C) 2013-2014 Jimdo GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'rake/clean'
require 'rspec/core/rake_task'
# Get module name from directory name; strip "puppet-" prefix.
def module_name
File.basename(File.dirname(__FILE__)).sub(/^puppet-/, '')
end
MODULE_NAME = ENV.fetch('MODULE_NAME', module_name)
FIXTURES_PATH = ENV.fetch('FIXTURES_PATH', 'fixtures')
MODULES_PATH = File.join(FIXTURES_PATH, 'modules')
MANIFESTS_PATH = File.join(FIXTURES_PATH, 'manifests')
MANIFEST_NAME = 'site.pp'
CLOBBER.include FIXTURES_PATH, '.librarian', '.tmp', '.vagrant'
desc 'Display information about the environment'
task :env do
{
:ruby => 'ruby --version',
:rubygems => 'gem --version',
:bundler => 'bundle --version',
:vagrant => 'vagrant --version',
:virtualbox => 'VBoxManage --version'
}.each do |key, cmd|
begin
result = `#{cmd}`.chomp
rescue Errno::ENOENT
result = 'not found'
end
puts " - #{key}: #{result}"
end
end
namespace :test do
# Prepare module and its dependencies as specified in Puppetfile.
task :prepare_modules do
if File.file?('Puppetfile')
sh 'librarian-puppet', 'install', '--path', MODULES_PATH, '--destructive'
else
rm_rf MODULES_PATH
mkdir_p MODULES_PATH
end
module_dir = File.join(MODULES_PATH, module_name)
mkdir_p module_dir
cp_r Dir.glob('{files,lib,manifests,templates}'), module_dir
end
# Prepare manifest as entry point for integration testing.
task :prepare_manifests do
rm_rf MANIFESTS_PATH
mkdir_p MANIFESTS_PATH
cp File.join('test', 'integration', MANIFEST_NAME), MANIFESTS_PATH
end
# Prepare empty site.pp for rspec-puppet.
task :prepare_manifests_for_rspec do
manifest_dir = MANIFESTS_PATH + '-rspec'
rm_rf manifest_dir
mkdir_p manifest_dir
touch File.join(manifest_dir, MANIFEST_NAME)
end
# Remove fixtures.
task :cleanup do
rm_rf FIXTURES_PATH
end
desc 'Check manifests with puppet-lint'
task :lint do
require 'puppet-lint/tasks/puppet-lint'
PuppetLint.configuration.ignore_paths = [
FIXTURES_PATH + '/**/*',
'vendor/**/*'
]
end
desc 'Run RSpec examples'
RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = 'spec/{classes,defines,unit,functions,hosts}/**/*_spec.rb'
t.rspec_opts = '--color --format documentation'
end
task :spec => [:prepare_modules, :prepare_manifests_for_rspec]
desc 'Run serverspec integration tests with Vagrant'
RSpec::Core::RakeTask.new(:integration) do |t|
t.pattern = 'spec/integration/**/*_spec.rb'
t.rspec_opts = '--color --format documentation'
end
task :integration => 'vagrant:provision'
desc 'Tear down VM used for integration tests'
task :integration_teardown do
# Shut VM down unless INTEGRATION_TEARDOWN is set to a different task.
Rake::Task[ENV.fetch('INTEGRATION_TEARDOWN', 'vagrant:halt')].invoke
end
desc 'Run test:lint and test:spec'
task :travis => [:lint, :spec]
desc 'Run test:lint, test:spec, and test:integration'
task :all => [:lint, :spec, :integration, :integration_teardown]
end
namespace :vagrant do
# Export settings to Vagrantfile.
task :export_vars do
ENV['MODULES_PATH'] = MODULES_PATH
ENV['MANIFESTS_PATH'] = MANIFESTS_PATH
ENV['MANIFEST_FILE'] = MANIFEST_NAME # relative to MANIFESTS_PATH
end
desc 'Provision the VM using Puppet'
task :provision => ['test:prepare_modules', 'test:prepare_manifests', :export_vars] do
sh 'vagrant', 'up', '--no-provision'
sh 'vagrant', 'provision'
end
desc 'SSH into the VM'
task :ssh do
sh 'vagrant', 'ssh'
end
desc 'Shutdown the VM'
task :halt do
sh 'vagrant', 'halt', '--force'
end
desc 'Destroy the VM'
task :destroy => :export_vars do
sh 'vagrant', 'destroy', '--force'
Rake::Task['test:cleanup'].invoke
end
end
# Aliases for backwards compatibility and convenience
task :lint => 'test:lint'
task :spec => 'test:spec'
task :test => 'test:all'
task :default => :test