Skip to content

Commit f47f125

Browse files
authored
Merge pull request #9282 from cthorn42/maint/main/revert_windows_resource_service_change
Revert "Merge pull request #9257 from cthorn42/maint/main/systemd_res…
2 parents 07b14b4 + fb9cc8a commit f47f125

File tree

8 files changed

+12
-80
lines changed

8 files changed

+12
-80
lines changed

lib/puppet/application/resource.rb

+2-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ def preinit
1515
option("--verbose", "-v")
1616
option("--edit", "-e")
1717
option("--to_yaml", "-y")
18-
option('--fail', '-f')
1918

2019
option("--types", "-t") do |_arg|
2120
env = Puppet.lookup(:environments).get(Puppet[:environment]) || create_default_environment
@@ -110,9 +109,6 @@ def help
110109
Output found resources in yaml format, suitable to use with Hiera and
111110
create_resources.
112111
113-
* --fail:
114-
Fails and returns an exit code of 1 if the resource is not found.
115-
116112
EXAMPLE
117113
-------
118114
This example uses `puppet resource` to return a Puppet configuration for
@@ -240,11 +236,8 @@ def find_or_save_resources(type, name, params)
240236
resource = Puppet::Resource.new(type, name, :parameters => params)
241237

242238
# save returns [resource that was saved, transaction log from applying the resource]
243-
save_result, report = Puppet::Resource.indirection.save(resource, key)
244-
status = report.resource_statuses[resource.ref]
245-
raise "Failed to manage resource #{resource.ref}" if status&.failed? && !options[:fail].nil? && options[:fail]
246-
247-
[save_result]
239+
save_result = Puppet::Resource.indirection.save(resource, key)
240+
[save_result.first]
248241
end
249242
else
250243
if type == "file"

lib/puppet/provider/service/systemd.rb

-14
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,6 @@ def daemon_reload?
165165
end
166166
end
167167

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

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

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

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

spec/unit/provider/service/systemd_spec.rb

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

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

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

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

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)