falkorlib 0.3.12 → 0.3.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/falkorlib/common.rb +62 -18
- data/lib/falkorlib/git/base.rb +6 -5
- data/lib/falkorlib/puppet/modules.rb +153 -76
- data/lib/falkorlib/tasks/puppet_modules.rake +59 -4
- data/lib/falkorlib/version.rb +1 -1
- data/spec/falkorlib/puppet_modules_spec.rb +57 -13
- data/templates/puppet/modules/Gemfile +2 -1
- data/templates/puppet/modules/doc/contributing.md.erb +8 -8
- data/templates/puppet/modules/tests/params.pp.erb +9 -23
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6d8cec0c3c632500898407975a5973f60f0e7fb
|
4
|
+
data.tar.gz: 7f4f4f44b51d0a166417f47b4de3b8fd560a5551
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b55f144b558fb083f70135c8e4234eae31e7205b4a32f629a2f7a93195f42288acafe1a02d052a5335269a48bde62ec3c6c309a85d077f0b9e00aa23922c5238
|
7
|
+
data.tar.gz: 4b059fa396dff399cdef5d1606fdfc12a5a19f5a636c824f456b6d6c7174c0497283213b319ace08aecefe7333c9c474bd0aeebd230d234f1345d2d02ce14604
|
data/Gemfile.lock
CHANGED
data/lib/falkorlib/common.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
################################################################################
|
3
|
-
# Time-stamp: <Ven 2014-
|
3
|
+
# Time-stamp: <Ven 2014-12-05 15:41 svarrette>
|
4
4
|
################################################################################
|
5
5
|
|
6
6
|
require "falkorlib"
|
7
7
|
require 'open3'
|
8
8
|
require 'erb' # required for module generation
|
9
9
|
require 'diffy'
|
10
|
+
require 'json'
|
10
11
|
|
11
12
|
module FalkorLib #:nodoc:
|
12
13
|
|
@@ -305,7 +306,8 @@ module FalkorLib #:nodoc:
|
|
305
306
|
end
|
306
307
|
end
|
307
308
|
|
308
|
-
|
309
|
+
###
|
310
|
+
# ERB generation of the file `outfile` using the source template file `erbfile`
|
309
311
|
# Supported options:
|
310
312
|
# :no_interaction [boolean]: do not interact
|
311
313
|
def write_from_erb_template(erbfile, outfile, config = {},
|
@@ -316,28 +318,70 @@ module FalkorLib #:nodoc:
|
|
316
318
|
template = File.read("#{erbfile}")
|
317
319
|
output = ERB.new(template, nil, '<>')
|
318
320
|
content = output.result(binding)
|
319
|
-
|
320
|
-
|
321
|
-
return if ref == content
|
322
|
-
warn "the file '#{outfile}' already exists and will be overwritten."
|
323
|
-
warn "Expected difference: \n------"
|
324
|
-
Diffy::Diff.default_format = :color
|
325
|
-
puts Diffy::Diff.new(ref, content, :context => 1)
|
326
|
-
else
|
327
|
-
|
328
|
-
watch = options[:no_interaction] ? 'no' : ask( cyan(" ==> Do you want to see the generated file before commiting the writing (y|N)"), 'No')
|
329
|
-
puts content if watch =~ /y.*/i
|
321
|
+
show_diff_and_write(content, outfile, options)
|
322
|
+
end
|
330
323
|
|
331
|
-
|
332
|
-
|
333
|
-
|
324
|
+
## Show the difference between a `content` string and an destination file (using Diff algorithm).
|
325
|
+
# Obviosuly, if the outfile does not exists, no difference is proposed.
|
326
|
+
# Supported options:
|
327
|
+
# :no_interaction [boolean]: do not interact
|
328
|
+
# :json_pretty_format [boolean]: write a json content, in pretty format
|
329
|
+
#
|
330
|
+
# return 0 if nothing happened, 1 if a write has been done
|
331
|
+
def show_diff_and_write(content, outfile, options = {
|
332
|
+
:no_interaction => false,
|
333
|
+
:json_pretty_format => false,
|
334
|
+
})
|
335
|
+
if File.exists?( outfile )
|
336
|
+
ref = File.read( outfile )
|
337
|
+
if options[:json_pretty_format]
|
338
|
+
ref = JSON.pretty_generate (JSON.parse( IO.read( outfile ) ))
|
339
|
+
end
|
340
|
+
if ref == content
|
341
|
+
warn "Nothing to update"
|
342
|
+
return 0
|
343
|
+
end
|
344
|
+
warn "the file '#{outfile}' already exists and will be overwritten."
|
345
|
+
warn "Expected difference: \n------"
|
346
|
+
Diffy::Diff.default_format = :color
|
347
|
+
puts Diffy::Diff.new(ref, content, :context => 1)
|
348
|
+
else
|
349
|
+
watch = options[:no_interaction] ? 'no' : ask( cyan(" ==> Do you want to see the generated file before commiting the writing (y|N)"), 'No')
|
350
|
+
puts content if watch =~ /y.*/i
|
351
|
+
end
|
352
|
+
proceed = options[:no_interaction] ? 'yes' : ask( cyan(" ==> proceed with the writing (Y|n)"), 'Yes')
|
353
|
+
return 0 if proceed =~ /n.*/i
|
334
354
|
info("=> writing #{outfile}")
|
335
355
|
File.open("#{outfile}", "w+") do |f|
|
336
|
-
|
356
|
+
f.write content
|
337
357
|
end
|
338
|
-
|
358
|
+
if FalkorLib::Git.init?(File.dirname(outfile))
|
359
|
+
do_commit = options[:no_interaction] ? 'yes' : ask( cyan(" ==> commit the changes (Y|n)"), 'Yes')
|
360
|
+
FalkorLib::Git.add(outfile, "update content of '#{File.basename(outfile)}'") if do_commit =~ /y.*/i
|
361
|
+
end
|
362
|
+
return 1
|
363
|
+
end
|
339
364
|
|
340
365
|
|
366
|
+
## Blind copy of a source file `src` into its destination directory `dstdir`
|
367
|
+
# Supported options:
|
368
|
+
# :no_interaction [boolean]: do not interact
|
369
|
+
# :srcdir [string]: source directory, make the `src` file relative to that directory
|
370
|
+
# :outfile [string]: alter the outfile name (File.basename(src) by default)
|
371
|
+
def write_from_template(src,dstdir,options = {
|
372
|
+
:no_interaction => false,
|
373
|
+
:srcdir => '',
|
374
|
+
:outfile => ''
|
375
|
+
})
|
376
|
+
srcfile = options[:srcdir].nil? ? src : File.join(options[:srcdir], src)
|
377
|
+
error "Unable to find the source file #{srcfile}" unless File.exists? ( srcfile )
|
378
|
+
error "The destination directory '#{dstdir}' do not exist" unless File.directory?( dstdir )
|
379
|
+
dstfile = options[:outfile].nil? ? File.basename(srcfile) : options[:outfile]
|
380
|
+
outfile = File.join(dstdir, dstfile)
|
381
|
+
content = File.read( srcfile )
|
382
|
+
show_diff_and_write(content, outfile, options)
|
383
|
+
end # copy_from_template
|
384
|
+
|
341
385
|
|
342
386
|
### RVM init
|
343
387
|
def init_rvm(rootdir = Dir.pwd, gemset = '')
|
data/lib/falkorlib/git/base.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
################################################################################
|
3
|
-
# Time-stamp: <
|
3
|
+
# Time-stamp: <Ven 2014-12-05 22:43 svarrette>
|
4
4
|
################################################################################
|
5
5
|
# Interface for the main Git operations
|
6
6
|
#
|
@@ -315,12 +315,12 @@ module FalkorLib #:nodoc:
|
|
315
315
|
FalkorLib.config.git[:subtrees].each do |dir,conf|
|
316
316
|
next if conf[:url].nil?
|
317
317
|
url = conf[:url]
|
318
|
-
remote = dir
|
318
|
+
remote = dir.gsub(/\//, '-')
|
319
319
|
branch = conf[:branch].nil? ? 'master' : conf[:branch]
|
320
320
|
remotes = FalkorLib::Git.remotes
|
321
321
|
unless remotes.include?( remote )
|
322
322
|
info "Initialize Git remote '#{remote}' from URL '#{url}'"
|
323
|
-
exit_status = execute "git remote add -f #{
|
323
|
+
exit_status = execute "git remote add -f #{remote} #{url}"
|
324
324
|
end
|
325
325
|
unless File.directory?( File.join(git_root_dir, dir) )
|
326
326
|
info "initialize Git subtree '#{dir}'"
|
@@ -356,7 +356,7 @@ module FalkorLib #:nodoc:
|
|
356
356
|
FalkorLib.config.git[:subtrees].each do |dir,conf|
|
357
357
|
next if conf[:url].nil?
|
358
358
|
url = conf[:url]
|
359
|
-
remote = dir
|
359
|
+
remote = dir.gsub(/\//, '-')
|
360
360
|
branch = conf[:branch].nil? ? 'master' : conf[:branch]
|
361
361
|
remotes = FalkorLib::Git.remotes
|
362
362
|
raise IOError, "The git remote '#{remote}' is not configured" unless remotes.include?( remote )
|
@@ -377,7 +377,7 @@ module FalkorLib #:nodoc:
|
|
377
377
|
FalkorLib.config.git[:subtrees].each do |dir,conf|
|
378
378
|
next if conf[:url].nil?
|
379
379
|
url = conf[:url]
|
380
|
-
remote = dir
|
380
|
+
remote = dir.gsub(/\//, '-')
|
381
381
|
branch = conf[:branch].nil? ? 'master' : conf[:branch]
|
382
382
|
remotes = FalkorLib::Git.remotes
|
383
383
|
info "Pulling changes into subtree '#{dir}' using remote '#{remote}/#{branch}'"
|
@@ -387,6 +387,7 @@ module FalkorLib #:nodoc:
|
|
387
387
|
raise IOError, "The git subtree directory '#{dir}' does not exists" unless File.directory? ( File.join(git_root_dir, dir) )
|
388
388
|
info "\t\\__ pulling changes"
|
389
389
|
exit_status = execute "git subtree pull --prefix #{dir} --squash #{remote} #{branch}"
|
390
|
+
#exit_status = puts "git subtree pull --prefix #{dir} --squash #{remote} #{branch}"
|
390
391
|
end
|
391
392
|
end
|
392
393
|
exit_status
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
################################################################################
|
3
|
-
# Time-stamp: <
|
3
|
+
# Time-stamp: <Lun 2014-09-08 16:41 svarrette>
|
4
4
|
################################################################################
|
5
5
|
# Interface for the main Puppet Module operations
|
6
6
|
#
|
@@ -30,7 +30,7 @@ module FalkorLib #:nodoc:
|
|
30
30
|
:source => '',
|
31
31
|
:project_page => '',
|
32
32
|
:issues_url => '',
|
33
|
-
|
33
|
+
:forge_url => 'https://forge.puppetlabs.com',
|
34
34
|
:dependencies => [],
|
35
35
|
:operatingsystem_support => [],
|
36
36
|
:tags => []
|
@@ -76,7 +76,7 @@ module FalkorLib #:nodoc:
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
result.uniq!
|
79
|
-
result
|
79
|
+
result.sort
|
80
80
|
end
|
81
81
|
|
82
82
|
|
@@ -102,7 +102,7 @@ module FalkorLib #:nodoc:
|
|
102
102
|
when :issues_url
|
103
103
|
config[:project_page].nil? ? v : "#{config[:project_page]}/issues"
|
104
104
|
when :forge_url
|
105
|
-
|
105
|
+
v + '/' + config[:name].gsub(/-/,'/')
|
106
106
|
when :description
|
107
107
|
config[:summary].nil? ? v : "#{config[:summary]}"
|
108
108
|
when :source
|
@@ -123,19 +123,20 @@ module FalkorLib #:nodoc:
|
|
123
123
|
idx.nil? ? 1 : idx + 1)
|
124
124
|
config[:license] = license.downcase unless license.empty?
|
125
125
|
puts "\t" + sprintf("%-20s", "Module License:") + config[:license]
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
126
|
+
|
127
|
+
# Supported platforms
|
128
|
+
config[:platforms] = [ 'debian' ]
|
129
|
+
config[:dependencies] = [{
|
130
|
+
"name" => "puppetlabs-stdlib",
|
131
|
+
"version_range" => ">= 1.0.0"
|
132
|
+
}]
|
133
|
+
config[:params] = ["ensure", "protocol", "port", "packagename" ]
|
133
134
|
#ap config
|
134
135
|
# Bootstrap the directory
|
135
136
|
templatedir = File.join( FalkorLib.templates, 'puppet', 'modules')
|
136
137
|
init_from_template(templatedir, moduledir, config, {
|
137
138
|
:erb_exclude => [ 'templates\/[^\/]*variables\.erb$' ],
|
138
|
-
|
139
|
+
:no_interaction => true
|
139
140
|
})
|
140
141
|
# Rename the files / element templatename
|
141
142
|
Dir["#{moduledir}/**/*"].each do |e|
|
@@ -152,22 +153,22 @@ module FalkorLib #:nodoc:
|
|
152
153
|
end
|
153
154
|
info "Initialize RVM"
|
154
155
|
init_rvm(moduledir)
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
156
|
+
unless FalkorLib::Git.init?(moduledir)
|
157
|
+
init_gitflow = command?('git-flow')
|
158
|
+
warn "Git #{init_gitflow ? '[Flow]' : ''} is not initialized in #{moduledir}."
|
159
|
+
a = ask("Proceed to git-flow initialization (Y|n)", 'Yes')
|
160
|
+
return if a =~ /n.*/i
|
161
|
+
init_gitflow ? FalkorLib::GitFlow.init(moduledir) : FalkorLib::Git.init(moduledir)
|
162
|
+
end
|
163
|
+
|
163
164
|
# Propose to commit the key files
|
164
165
|
if FalkorLib::Git.init?(moduledir)
|
165
166
|
if FalkorLib::GitFlow.init?(moduledir)
|
166
167
|
info "=> preparing git-flow feature for the newly created module '#{config[:name]}'"
|
167
168
|
FalkorLib::GitFlow.start('feature', "bootstraping", moduledir)
|
168
169
|
end
|
169
|
-
[ 'metadata.json',
|
170
|
-
'doc/', 'LICENSE', '.gitignore',
|
170
|
+
[ 'metadata.json',
|
171
|
+
'doc/', 'LICENSE', '.gitignore',
|
171
172
|
'Gemfile', '.vagrant_init.rb', 'Rakefile', 'Vagrantfile' ].each do |f|
|
172
173
|
FalkorLib::Git.add(File.join(moduledir, f))
|
173
174
|
end
|
@@ -176,15 +177,25 @@ module FalkorLib #:nodoc:
|
|
176
177
|
|
177
178
|
####
|
178
179
|
# Parse a given modules to collect information
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
180
|
+
# Supported options:
|
181
|
+
# :no_interaction [boolean]: do not interact
|
182
|
+
#
|
183
|
+
def parse(moduledir = Dir.pwd, options = {
|
184
|
+
:no_interaction => false
|
185
|
+
})
|
186
|
+
name = File.basename(moduledir)
|
187
|
+
metadata = metadata(moduledir, {
|
188
|
+
:use_symbols => false,
|
189
|
+
:extras => false
|
190
|
+
})
|
191
|
+
puts "**********************"
|
192
|
+
puts metadata.to_yaml
|
193
|
+
# error "The module #{name} does not exist" unless File.directory?( moduledir )
|
183
194
|
jsonfile = File.join( moduledir, 'metadata.json')
|
184
|
-
error "Unable to find #{jsonfile}" unless File.exist?( jsonfile )
|
185
|
-
metadata = JSON.parse( IO.read( jsonfile ) )
|
195
|
+
# error "Unable to find #{jsonfile}" unless File.exist?( jsonfile )
|
196
|
+
# metadata = JSON.parse( IO.read( jsonfile ) )
|
186
197
|
ref = JSON.pretty_generate( metadata )
|
187
|
-
|
198
|
+
metadata["classes"] = classes(moduledir)
|
188
199
|
metadata["definitions"] = definitions(moduledir)
|
189
200
|
deps = deps(moduledir)
|
190
201
|
listed_deps = metadata["dependencies"]
|
@@ -195,18 +206,16 @@ module FalkorLib #:nodoc:
|
|
195
206
|
deps.delete( lib )
|
196
207
|
else
|
197
208
|
unless lib =~ /stdlib/
|
198
|
-
warn "The library '#{dep["name"]}' is not analyzed as part of the #{
|
209
|
+
warn "The library '#{dep["name"]}' is not analyzed as part of the #{metadata['shortname']} module"
|
199
210
|
missed_deps << dep
|
200
211
|
end
|
201
212
|
end
|
202
213
|
end
|
203
214
|
if ! deps.empty?
|
204
215
|
deps.each do |l|
|
205
|
-
shortname = name.gsub(/.*-/, '')
|
206
|
-
shortmetaname = metadata["name"].gsub(/.*-/, '')
|
207
216
|
next if [name, metadata["name"], name.gsub(/.*-/, ''), metadata["name"].gsub(/.*-/, '') ].include? ( l )
|
208
217
|
warn "The module '#{l}' is missing in the dependencies thus added"
|
209
|
-
login
|
218
|
+
login = ask("[Github] login for the module '#{l}'")
|
210
219
|
version = ask("Version requirement (ex: '>=1.0.0 <2.0.0' or '1.2.3' or '1.x')")
|
211
220
|
metadata["dependencies"] << {
|
212
221
|
"name" => "#{login}/#{l}",
|
@@ -214,58 +223,126 @@ module FalkorLib #:nodoc:
|
|
214
223
|
}
|
215
224
|
end
|
216
225
|
end
|
217
|
-
|
226
|
+
content = JSON.pretty_generate( metadata )
|
218
227
|
info "Metadata configuration for the module '#{name}'"
|
219
228
|
puts content
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
info "Differences with the previous file"
|
225
|
-
Diffy::Diff.default_format = :color
|
226
|
-
puts Diffy::Diff.new(ref, content, :context => 1)
|
227
|
-
warn "About to commit these changes in the '#{name}/metadata.json' file"
|
228
|
-
really_continue?
|
229
|
-
File.open(jsonfile,"w") do |f|
|
230
|
-
f.write JSON.pretty_generate( metadata )
|
231
|
-
end
|
232
|
-
run %{ git commit -s -m "Update metadata.json" #{jsonfile} }
|
229
|
+
show_diff_and_write(content, jsonfile, {
|
230
|
+
:no_interaction => options[:no_interaction],
|
231
|
+
:json_pretty_format => true
|
232
|
+
})
|
233
233
|
metadata
|
234
234
|
end # parse
|
235
235
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
236
|
+
###
|
237
|
+
# Retrieves the metadata from the metadata.json file in `moduledir`.
|
238
|
+
# Supported options:
|
239
|
+
# :use_symbols [boolean]: convert all keys to symbols
|
240
|
+
# :extras [boolean]: add extra keys
|
241
|
+
#
|
242
|
+
def metadata(moduledir = Dir.pwd, options = {
|
243
|
+
:use_symbols => true,
|
244
|
+
:extras => true
|
245
|
+
})
|
246
|
+
add_extras = options[:extras].nil? ? true : options[:extras]
|
241
247
|
name = File.basename( moduledir )
|
242
248
|
error "The module #{name} does not exist" unless File.directory?( moduledir )
|
243
249
|
jsonfile = File.join( moduledir, 'metadata.json')
|
244
250
|
error "Unable to find #{jsonfile}" unless File.exist?( jsonfile )
|
245
251
|
metadata = JSON.parse( IO.read( jsonfile ) )
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
metadata[
|
252
|
+
if add_extras
|
253
|
+
metadata[:shortname] = name.gsub(/.*-/, '')
|
254
|
+
metadata[:platforms] = []
|
255
|
+
metadata["operatingsystem_support"].each do |e|
|
256
|
+
metadata[:platforms] << e["operatingsystem"].downcase unless e["operatingsystem"].nil?
|
257
|
+
end
|
258
|
+
# Analyse params
|
259
|
+
params_manifest = File.join(moduledir, 'manifests', 'params.pp')
|
260
|
+
if File.exist?(params_manifest)
|
261
|
+
params = []
|
262
|
+
File.read(params_manifest).scan(/^\s*\$(.*)\s*=/) do |m|
|
263
|
+
params << $1 unless $1.nil?
|
264
|
+
end
|
265
|
+
metadata[:params] = params.uniq
|
266
|
+
end
|
250
267
|
end
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
[ 'README.md', 'doc/contributing.md'].each do |f|
|
257
|
-
info "Upgrade the content of #{f}"
|
258
|
-
ans = options[:no_interaction] ? 'Yes' : ask("procceed?", 'Yes')
|
259
|
-
next unless ans =~ /n*/i
|
260
|
-
write_from_erb_template(File.join(templatedir, "#{f}.erb"),
|
261
|
-
File.join(moduledir, f),
|
262
|
-
metadata,
|
263
|
-
options)
|
268
|
+
if options[:use_symbols]
|
269
|
+
# convert string keys to symbols
|
270
|
+
metadata.keys.each do |k|
|
271
|
+
metadata[(k.to_sym rescue k) || k] = metadata.delete(k)
|
272
|
+
end
|
264
273
|
end
|
265
|
-
|
274
|
+
metadata
|
275
|
+
end # metadata
|
266
276
|
|
267
277
|
|
268
278
|
|
279
|
+
##
|
280
|
+
# Upgrade the key files (README etc.) of the puppet module hosted
|
281
|
+
# in `moduledir` with the latest version of the FalkorLib template
|
282
|
+
# Supported options:
|
283
|
+
# :no_interaction [boolean]: do not interact
|
284
|
+
# :only [Array of string]: update only the listed files
|
285
|
+
# :exclude [Array of string]: exclude from the upgrade the listed
|
286
|
+
# files
|
287
|
+
# return the number of considered files
|
288
|
+
def upgrade(moduledir = Dir.pwd,
|
289
|
+
options = {
|
290
|
+
:no_interaction => false,
|
291
|
+
:only => nil,
|
292
|
+
:exclude => []
|
293
|
+
})
|
294
|
+
metadata = metadata(moduledir)
|
295
|
+
templatedir = File.join( FalkorLib.templates, 'puppet', 'modules')
|
296
|
+
i = 0
|
297
|
+
update_from_erb = [ 'README.md', 'doc/contributing.md']
|
298
|
+
(update_from_erb + [ 'Gemfile', 'Rakefile', 'Vagrantfile', '.vagrant_init.rb' ]).each do |f|
|
299
|
+
next unless options[:exclude].nil? or ! options[:exclude].include?( f )
|
300
|
+
next unless options[:only].nil? or options[:only].include?(f)
|
301
|
+
info "Upgrade the content of #{f}"
|
302
|
+
ans = options[:no_interaction] ? 'Yes' : ask(cyan("==> procceed? (Y|n)"), 'Yes')
|
303
|
+
next if ans =~ /n.*/i
|
304
|
+
if update_from_erb.include?(f)
|
305
|
+
i += write_from_erb_template(File.join(templatedir, "#{f}.erb"),
|
306
|
+
File.join(moduledir, f),
|
307
|
+
metadata,
|
308
|
+
options)
|
309
|
+
else
|
310
|
+
i+= write_from_template(f, moduledir, {
|
311
|
+
:no_interaction => options[:no_interaction],
|
312
|
+
:srcdir => templatedir
|
313
|
+
})
|
314
|
+
end
|
315
|
+
end
|
316
|
+
i
|
317
|
+
end
|
318
|
+
|
319
|
+
##
|
320
|
+
# initializes or update the (tests/specs/etc.) sub-directory of the
|
321
|
+
# `moduledir` using the correcponding ERB files.
|
322
|
+
# Supported options:
|
323
|
+
# :no_interaction [boolean]: do not interactww
|
324
|
+
#
|
325
|
+
# returns the number of considered files
|
326
|
+
def upgrade_from_template(moduledir = Dir.pwd,
|
327
|
+
subdir = 'tests',
|
328
|
+
options = {
|
329
|
+
:no_interaction => false
|
330
|
+
})
|
331
|
+
metadata = metadata(moduledir)
|
332
|
+
#ap metadata
|
333
|
+
i = 0
|
334
|
+
templatedir = File.join( FalkorLib.templates, 'puppet', 'modules', subdir)
|
335
|
+
error "Unable to find the template directory '#{templatedir}" unless File.directory?( templatedir )
|
336
|
+
Dir["#{templatedir}/**/*.erb"].each do |erbfile|
|
337
|
+
f = File.join(subdir, File.basename(erbfile, '.erb'))
|
338
|
+
info "Upgrade the content of #{f}"
|
339
|
+
ans = options[:no_interaction] ? 'Yes' : ask(cyan("==> procceed? (Y|n)"), 'Yes')
|
340
|
+
next if ans =~ /n.*/i
|
341
|
+
i+= write_from_erb_template(erbfile, File.join(moduledir, f), metadata, options)
|
342
|
+
end
|
343
|
+
i
|
344
|
+
end
|
345
|
+
|
269
346
|
|
270
347
|
#######
|
271
348
|
# Find the classes of a given module
|
@@ -298,12 +375,12 @@ module FalkorLib #:nodoc:
|
|
298
375
|
resulttmp = result.dup
|
299
376
|
(result - result2).each do |x|
|
300
377
|
Dir["#{moduledir}/**/*.pp"].each do |ppfile|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
378
|
+
File.read(ppfile).scan(/^\s*(include|require|class\s*{)\s*["']?(::)?([0-9a-zA-Z:{$}\-]*)["']?/) do |m|
|
379
|
+
next if $3.nil?
|
380
|
+
entry = $3.split('::').first
|
381
|
+
result << entry unless entry.nil? or entry.empty?
|
382
|
+
end
|
383
|
+
end
|
307
384
|
end
|
308
385
|
result.uniq!
|
309
386
|
result2 = resulttmp.dup
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
################################################################################
|
3
3
|
# puppet_modules.rake - Special tasks for the management of Puppet modules
|
4
|
-
# Time-stamp: <
|
4
|
+
# Time-stamp: <Lun 2014-09-08 17:19 svarrette>
|
5
5
|
#
|
6
6
|
# Copyright (c) 2014 Sebastien Varrette <Sebastien.Varrette@uni.lu>
|
7
7
|
# http://varrette.gforge.uni.lu
|
8
8
|
################################################################################
|
9
9
|
|
10
|
+
require 'rake'
|
10
11
|
require 'falkorlib'
|
11
12
|
require 'falkorlib/tasks'
|
12
13
|
require 'falkorlib/puppet'
|
@@ -119,12 +120,40 @@ end # namespace puppet
|
|
119
120
|
|
120
121
|
#.....................
|
121
122
|
namespace :templates do
|
123
|
+
|
122
124
|
namespace :upgrade do
|
123
|
-
###########
|
124
|
-
task :
|
125
|
-
|
125
|
+
########### templates:upgrade:all ###########
|
126
|
+
task :all do
|
127
|
+
info "Upgrade all key module files from FalkorLib templates"
|
126
128
|
FalkorLib::Puppet::Modules.upgrade()
|
127
129
|
end
|
130
|
+
|
131
|
+
[ 'readme', 'rake', 'vagrant' ].each do |t|
|
132
|
+
########### templates:upgrade:{readme,rake,vagrant} ###########
|
133
|
+
task t.to_sym do
|
134
|
+
list = case t
|
135
|
+
when 'readme'
|
136
|
+
[ 'README.md', 'doc/contributing.md' ]
|
137
|
+
when 'rake'
|
138
|
+
[ 'Gemfile', 'Rakefile' ]
|
139
|
+
when 'vagrant'
|
140
|
+
[ 'Vagrantfile', '.vagrant_init.rb']
|
141
|
+
else []
|
142
|
+
end
|
143
|
+
#info "Upgrade the module files '#{list.join(',')}' from FalkorLib templates"
|
144
|
+
FalkorLib::Puppet::Modules.upgrade(Dir.pwd,{
|
145
|
+
:only => list
|
146
|
+
})
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
########### templates:upgrade:tests ###########
|
151
|
+
task :tests do
|
152
|
+
info "Upgrade the basic tests manifests in tests/"
|
153
|
+
FalkorLib::Puppet::Modules.upgrade_from_template(Dir.pwd, 'tests')
|
154
|
+
end
|
155
|
+
|
156
|
+
|
128
157
|
end # namespace upgrade
|
129
158
|
end # namespace module
|
130
159
|
|
@@ -162,6 +191,32 @@ PuppetSyntax.exclude_paths = exclude_tests_paths
|
|
162
191
|
# end
|
163
192
|
# task :syntax => :syntax_info
|
164
193
|
|
194
|
+
#.........................................................................
|
195
|
+
# rspec-puppet tasks -- see http://rspec-puppet.com/tutorial/
|
196
|
+
#
|
197
|
+
require 'rspec/core/rake_task'
|
198
|
+
|
199
|
+
########## rspec #################
|
200
|
+
desc "Run all RSpec code examples"
|
201
|
+
RSpec::Core::RakeTask.new(:rspec) do |t|
|
202
|
+
t.rspec_opts = File.read("spec/spec.opts").chomp || ""
|
203
|
+
end
|
204
|
+
|
205
|
+
SPEC_SUITES = (Dir.entries('spec') - ['.', '..','fixtures']).select {|e| File.directory? "spec/#{e}" }
|
206
|
+
namespace :rspec do
|
207
|
+
SPEC_SUITES.each do |suite|
|
208
|
+
############ rspec:{classes,defines...} ##########
|
209
|
+
desc "Run #{suite} RSpec code examples"
|
210
|
+
RSpec::Core::RakeTask.new(suite) do |t|
|
211
|
+
t.pattern = "spec/#{suite}/**/*_spec.rb"
|
212
|
+
t.rspec_opts = File.read("spec/spec.opts").chomp || ""
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
task :default => :rspec
|
217
|
+
|
218
|
+
|
219
|
+
|
165
220
|
|
166
221
|
################################################
|
167
222
|
|
data/lib/falkorlib/version.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
#########################################
|
3
3
|
# puppet_modules_spec.rb
|
4
4
|
# @author Sebastien Varrette <Sebastien.Varrette@uni.lu>
|
5
|
-
# Time-stamp: <
|
5
|
+
# Time-stamp: <Ven 2014-12-05 22:56 svarrette>
|
6
6
|
#
|
7
7
|
# @description Check the Puppet Modules operations
|
8
8
|
#
|
@@ -88,17 +88,23 @@ describe FalkorLib::Puppet::Modules do
|
|
88
88
|
d.should == []
|
89
89
|
end
|
90
90
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
91
|
+
it "#metadata" do
|
92
|
+
ref = JSON.parse( IO.read( jsonfile ) )
|
93
|
+
metadata = FalkorLib::Puppet::Modules.metadata(moduledir, {
|
94
|
+
:use_symbols => false,
|
95
|
+
:extras => false
|
96
|
+
})
|
97
|
+
ref.keys.each do |k|
|
98
|
+
metadata[k].should == ref[k]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
96
102
|
|
97
103
|
it "#parse" do
|
98
|
-
STDIN.should_receive(:gets).and_return('')
|
104
|
+
#STDIN.should_receive(:gets).and_return('')
|
99
105
|
ref = JSON.parse( IO.read( jsonfile ) )
|
100
|
-
|
101
|
-
|
106
|
+
metadata = FalkorLib::Puppet::Modules.parse(moduledir, { :no_interaction => true })
|
107
|
+
diff = (metadata.to_a - ref.to_a).flatten.sort
|
102
108
|
diff.should == [
|
103
109
|
'classes',
|
104
110
|
'definitions',
|
@@ -111,9 +117,11 @@ describe FalkorLib::Puppet::Modules do
|
|
111
117
|
]
|
112
118
|
end
|
113
119
|
|
114
|
-
it "#parse again" do
|
115
|
-
|
116
|
-
metadata.
|
120
|
+
it "#parse again -- should not exhibit any difference" do
|
121
|
+
ref = JSON.parse( IO.read( jsonfile ) )
|
122
|
+
metadata = FalkorLib::Puppet::Modules.parse(moduledir, { :no_interaction => true })
|
123
|
+
diff = (metadata.to_a - ref.to_a).flatten.sort
|
124
|
+
diff.should == []
|
117
125
|
end
|
118
126
|
|
119
127
|
it "#deps -- should find a new dependency" do
|
@@ -124,11 +132,12 @@ describe FalkorLib::Puppet::Modules do
|
|
124
132
|
a.should include newdep
|
125
133
|
end
|
126
134
|
|
127
|
-
it "#parse -- should ask new dependency elements" do
|
135
|
+
it "#parse again -- should ask new dependency elements" do
|
128
136
|
ref = JSON.parse( IO.read( jsonfile ) )
|
129
137
|
STDIN.should_receive(:gets).and_return('svarrette')
|
130
138
|
STDIN.should_receive(:gets).and_return('1.2')
|
131
139
|
STDIN.should_receive(:gets).and_return('Yes')
|
140
|
+
STDIN.should_receive(:gets).and_return('')
|
132
141
|
metadata = FalkorLib::Puppet::Modules.parse(moduledir)
|
133
142
|
diff = (metadata.to_a - ref.to_a).flatten
|
134
143
|
diff.should == [
|
@@ -137,6 +146,41 @@ describe FalkorLib::Puppet::Modules do
|
|
137
146
|
{"name"=>"svarrette/tata", "version_requirement"=>"1.2"}
|
138
147
|
]
|
139
148
|
end
|
149
|
+
|
150
|
+
upgraded_files_default = 1
|
151
|
+
it "#upgrade" do
|
152
|
+
d = FalkorLib::Puppet::Modules.upgrade(moduledir, {
|
153
|
+
:no_interaction => true
|
154
|
+
})
|
155
|
+
d.should == upgraded_files_default
|
156
|
+
end
|
157
|
+
|
158
|
+
it "#upgrade -- with only a subset of files" do
|
159
|
+
d = FalkorLib::Puppet::Modules.upgrade(moduledir, {
|
160
|
+
:no_interaction => true,
|
161
|
+
:only => [ 'README.md', 'Gemfile']
|
162
|
+
})
|
163
|
+
d.should == 0
|
164
|
+
end
|
165
|
+
|
166
|
+
it "#upgrade -- exclude some files" do
|
167
|
+
d = FalkorLib::Puppet::Modules.upgrade(moduledir, {
|
168
|
+
:no_interaction => true,
|
169
|
+
:exclude => [ 'README.md']
|
170
|
+
})
|
171
|
+
d.should == (upgraded_files_default - 1)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "#upgrade -- both include and exclude files" do
|
175
|
+
d = FalkorLib::Puppet::Modules.upgrade(moduledir, {
|
176
|
+
:no_interaction => true,
|
177
|
+
:only => [ 'README.md'],
|
178
|
+
:exclude => [ 'README.md']
|
179
|
+
})
|
180
|
+
d.should == 0
|
181
|
+
end
|
182
|
+
|
183
|
+
|
140
184
|
end # context
|
141
185
|
|
142
186
|
end
|
@@ -6,7 +6,8 @@ gem 'falkorlib' #, :path => '~/git/github.com/Falkor/falkorlib'
|
|
6
6
|
# Puppet stuff
|
7
7
|
puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 3.3']
|
8
8
|
gem "puppet", puppetversion
|
9
|
-
gem 'puppetlabs_spec_helper', '>= 0.1.0'
|
9
|
+
#gem 'puppetlabs_spec_helper', '>= 0.1.0'
|
10
10
|
gem 'puppet-lint', '>= 0.3.2'
|
11
11
|
gem 'puppet-syntax'
|
12
12
|
gem 'facter', '>= 1.7.0'
|
13
|
+
gem 'rspec-puppet'
|
@@ -1,6 +1,6 @@
|
|
1
1
|
-*- mode: markdown; mode: auto-fill; fill-column: 80 -*-
|
2
2
|
|
3
|
-
# <%= config[:
|
3
|
+
# <%= config[:shortname].capitalize %> Puppet Module Developments
|
4
4
|
|
5
5
|
If you want to contribute to the code, you shall be aware of the way this module
|
6
6
|
is organized.
|
@@ -13,18 +13,18 @@ is organized.
|
|
13
13
|
`-- files/ # Contains static files, which managed nodes can download
|
14
14
|
`-- lib/ # custom facts/type/provider definitions
|
15
15
|
`-- manifests/
|
16
|
-
`-- init.pp # Main manifests file
|
17
|
-
`--
|
18
|
-
|
19
|
-
|
20
|
-
`-- definitions/ # Hold manifest for <%= config[:name] %> definitions
|
21
|
-
`-- <%= config[:name] %>-mydef.pp # defines the <%= config[:name] %>::mydef definition `-- templates/ # Module ERB template files
|
16
|
+
`-- init.pp # Main manifests file which defines the <%= config[:shortname] %> class
|
17
|
+
`-- params.pp # <%= config[:name] %> module variables
|
18
|
+
`-- mydef.pp # defines the <%= config[:shortname] %>::mydef definition
|
19
|
+
`-- templates/ # Module ERB template files
|
22
20
|
`-- tests/ # Contains examples showing how to declare the module’s classes and defined type
|
23
|
-
`-- spec/ # Contains
|
21
|
+
`-- spec/ # Contains rspec tests
|
24
22
|
`-- Rakefile # Definition of the [rake](https://github.com/jimweirich/rake) tasks
|
25
23
|
`-- .ruby-{version,gemset} # [RVM](https://rvm.io/) configuration
|
26
24
|
`-- Gemfile[.lock] # [Bundler](http://bundler.io/) configuration
|
27
25
|
`-- .git/ # Hold git configuration
|
26
|
+
`-- .vagrant_init.rb # Vagrant provisionner to test this module
|
27
|
+
`-- Vagrantfile # Vagrant file
|
28
28
|
|
29
29
|
### Git Branching Model
|
30
30
|
|
@@ -15,27 +15,13 @@
|
|
15
15
|
|
16
16
|
include '<%= config[:shortname] %>::params'
|
17
17
|
|
18
|
-
$names = [
|
19
|
-
"ensure",
|
20
|
-
"protocol",
|
21
|
-
"port",
|
22
|
-
"packagename",
|
23
|
-
"logdir",
|
24
|
-
"logdir_mode",
|
25
|
-
"logdir_owner",
|
26
|
-
"logdir_group",
|
27
|
-
"servicename",
|
28
|
-
"processname",
|
29
|
-
"hasstatus",
|
30
|
-
"hasrestart",
|
31
|
-
"configfile",
|
32
|
-
"configfile_init",
|
33
|
-
"configfile_mode",
|
34
|
-
"configfile_owner",
|
35
|
-
"configfile_group",
|
36
|
-
]
|
18
|
+
$names = <%= config[:params] %>
|
37
19
|
|
38
|
-
each
|
39
|
-
|
40
|
-
|
41
|
-
|
20
|
+
<% config[:params].each do |v| %>
|
21
|
+
notice("<%= config[:shortname] %>::params::<%= v %> = ${<%= config[:shortname] %>::params::<%= v %>}")
|
22
|
+
<% end %>
|
23
|
+
|
24
|
+
#each($names) |$v| {
|
25
|
+
# $var = "<%= config[:shortname] %>::params::${v}"
|
26
|
+
# notice("${var} = ", inline_template('<%%= scope.lookupvar(@var) %>'))
|
27
|
+
#}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: falkorlib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastien Varrette
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|