Skip to content

Commit 8ed2564

Browse files
(maint) Merge up a64d9e3 to main
Generated by CI * commit 'a64d9e31537843bbc20cf824a986c7829d8b9644': (PUP-11200) Allow loading Task files from scripts mount (PUP-11199) Improve exec noop documentation
2 parents a4be41f + a64d9e3 commit 8ed2564

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
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_]*$/

lib/puppet/type/exec.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ module Puppet
1111
1212
* The command itself is already idempotent. (For example, `apt-get update`.)
1313
* The exec has an `onlyif`, `unless`, or `creates` attribute, which prevents
14-
Puppet from running the command unless some condition is met.
14+
Puppet from running the command unless some condition is met. The
15+
`onlyif` and `unless` commands of an `exec` are used in the process of
16+
determining whether the `exec` is already in sync, therefore they must be run
17+
during a noop Puppet run.
1518
* The exec has `refreshonly => true`, which allows Puppet to run the
1619
command only when some other resource is changed. (See the notes on refreshing
1720
below.)
@@ -456,6 +459,9 @@ def check(value)
456459
`user`, `cwd`, and `group` as the main command. If the `path` isn't set, you
457460
must fully qualify the command's name.
458461
462+
Since this command is used in the process of determining whether the
463+
`exec` is already in sync, it must be run during a noop Puppet run.
464+
459465
This parameter can also take an array of commands. For example:
460466
461467
unless => ['test -f /tmp/file1', 'test -f /tmp/file2'],
@@ -516,6 +522,9 @@ def check(value)
516522
`user`, `cwd`, and `group` as the main command. If the `path` isn't set, you
517523
must fully qualify the command's name.
518524
525+
Since this command is used in the process of determining whether the
526+
`exec` is already in sync, it must be run during a noop Puppet run.
527+
519528
This parameter can also take an array of commands. For example:
520529
521530
onlyif => ['test -f /tmp/file1', 'test -f /tmp/file2'],

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)