diff options
author | Justin Seubert <dude051@gmail.com> | 2015-11-12 11:15:10 -0600 |
---|---|---|
committer | Bryan McLellan <btm@chef.io> | 2015-11-23 18:12:14 -0500 |
commit | 27c71ab080ba63b3ce83c44907bfd654a66b26d9 (patch) | |
tree | 042915b2e24a470b039b4e8b9e408a82327f16e6 | |
parent | ced05a7932f1ab29b4d985d95c4084a108aa3f13 (diff) | |
download | chef-27c71ab080ba63b3ce83c44907bfd654a66b26d9.tar.gz |
Correcting regex for upstart_state
-rw-r--r-- | lib/chef/provider/service/upstart.rb | 6 | ||||
-rw-r--r-- | spec/unit/provider/service/upstart_service_spec.rb | 19 |
2 files changed, 22 insertions, 3 deletions
diff --git a/lib/chef/provider/service/upstart.rb b/lib/chef/provider/service/upstart.rb index c08a5f8636..8d9adaa3b3 100644 --- a/lib/chef/provider/service/upstart.rb +++ b/lib/chef/provider/service/upstart.rb @@ -30,7 +30,7 @@ class Chef Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart) end - UPSTART_STATE_FORMAT = /\w+ \(?(\w+)\)?[\/ ](\w+)/ + UPSTART_STATE_FORMAT = /\S+ \(?(start|stop)?\)? ?[\/ ](\w+)/ def self.supports?(resource, action) Chef::Platform::ServiceHelpers.config_for_service(resource.service_name).include?(:upstart) @@ -224,10 +224,10 @@ class Chef command = "/sbin/status #{@job}" status = popen4(command) do |pid, stdin, stdout, stderr| stdout.each_line do |line| - # rsyslog stop/waiting # service goal/state # OR - # rsyslog (stop) waiting + # service (instance) goal/state + # OR # service (goal) state line =~ UPSTART_STATE_FORMAT data = Regexp.last_match diff --git a/spec/unit/provider/service/upstart_service_spec.rb b/spec/unit/provider/service/upstart_service_spec.rb index 1c8e304cb7..6fb1f9fdbf 100644 --- a/spec/unit/provider/service/upstart_service_spec.rb +++ b/spec/unit/provider/service/upstart_service_spec.rb @@ -123,6 +123,25 @@ describe Chef::Provider::Service::Upstart do end end + describe "when the status command uses the new format with an instance" do + before do + end + + it "should set running to true if the status command returns 0" do + @stdout = StringIO.new("rsyslog (test) start/running, process 100") + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.load_current_resource + expect(@current_resource.running).to be_truthy + end + + it "should set running to false if the status command returns anything except 0" do + @stdout = StringIO.new("rsyslog (test) stop/waiting, process 100") + allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @provider.load_current_resource + expect(@current_resource.running).to be_falsey + end + end + describe "when the status command uses the old format" do it "should set running to true if the status command returns 0" do @stdout = StringIO.new("rsyslog (start) running, process 32225") |