Skip to content

Commit a64d9e3

Browse files
authored
Merge pull request #8732 from lucywyman/PUP-11200
(PUP-11200) Allow loading Task files from scripts mount
2 parents 2ffe977 + ab668b3 commit a64d9e3

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

lib/puppet/module/plan.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ def initialize(plan_name, module_name)
5050
RESERVED_DATA_TYPES = %w{any array boolean catalogentry class collection
5151
callable data default enum float hash integer numeric optional pattern
5252
resource runtime scalar string struct tuple type undef variant}
53-
MOUNTS = %w[lib files plans]
5453

5554
def self.is_plan_name?(name)
5655
return true if name =~ /^[a-z][a-z0-9_]*$/

lib/puppet/module/task.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def initialize(task_name, module_name)
4545
end
4646

4747
FORBIDDEN_EXTENSIONS = %w{.conf .md}
48-
MOUNTS = %w[lib files tasks]
48+
MOUNTS = %w[files lib scripts tasks]
4949

5050
def self.is_task_name?(name)
5151
return true if name =~ /^[a-z][a-z0-9_]*$/

spec/lib/puppet_spec/modules.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def create(name, dir, options = {})
3636
end
3737
end
3838

39-
if plans = options[:plans]
39+
if (plans = options[:plans])
4040
plans_dir = File.join(module_dir, 'plans')
4141
FileUtils.mkdir_p(plans_dir)
4242
plans.each do |plan_file|
@@ -48,6 +48,17 @@ def create(name, dir, options = {})
4848
end
4949
end
5050

51+
if (scripts = options[:scripts])
52+
scripts_dir = File.join(module_dir, 'scripts')
53+
FileUtils.mkdir_p(scripts_dir)
54+
scripts.each do |script_file|
55+
if script_file.is_a?(String)
56+
script_file = { :name => script_file, :content => "" }
57+
end
58+
File.write(File.join(scripts_dir, script_file[:name]), script_file[:content])
59+
end
60+
end
61+
5162
(options[:files] || {}).each do |fname, content|
5263
path = File.join(module_dir, fname)
5364
FileUtils.mkdir_p(File.dirname(path))
@@ -61,7 +72,7 @@ def generate_files(name, dir, options = {})
6172
module_dir = File.join(dir, name)
6273
FileUtils.mkdir_p(module_dir)
6374

64-
if metadata = options[:metadata]
75+
if (metadata = options[:metadata])
6576
File.open(File.join(module_dir, 'metadata.json'), 'w') do |f|
6677
f.write(metadata.to_json)
6778
end

spec/unit/module_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,20 @@
567567
expect(mod.task_file(task_exe)).to eq("#{mod.path}/tasks/#{task_exe}")
568568
end
569569

570+
it "should list files from the scripts directory if required by the task" do
571+
mod = 'loads_scripts'
572+
task_dep = 'myscript.sh'
573+
script_ref = "#{mod}/scripts/#{task_dep}"
574+
task_json = JSON.generate({'files' => [script_ref]})
575+
task = [['task', { name: 'task.json', content: task_json }]]
576+
mod = PuppetSpec::Modules.create(mod, @modpath, {:environment => env,
577+
:scripts => [task_dep],
578+
:tasks => task})
579+
580+
expect(mod.tasks.first.files).to include({'name' => script_ref,
581+
'path' => /#{script_ref}/})
582+
end
583+
570584
it "should return nil when asked for an individual task file if it does not exist" do
571585
mod = PuppetSpec::Modules.create('task_file_neg', @modpath, {:environment => env,
572586
:tasks => []})

0 commit comments

Comments
 (0)