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