|
389 | 389 | # Note: systemd provider does not care about hasstatus or a custom status
|
390 | 390 | # command. I just assume that it does not make sense for systemd.
|
391 | 391 | describe "#status" do
|
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)) |
| 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 |
397 | 406 | expect(provider.status).to eq(:running)
|
398 | 407 | end
|
399 | 408 |
|
| 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 | + |
400 | 420 | [-10,-1,3,10].each { |ec|
|
401 | 421 | it "should return stopped if the command returns something non-0" do
|
402 | 422 | 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 |
403 | 426 | expect(provider).to receive(:execute)
|
404 |
| - .with(['/bin/systemctl','is-active', '--', 'sshd.service'], {:failonfail => false, :override_locale => false, :squelch => false, :combine => true}) |
| 427 | + .with(['/bin/systemctl','is-active', '--', 'sshd.service'], {:failonfail => false, :override_locale => false, :squelch => false, :combine => true}) |
405 | 428 | .and_return(Puppet::Util::Execution::ProcessOutput.new("inactive\n", ec))
|
406 | 429 | expect(provider.status).to eq(:stopped)
|
407 | 430 | end
|
408 | 431 | }
|
409 | 432 |
|
410 | 433 | it "should use the supplied status command if specified" do
|
411 | 434 | 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 |
412 | 438 | expect(provider).to receive(:execute)
|
413 | 439 | .with(['/bin/foo'], {:failonfail => false, :override_locale => false, :squelch => false, :combine => true})
|
414 | 440 | .and_return(process_output)
|
|
0 commit comments