summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Gilman <evan@pagerduty.com>2016-08-24 17:02:06 -0700
committerEvan Gilman <evan@pagerduty.com>2016-08-24 17:02:06 -0700
commit7f6b92e88247739dd2ec6f47096b8e267021fa67 (patch)
treef6040569da3179359de59c42d8a4d7191813f1c5
parentdced5fa9f21f73d61382731b3d5201676d10a40a (diff)
downloadchef-7f6b92e88247739dd2ec6f47096b8e267021fa67.tar.gz
Use upstart goal state as service status
Solves #5204
-rw-r--r--lib/chef/provider/service/upstart.rb6
-rw-r--r--spec/unit/provider/service/upstart_service_spec.rb39
2 files changed, 30 insertions, 15 deletions
diff --git a/lib/chef/provider/service/upstart.rb b/lib/chef/provider/service/upstart.rb
index 99ffc24653..6e2a3b6473 100644
--- a/lib/chef/provider/service/upstart.rb
+++ b/lib/chef/provider/service/upstart.rb
@@ -119,7 +119,7 @@ class Chef
end
else
begin
- if upstart_state == "running"
+ if upstart_goal_state == "start"
@current_resource.running true
else
@current_resource.running false
@@ -223,7 +223,7 @@ class Chef
conf.write_file
end
- def upstart_state
+ def upstart_goal_state
command = "/sbin/status #{@job}"
status = popen4(command) do |pid, stdin, stdout, stderr|
stdout.each_line do |line|
@@ -234,7 +234,7 @@ class Chef
# service (goal) state
line =~ UPSTART_STATE_FORMAT
data = Regexp.last_match
- return data[2]
+ return data[1]
end
end
end
diff --git a/spec/unit/provider/service/upstart_service_spec.rb b/spec/unit/provider/service/upstart_service_spec.rb
index fd9ea0573c..fb5a418684 100644
--- a/spec/unit/provider/service/upstart_service_spec.rb
+++ b/spec/unit/provider/service/upstart_service_spec.rb
@@ -105,17 +105,21 @@ describe Chef::Provider::Service::Upstart do
end
describe "when the status command uses the new format" do
- before do
+ it "should set running to true if the goal state is 'start'" do
+ @stdout = StringIO.new("rsyslog start/running")
+ 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 true if the status command returns 0" do
- @stdout = StringIO.new("rsyslog start/running")
+ it "should set running to true if the goal state is 'start' but current state is not 'running'" do
+ @stdout = StringIO.new("rsyslog start/starting")
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
+ it "should set running to false if the goal state is 'stop'" do
@stdout = StringIO.new("rsyslog stop/waiting")
allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
@provider.load_current_resource
@@ -124,17 +128,21 @@ describe Chef::Provider::Service::Upstart do
end
describe "when the status command uses the new format with an instance" do
- before do
+ it "should set running to true if the goal state is 'start'" 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 true if the status command returns 0" do
- @stdout = StringIO.new("rsyslog (test) start/running, process 100")
+ it "should set running to true if the goal state is 'start' but current state is not 'running'" do
+ @stdout = StringIO.new("rsyslog (test) start/starting, 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
+ it "should set running to false if the goal state is 'stop'" 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
@@ -143,14 +151,21 @@ describe Chef::Provider::Service::Upstart do
end
describe "when the status command uses the old format" do
- it "should set running to true if the status command returns 0" do
+ it "should set running to true if the goal state is 'start'" do
@stdout = StringIO.new("rsyslog (start) running, process 32225")
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
+ it "should set running to true if the goal state is 'start' but current state is not 'running'" do
+ @stdout = StringIO.new("rsyslog (start) starting, process 32225")
+ 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 goal state is 'stop'" do
@stdout = StringIO.new("rsyslog (stop) waiting")
allow(@provider).to receive(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
@provider.load_current_resource
@@ -214,8 +229,8 @@ describe Chef::Provider::Service::Upstart do
end
end
- it "should track state when we fail to obtain service status via upstart_state" do
- expect(@provider).to receive(:upstart_state).and_raise Chef::Exceptions::Exec
+ it "should track state when we fail to obtain service status via upstart_goal_state" do
+ expect(@provider).to receive(:upstart_goal_state).and_raise Chef::Exceptions::Exec
@provider.load_current_resource
expect(@provider.instance_variable_get("@command_success")).to eq(false)
end