|
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 '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)) |
405 | 396 | expect(provider.status).to eq(:running) |
406 | 397 | end |
407 | 398 |
|
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 | | - |
419 | 399 | [-10,-1,3,10].each { |ec| |
420 | 400 | it "should return stopped if the command returns something non-0" do |
421 | 401 | 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 |
425 | 402 | 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}) |
427 | 404 | .and_return(Puppet::Util::Execution::ProcessOutput.new("inactive\n", ec)) |
428 | 405 | expect(provider.status).to eq(:stopped) |
429 | 406 | end |
430 | 407 | } |
431 | 408 |
|
432 | 409 | it "should use the supplied status command if specified" do |
433 | 410 | 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 |
437 | 411 | expect(provider).to receive(:execute) |
438 | 412 | .with(['/bin/foo'], {:failonfail => false, :override_locale => false, :squelch => false, :combine => true}) |
439 | 413 | .and_return(process_output) |
|
0 commit comments