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