Skip to content

Commit b622c94

Browse files
authored
Merge pull request #8957 from mhashizume/maint/main/7.x-mergeup-12-1-22
(maint) Manual 7.x -> main mergeup
2 parents 4f111f4 + 921be41 commit b622c94

File tree

5 files changed

+56
-16
lines changed

5 files changed

+56
-16
lines changed

lib/puppet/info_service/task_information_service.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@ class Puppet::InfoService::TaskInformationService
44
def self.tasks_per_environment(environment_name)
55
# get the actual environment object, raise error if the named env doesn't exist
66
env = Puppet.lookup(:environments).get!(environment_name)
7+
78
env.modules.map do |mod|
89
mod.tasks.map do |task|
9-
{:module => {:name => task.module.name}, :name => task.name, :metadata => task.metadata}
10+
# If any task is malformed continue to list other tasks in module
11+
begin
12+
task.validate
13+
{:module => {:name => task.module.name}, :name => task.name, :metadata => task.metadata}
14+
rescue Puppet::Module::Task::Error => err
15+
Puppet.log_exception(err, 'Failed to validate task')
16+
nil
17+
end
1018
end
11-
end.flatten
19+
end.flatten.compact
1220
end
1321

1422
def self.task_data(environment_name, module_name, task_name)

lib/puppet/type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def self.newmetaparam(name, options = {}, &block)
361361
# @return [Void]
362362
def copy_metaparams(parameters)
363363
parameters.each do |name, param|
364-
self[name] = param.value if param.metaparam? && !name == :alias
364+
self[name] = param.value if param.metaparam? && name != :alias
365365
end
366366
nil
367367
end

lib/puppet/type/tidy.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,10 @@ def mkfile(path)
247247
:ensure => :absent, :force => true
248248
}
249249

250-
parameters[:noop] = self[:noop] unless self[:noop].nil?
250+
new_file = Puppet::Type.type(:file).new(parameters)
251+
new_file.copy_metaparams(@parameters)
251252

252-
Puppet::Type.type(:file).new(parameters)
253+
new_file
253254
end
254255

255256
def retrieve

spec/unit/info_service_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,27 @@
3333
end
3434
end
3535

36+
it "returns task data for valid tasks in an environment even if invalid tasks exist" do
37+
Puppet.override(:environments => env_loader) do
38+
@mod = PuppetSpec::Modules.create(mod_name, modpath, {:environment => env,
39+
:tasks => [['atask',
40+
{:name => 'atask.json',
41+
:content => metadata.to_json}],
42+
['btask',
43+
{:name => 'btask.json',
44+
:content => metadata.to_json}],
45+
['ctask',
46+
{:name => 'ctask.json',
47+
:content => metadata.to_json}]]})
48+
File.write("#{modpath}/#{mod_name}/tasks/atask.json", "NOT JSON")
49+
50+
expect(Puppet).to receive(:send_log).with(:err, 'Failed to validate task')
51+
52+
@tasks = Puppet::InfoService.tasks_per_environment(env_name)
53+
expect(@tasks.map{|t| t[:name]}).to contain_exactly('test1::btask', 'test1::ctask')
54+
end
55+
end
56+
3657
it "should throw EnvironmentNotFound if given a nonexistent environment" do
3758
expect{ Puppet::InfoService.tasks_per_environment('utopia') }.to raise_error(Puppet::Environments::EnvironmentNotFound)
3859
end

spec/unit/type/tidy_spec.rb

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,27 +141,20 @@
141141
describe "and generating files" do
142142
it "should set the backup on the file if backup is set on the tidy instance" do
143143
@tidy[:backup] = "whatever"
144-
expect(Puppet::Type.type(:file)).to receive(:new).with(hash_including(backup: "whatever"))
145144

146-
@tidy.mkfile(@basepath)
145+
expect(@tidy.mkfile(@basepath)[:backup]).to eq("whatever")
147146
end
148147

149148
it "should set the file's path to the tidy's path" do
150-
expect(Puppet::Type.type(:file)).to receive(:new).with(hash_including(path: @basepath))
151-
152-
@tidy.mkfile(@basepath)
149+
expect(@tidy.mkfile(@basepath)[:path]).to eq(@basepath)
153150
end
154151

155152
it "should configure the file for deletion" do
156-
expect(Puppet::Type.type(:file)).to receive(:new).with(hash_including(ensure: :absent))
157-
158-
@tidy.mkfile(@basepath)
153+
expect(@tidy.mkfile(@basepath)[:ensure]).to eq(:absent)
159154
end
160155

161156
it "should force deletion on the file" do
162-
expect(Puppet::Type.type(:file)).to receive(:new).with(hash_including(force: true))
163-
164-
@tidy.mkfile(@basepath)
157+
expect(@tidy.mkfile(@basepath)[:force]).to eq(true)
165158
end
166159

167160
it "should do nothing if the targeted file does not exist" do
@@ -471,6 +464,23 @@
471464

472465
expect(result.values).to all(be_noop)
473466
end
467+
468+
it "generates resources whose schedule parameter matches the managed resource's schedule parameter" do
469+
@tidy[:recurse] = true
470+
@tidy[:schedule] = 'fake_schedule'
471+
472+
fileset = double('fileset')
473+
expect(Puppet::FileServing::Fileset).to receive(:new).with(@basepath, {:recurse => true, :max_files=>0}).and_return(fileset)
474+
expect(fileset).to receive(:files).and_return(%w{. a a/2 a/1 a/3})
475+
allow(@tidy).to receive(:tidy?).and_return(true)
476+
477+
result = @tidy.generate.inject({}) { |hash, res| hash[res[:path]] = res; hash }
478+
479+
result.each do |file_resource|
480+
expect(file_resource[1][:schedule]).to eq('fake_schedule')
481+
end
482+
483+
end
474484
end
475485

476486
def lstat_is(path, stat)

0 commit comments

Comments
 (0)