Skip to content

Commit 272abb9

Browse files
authored
Merge pull request #9198 from puppetlabs/revert-9175-bug_fix/main/error_when_resource_not_found
Revert "SystemD and Windows resources when not resource found will now return error"
2 parents 2241371 + 1818d78 commit 272abb9

File tree

8 files changed

+12
-76
lines changed

8 files changed

+12
-76
lines changed

Diff for: lib/puppet/application/resource.rb

+2-5
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,8 @@ def find_or_save_resources(type, name, params)
236236
resource = Puppet::Resource.new( type, name, :parameters => params )
237237

238238
# save returns [resource that was saved, transaction log from applying the resource]
239-
save_result, report = Puppet::Resource.indirection.save(resource, key)
240-
status = report.resource_statuses[resource.ref]
241-
raise "Failed to manage resource #{resource.ref}" if status&.failed?
242-
243-
[ save_result ]
239+
save_result = Puppet::Resource.indirection.save(resource, key)
240+
[ save_result.first ]
244241
end
245242
else
246243
if type == "file"

Diff for: lib/puppet/provider/service/systemd.rb

-14
Original file line numberDiff line numberDiff line change
@@ -163,20 +163,6 @@ def daemon_reload?
163163
end
164164
end
165165

166-
# override base#status
167-
def status
168-
if exist?
169-
status = service_command(:status, false)
170-
if status.exitstatus == 0
171-
return :running
172-
else
173-
return :stopped
174-
end
175-
else
176-
return :absent
177-
end
178-
end
179-
180166
def enable
181167
self.unmask
182168
systemctl_change_enable(:enable)

Diff for: lib/puppet/provider/service/windows.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def stop
9090
end
9191

9292
def status
93-
return :absent unless Puppet::Util::Windows::Service.exists?(@resource[:name])
93+
return :stopped unless Puppet::Util::Windows::Service.exists?(@resource[:name])
9494

9595
current_state = Puppet::Util::Windows::Service.service_state(@resource[:name])
9696
state = case current_state

Diff for: lib/puppet/type/service.rb

-6
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,6 @@ def insync?(current)
110110
provider.start
111111
end
112112

113-
newvalue(:absent)
114-
115-
validate do |val|
116-
fail "Managing absent on a service is not supported" if val.to_s == 'absent'
117-
end
118-
119113
aliasvalue(:false, :stopped)
120114
aliasvalue(:true, :running)
121115

Diff for: spec/unit/application/resource_spec.rb

+1-10
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,12 @@
118118
@resource_app.main
119119
end
120120

121-
before :each do
122-
allow(@res).to receive(:ref).and_return("type/name")
123-
end
124-
125121
it "should add given parameters to the object" do
126122
allow(@resource_app.command_line).to receive(:args).and_return(['type','name','param=temp'])
127123

128124
expect(Puppet::Resource.indirection).to receive(:save).with(@res, 'type/name').and_return([@res, @report])
129125
expect(Puppet::Resource).to receive(:new).with('type', 'name', {:parameters => {'param' => 'temp'}}).and_return(@res)
130126

131-
resource_status = instance_double('Puppet::Resource::Status')
132-
allow(@report).to receive(:resource_statuses).and_return({'type/name' => resource_status})
133-
allow(resource_status).to receive(:failed?).and_return(false)
134127
@resource_app.main
135128
end
136129
end
@@ -147,13 +140,11 @@ def exists?
147140
true
148141
end
149142

150-
def string=(value)
151-
end
152-
153143
def string
154144
Puppet::Util::Execution::ProcessOutput.new('test', 0)
155145
end
156146
end
147+
157148
it "should not emit puppet class tags when printing yaml when strict mode is off" do
158149
Puppet[:strict] = :warning
159150

Diff for: spec/unit/provider/service/systemd_spec.rb

+6-32
Original file line numberDiff line numberDiff line change
@@ -388,52 +388,26 @@
388388
# Note: systemd provider does not care about hasstatus or a custom status
389389
# command. I just assume that it does not make sense for systemd.
390390
describe "#status" do
391-
it 'when called on a service that does not exist returns absent' do
392-
provider = provider_class.new(Puppet::Type.type(:service).new(:name => 'doesnotexist.service'))
393-
expect(provider).to receive(:exist?).and_return(false)
394-
expect(provider.status).to eq(:absent)
395-
end
396-
397-
it 'when called on a service that does exist and is running returns running' do
398-
provider = provider_class.new(Puppet::Type.type(:service).new(:name => 'doesexist.service'))
399-
expect(provider).to receive(:execute).
400-
with(['/bin/systemctl','cat', '--', 'doesexist.service'], {:failonfail=>false}).
401-
and_return(Puppet::Util::Execution::ProcessOutput.new("# /lib/systemd/system/doesexist.service\n...", 0)).once
402-
expect(provider).to receive(:execute).
403-
with(['/bin/systemctl','is-active', '--', 'doesexist.service'], {:combine=>true, :failonfail=>false, :override_locale=>false, :squelch=>false}).
404-
and_return(Puppet::Util::Execution::ProcessOutput.new("# /lib/systemd/system/doesexist.service\n...", 0)).once
391+
it "should return running if the command returns 0" do
392+
provider = provider_class.new(Puppet::Type.type(:service).new(:name => 'sshd.service'))
393+
expect(provider).to receive(:execute)
394+
.with(['/bin/systemctl','is-active', '--', 'sshd.service'], {:failonfail => false, :override_locale => false, :squelch => false, :combine => true})
395+
.and_return(Puppet::Util::Execution::ProcessOutput.new("active\n", 0))
405396
expect(provider.status).to eq(:running)
406397
end
407398

408-
it 'when called on a service that does exist and is not running returns stopped' do
409-
provider = provider_class.new(Puppet::Type.type(:service).new(:name => 'doesexist.service'))
410-
expect(provider).to receive(:execute).
411-
with(['/bin/systemctl','cat', '--', 'doesexist.service'], {:failonfail=>false}).
412-
and_return(Puppet::Util::Execution::ProcessOutput.new("# /lib/systemd/system/doesexist.service\n...", 0)).once
413-
expect(provider).to receive(:execute).
414-
with(['/bin/systemctl','is-active', '--', 'doesexist.service'], {:combine=>true, :failonfail=>false, :override_locale=>false, :squelch=>false}).
415-
and_return(Puppet::Util::Execution::ProcessOutput.new("inactive\n", 3)).once
416-
expect(provider.status).to eq(:stopped)
417-
end
418-
419399
[-10,-1,3,10].each { |ec|
420400
it "should return stopped if the command returns something non-0" do
421401
provider = provider_class.new(Puppet::Type.type(:service).new(:name => 'sshd.service'))
422-
expect(provider).to receive(:execute).
423-
with(['/bin/systemctl','cat', '--', 'sshd.service'], {:failonfail=>false}).
424-
and_return(Puppet::Util::Execution::ProcessOutput.new("# /lib/systemd/system/sshd.service\n...", 0)).once
425402
expect(provider).to receive(:execute)
426-
.with(['/bin/systemctl','is-active', '--', 'sshd.service'], {:failonfail => false, :override_locale => false, :squelch => false, :combine => true})
403+
.with(['/bin/systemctl','is-active', '--', 'sshd.service'], {:failonfail => false, :override_locale => false, :squelch => false, :combine => true})
427404
.and_return(Puppet::Util::Execution::ProcessOutput.new("inactive\n", ec))
428405
expect(provider.status).to eq(:stopped)
429406
end
430407
}
431408

432409
it "should use the supplied status command if specified" do
433410
provider = provider_class.new(Puppet::Type.type(:service).new(:name => 'sshd.service', :status => '/bin/foo'))
434-
expect(provider).to receive(:execute).
435-
with(['/bin/systemctl','cat', '--', 'sshd.service'], {:failonfail=>false}).
436-
and_return(Puppet::Util::Execution::ProcessOutput.new("# /lib/systemd/system/sshd.service\n...", 0)).once
437411
expect(provider).to receive(:execute)
438412
.with(['/bin/foo'], {:failonfail => false, :override_locale => false, :squelch => false, :combine => true})
439413
.and_return(process_output)

Diff for: spec/unit/provider/service/windows_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@
8181
end
8282

8383
describe "#status" do
84-
it "should report a nonexistent service as absent" do
84+
it "should report a nonexistent service as stopped" do
8585
allow(service_util).to receive(:exists?).with(resource[:name]).and_return(false)
8686

87-
expect(provider.status).to eql(:absent)
87+
expect(provider.status).to eql(:stopped)
8888
end
8989

9090
it "should report service as stopped when status cannot be retrieved" do

Diff for: spec/unit/type/service_spec.rb

-6
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,6 @@ def safely_load_service_type
6767
expect(svc.should(:ensure)).to eq(:stopped)
6868
end
6969

70-
describe 'the absent property' do
71-
it 'should fail validate if it is a service' do
72-
expect { Puppet::Type.type(:service).new(:name => "service_name", :ensure => :absent) }.to raise_error(Puppet::Error, /Managing absent on a service is not supported/)
73-
end
74-
end
75-
7670
describe "the enable property" do
7771
before :each do
7872
allow(@provider.class).to receive(:supports_parameter?).and_return(true)

0 commit comments

Comments
 (0)