diff options
author | kaustubh-d <kaustubh@clogeny.com> | 2014-09-15 23:00:58 +0530 |
---|---|---|
committer | kaustubh-d <kaustubh@clogeny.com> | 2014-09-15 23:00:58 +0530 |
commit | e01488c625ba11ec0ff4f9a9eeb81bcc0f829c3e (patch) | |
tree | c2bb73323598ef16b192f4cf30dab2c5a7e985e2 | |
parent | f2c6433811852b98f6f772c37daaab26702a8f5b (diff) | |
download | chef-e01488c625ba11ec0ff4f9a9eeb81bcc0f829c3e.tar.gz |
aix service provider more code changes
-rw-r--r-- | lib/chef/provider/service/aix.rb | 37 | ||||
-rw-r--r-- | spec/unit/provider/service/aix_service_spec.rb | 68 |
2 files changed, 80 insertions, 25 deletions
diff --git a/lib/chef/provider/service/aix.rb b/lib/chef/provider/service/aix.rb index be57096b65..6f70f797b9 100644 --- a/lib/chef/provider/service/aix.rb +++ b/lib/chef/provider/service/aix.rb @@ -37,7 +37,6 @@ class Chef @is_resource_group = false determine_current_status! - is_resource_group? @current_resource end @@ -86,32 +85,17 @@ class Chef def define_resource_requirements # FIXME? need reload from service.rb shared_resource_requirements - requirements.assert(:start) do |a| - a.assertion { @new_resource.start_command } - a.failure_message Chef::Exceptions::Service, "#{self.to_s} requires that start_command be set" - end - requirements.assert(:stop) do |a| - a.assertion { @new_resource.stop_command } - a.failure_message Chef::Exceptions::Service, "#{self.to_s} requires that stop_command be set" - end - - requirements.assert(:restart) do |a| - a.assertion { @new_resource.restart_command || ( @new_resource.start_command && @new_resource.stop_command ) } - a.failure_message Chef::Exceptions::Service, "#{self.to_s} requires a restart_command or both start_command and stop_command be set in order to perform a restart" - end - - requirements.assert(:reload) do |a| - a.assertion { @new_resource.reload_command } - a.failure_message Chef::Exceptions::UnsupportedAction, "#{self.to_s} requires a reload_command be set in order to perform a reload" - end end protected def determine_current_status! Chef::Log.debug "#{@new_resource} using lssrc to check the status " begin - if shell_out!("lssrc -a | grep #{@new_resource.service_name}").stdout.split(' ').last == "active" - @current_resource.running(true) + services = shell_out!("lssrc -a | grep -w #{@new_resource.service_name}").stdout.split("\n") + is_resource_group?(services) + + if services.length == 1 && services[0].split(' ').last == "active" + @current_resource.running true else @current_resource.running false end @@ -126,9 +110,14 @@ class Chef end end - def is_resource_group? - args = shell_out!("lssrc -a | grep #{@new_resource.service_name}").stdout.split(' ') - @is_resource_group = true if (args[1] != "" && args.length > 3) + def is_resource_group? (services) + if services.length > 1 + Chef::Log.debug("#{@new_resource.service_name} is a group") + @is_resource_group = true + elsif services[0].split(' ')[1] == @new_resource.service_name + Chef::Log.debug("#{@new_resource.service_name} is a group") + @is_resource_group = true + end end end end diff --git a/spec/unit/provider/service/aix_service_spec.rb b/spec/unit/provider/service/aix_service_spec.rb index 451eecfa2c..070f618b99 100644 --- a/spec/unit/provider/service/aix_service_spec.rb +++ b/spec/unit/provider/service/aix_service_spec.rb @@ -39,11 +39,77 @@ describe Chef::Provider::Service::Aix do Chef::Resource::Service.should_receive(:new).and_return(@current_resource) @current_resource.should_receive(:service_name).with("chef") @provider.should_receive(:determine_current_status!) - @provider.should_receive(:is_resource_group?) @provider.load_current_resource end + end + + describe "determine current status" do + context "when the service is active" do + before do + @status = double("Status", :exitstatus => 0, :stdout => "chef chef 12345 active\n") + end + + it "current resource is running" do + @provider.should_receive(:shell_out!).with("lssrc -a | grep -w chef").and_return(@status) + @provider.should_receive(:is_resource_group?).with(["chef chef 12345 active"]) + + @provider.load_current_resource + @current_resource.running.should be_true + end + end + context "when the service is inoprative" do + before do + @status = double("Status", :exitstatus => 0, :stdout => "chef chef inoperative\n") + end + + it "current resource is not running" do + @provider.should_receive(:shell_out!).with("lssrc -a | grep -w chef").and_return(@status) + @provider.should_receive(:is_resource_group?).with(["chef chef inoperative"]) + + @provider.load_current_resource + @current_resource.running.should be_false + end + end + end + + describe "is resource group" do + context "when there are mutiple subsystems associated with group" do + before do + @status = double("Status", :exitstatus => 0, :stdout => "chef1 chef 12345 active\nchef2 chef 12334 active\nchef3 chef inoperative") + end + + it "service is a group" do + @provider.should_receive(:shell_out!).with("lssrc -a | grep -w chef").and_return(@status) + @provider.load_current_resource + @provider.instance_eval("@is_resource_group").should be_true + end + end + + context "when there is a single subsystem in the group" do + before do + @status = double("Status", :exitstatus => 0, :stdout => "chef1 chef inoperative\n") + end + + it "service is a group" do + @provider.should_receive(:shell_out!).with("lssrc -a | grep -w chef").and_return(@status) + @provider.load_current_resource + @provider.instance_eval("@is_resource_group").should be_true + end + end + + context "when there service is a subsytem" do + before do + @status = double("Status", :exitstatus => 0, :stdout => "chef chef123 inoperative\n") + end + + it "service is a subsystem" do + @provider.should_receive(:shell_out!).with("lssrc -a | grep -w chef").and_return(@status) + @provider.load_current_resource + @provider.instance_eval("@is_resource_group").should be_false + end + end end describe "when starting the service" do |