summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkaustubh-d <kaustubh@clogeny.com>2014-09-23 14:47:48 +0530
committerkaustubh-d <kaustubh@clogeny.com>2014-09-23 14:47:48 +0530
commit09fbf4a6efacad4c635531b005dbc5832e8c03c8 (patch)
treee02b421b2dfb99d2a6618c5e6e06e246218f8a36
parent36aca4d584cba3600789e0668aaa7eb67dfa84c5 (diff)
downloadchef-09fbf4a6efacad4c635531b005dbc5832e8c03c8.tar.gz
fixed functional tests
-rw-r--r--lib/chef/provider/service/aixinit.rb8
-rwxr-xr-xspec/functional/assets/chefinittest5
-rwxr-xr-xspec/functional/assets/testchefsubsys20
-rwxr-xr-xspec/functional/resource/aix_service_spec.rb109
-rwxr-xr-xspec/functional/resource/aixinit_service_spec.rb90
-rw-r--r--spec/spec_helper.rb1
6 files changed, 137 insertions, 96 deletions
diff --git a/lib/chef/provider/service/aixinit.rb b/lib/chef/provider/service/aixinit.rb
index f4ef2163a6..ab4b8e5406 100644
--- a/lib/chef/provider/service/aixinit.rb
+++ b/lib/chef/provider/service/aixinit.rb
@@ -57,7 +57,7 @@ class Chef
end
def enable_service
- Dir.glob(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).each { |f| File.delete(f)}
+ Dir.glob(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).each { |f| ::File.delete(f)}
if @new_resource.priority.is_a? Integer
create_symlink(2, 'S', @new_resource.priority)
@@ -72,7 +72,7 @@ class Chef
end
def disable_service
- Dir.glob(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).each { |f| File.delete(f) }
+ Dir.glob(["/etc/rc.d/rc2.d/[SK][0-9][0-9]#{@new_resource.service_name}", "/etc/rc.d/rc2.d/[SK]#{@new_resource.service_name}"]).each { |f| ::File.delete(f) }
if @new_resource.priority.is_a? Integer
create_symlink(2, 'K',100 - @new_resource.priority)
@@ -86,7 +86,7 @@ class Chef
end
def create_symlink(run_level, status, priority)
- File.symlink("/etc/rc.d/init.d/#{@new_resource.service_name}", "/etc/rc.d/rc#{run_level}.d/#{status}#{priority}#{@new_resource.service_name}")
+ ::File.symlink("/etc/rc.d/init.d/#{@new_resource.service_name}", "/etc/rc.d/rc#{run_level}.d/#{status}#{priority}#{@new_resource.service_name}")
end
def set_current_resource_attributes
@@ -114,4 +114,4 @@ class Chef
end
end
end
-end
+end \ No newline at end of file
diff --git a/spec/functional/assets/chefinittest b/spec/functional/assets/chefinittest
index e7a0cdb744..79e064cd5f 100755
--- a/spec/functional/assets/chefinittest
+++ b/spec/functional/assets/chefinittest
@@ -19,12 +19,13 @@ start )
stop )
delete_chef_txt
;;
+status )
+ [ -f /tmp/chefinittest.txt ] || [ -f /tmp/chefinittest_reload.txt ] || [ -f /tmp/chefinittest_restart.txt ]
+ ;;
reload )
rename_chef_txt "chefinittest_reload.txt"
;;
restart )
- delete_chef_txt
- create_chef_txt
rename_chef_txt "chefinittest_restart.txt"
;;
* )
diff --git a/spec/functional/assets/testchefsubsys b/spec/functional/assets/testchefsubsys
index b7a0ae17ab..e9ff30d4aa 100755
--- a/spec/functional/assets/testchefsubsys
+++ b/spec/functional/assets/testchefsubsys
@@ -1,17 +1,11 @@
-#!/bin/ksh
+#!/bin/bash
+# trapchild
+sleep 120 &
-trap "" HUP INT QUIT TSTP STOP
-trap "shutdown_ss" TERM
+pid="$!"
-shutdown_ss ()
-{
- echo "Shutting down script..." >> /tmp/testchefsubsystem.log
- exit
-}
+trap 'echo I am going down, so killing off my processes..; kill $pid; exit' SIGHUP SIGINT
+ SIGQUIT SIGTERM
-while true
-do
- echo "Iterating..." >> /tmp/testchefsubsystem.log
- sleep 10
-done
+wait \ No newline at end of file
diff --git a/spec/functional/resource/aix_service_spec.rb b/spec/functional/resource/aix_service_spec.rb
index c566c16ec5..6008fdea8f 100755
--- a/spec/functional/resource/aix_service_spec.rb
+++ b/spec/functional/resource/aix_service_spec.rb
@@ -17,18 +17,19 @@
# limitations under the License.
#
+require 'spec_helper'
require 'functional/resource/base'
require 'chef/mixin/shell_out'
-describe Chef::Resource::Service::Aix, :requires_root, :aix_only do
+shared_examples "src service" do
include Chef::Mixin::ShellOut
- def service_started?
+ def service_should_be_started
expect(shell_out!("lssrc -a | grep #{new_resource.service_name}").stdout.split(' ').last).to eq("active")
end
- def service_stopped?
+ def service_should_be_stopped
expect(shell_out!("lssrc -a | grep #{new_resource.service_name}").stdout.split(' ').last).to eq("inoperative")
end
@@ -41,57 +42,95 @@ describe Chef::Resource::Service::Aix, :requires_root, :aix_only do
end
end
- # Actual tests
- let(:new_resource) do
- new_resource = Chef::Resource::Service.new("testchefsubsys", run_context)
- new_resource
- end
-
- let(:provider) do
- provider = new_resource.provider_for_action(new_resource.action)
- provider
- end
-
- before(:all) do
- script_dir = File.join(File.dirname(__FILE__), "/../assets/")
- shell_out!("mkssys -s testchefsubsys -p #{script_dir}/testchefsubsys -u 0 -S -n 15 -f 9 -R -Q")
- end
-
- after(:all) do
- shell_out!("rmssys -s testchefsubsys")
- end
-
describe "start service" do
it "should start the service" do
new_resource.run_action(:start)
- service_started?
+ service_should_be_started
end
end
describe "stop service" do
- it "should stop the service" do
+ before do
+ new_resource.run_action(:start)
+ end
+
+ it "should stop the service" do
new_resource.run_action(:stop)
- service_stopped?
+ service_should_be_stopped
end
end
describe "restart service" do
+ before do
+ new_resource.run_action(:start)
+ end
+
it "should restart the service" do
new_resource.run_action(:restart)
- service_started?
+ service_should_be_started
end
end
+end
- describe "reload service" do
- before do
- new_resource.run_action(:start)
- @current_pid = get_service_pid
+describe Chef::Resource::Service, :requires_root, :aix_only do
+ def get_user_id
+ shell_out("id -u #{ENV['USER']}").stdout.chomp
+ end
+
+ describe "When service is a subsystem" do
+ before(:all) do
+ script_dir = File.join(File.dirname(__FILE__), "/../assets/")
+ shell_out!("mkssys -s ctestsys -p #{script_dir}/testchefsubsys -u #{get_user_id} -S -n 15 -f 9 -R -Q")
end
- it "should reload the service" do
- new_resource.run_action(:reload)
- service_started?
- expect(get_service_pid).not_to eq(@current_pid)
+ after(:each) do
+ shell_out("stopsrc -s ctestsys")
end
+
+ after(:all) do
+ shell_out!("rmssys -s ctestsys")
+ end
+
+
+ let(:new_resource) do
+ new_resource = Chef::Resource::Service.new("ctestsys", run_context)
+ new_resource
+ end
+
+ let(:provider) do
+ provider = new_resource.provider_for_action(new_resource.action)
+ provider
+ end
+
+ it_behaves_like "src service"
+ end
+
+
+ describe "When service is a group" do
+ before(:all) do
+ script_dir = File.join(File.dirname(__FILE__), "/../assets/")
+ shell_out!("mkssys -s ctestsys -p #{script_dir}/testchefsubsys -u #{get_user_id} -S -n 15 -f 9 -R -Q -G ctestgrp")
+ end
+
+ after(:each) do
+ shell_out("stopsrc -g ctestgrp")
+ end
+
+ after(:all) do
+ # rmssys supports only -s option.
+ shell_out!("rmssys -s ctestsys")
+ end
+
+ let(:new_resource) do
+ new_resource = Chef::Resource::Service.new("ctestgrp", run_context)
+ new_resource
+ end
+
+ let(:provider) do
+ provider = new_resource.provider_for_action(new_resource.action)
+ provider
+ end
+
+ it_behaves_like "src service"
end
end
diff --git a/spec/functional/resource/aixinit_service_spec.rb b/spec/functional/resource/aixinit_service_spec.rb
index 42422117fd..a99309187c 100755
--- a/spec/functional/resource/aixinit_service_spec.rb
+++ b/spec/functional/resource/aixinit_service_spec.rb
@@ -17,46 +17,49 @@
# limitations under the License.
#
+require 'spec_helper'
require 'functional/resource/base'
require 'chef/mixin/shell_out'
require 'fileutils'
-describe Chef::Resource::Service::Aixinit, :requires_root, :aix_only do
+describe Chef::Resource::Service, :requires_root, :aix_only do
include Chef::Mixin::ShellOut
# Platform specific validation routines.
def service_should_be_started(file_name)
# The existance of this file indicates that the service was started.
- expect(File.exists("/tmp/#{file_name}").to be_true
+ expect(File.exists?("/tmp/#{file_name}")).to be_true
end
def service_should_be_stopped(file_name)
- expect(File.exists("/tmp/#{file_name}").to be_false
+ expect(File.exists?("/tmp/#{file_name}")).to be_false
end
- def search_symlinks(run_level = nil, status = nil, priority = nil)
+ def valide_symlinks(expected_output, run_level = nil, status = nil, priority = nil)
directory = []
if priority.is_a?Hash
priority.each do |level,o|
- search_directory << "/etc/rc.d/rc#{level}.d/#{(o[0] == :start ? 'S' : 'K')}#{o[1]}#{new_resource.service_name}"
+ directory << "/etc/rc.d/rc#{level}.d/#{(o[0] == :start ? 'S' : 'K')}#{o[1]}#{new_resource.service_name}"
end
directory
else
- directory << "/etc/rc.d/rc#{run_level}.d/#{status}#{priority}#{new_resource.service_name}"]
+ directory << "/etc/rc.d/rc#{run_level}.d/#{status}#{priority}#{new_resource.service_name}"
end
+ expect(Dir.glob(directory)).to eq(expected_output)
File.delete(*directory)
-
end
def delete_test_files
- files = Dir.glob(Dir.glob("/tmp/chefinittest[a-z_]*.txt"))
+ files = Dir.glob("/tmp/chefinit[a-z_]*.txt")
File.delete(*files)
end
# Actual tests
let(:new_resource) do
new_resource = Chef::Resource::Service.new("chefinittest", run_context)
+ new_resource.provider Chef::Provider::Service::AixInit
+ new_resource.supports({:status => true, :restart => true, :reload => true})
new_resource
end
@@ -66,12 +69,12 @@ describe Chef::Resource::Service::Aixinit, :requires_root, :aix_only do
end
before(:all) do
- File.delete("/etc/rc.d/init.d/chefinittest")
- FileUtils.cp("../assets/chefinittest", "/etc/rc.d/init.d/chefinittest")
+ File.delete("/etc/rc.d/init.d/chefinittest") if File.exists?("/etc/rc.d/init.d/chefinittest")
+ FileUtils.cp("#{File.join(File.dirname(__FILE__), "/../assets/chefinittest")}", "/etc/rc.d/init.d/chefinittest")
end
after(:all) do
- File.delete("/etc/rc.d/init.d/chefinittest")
+ File.delete("/etc/rc.d/init.d/chefinittest") if File.exists?("/etc/rc.d/init.d/chefinittest")
end
before(:each) do
@@ -85,7 +88,7 @@ describe Chef::Resource::Service::Aixinit, :requires_root, :aix_only do
describe "start service" do
it "should start the service" do
new_resource.run_action(:start)
- service_started?("chef.txt")
+ service_should_be_started("chefinittest.txt")
end
end
@@ -96,34 +99,38 @@ describe Chef::Resource::Service::Aixinit, :requires_root, :aix_only do
it "should stop the service" do
new_resource.run_action(:stop)
- service_stopped?("chef.txt")
+ service_should_be_stopped("chefinittest.txt")
end
end
describe "restart service" do
+ before do
+ new_resource.run_action(:start)
+ end
+
it "should restart the service" do
new_resource.run_action(:restart)
- service_started?("chef_restart.txt")
+ service_should_be_started("chefinittest_restart.txt")
end
end
describe "reload service" do
+ before do
+ new_resource.run_action(:start)
+ end
+
it "should reload the service" do
new_resource.run_action(:reload)
- service_started?("chef_reload.txt")
+ service_should_be_started("chefinittest_reload.txt")
end
end
describe "enable service" do
context "when the service doesn't set a priority" do
- after do
- delete_files(search_symlinks(2,'S'))
- end
-
it "creates symlink with status S" do
new_resource.run_action(:enable)
- expect(Dir.glob(search_symlinks(2,'S'))).to eq(["/etc/rc.d/rc2.d/Schef"])
+ valide_symlinks(["/etc/rc.d/rc2.d/Schefinittest"],2,'S')
end
end
@@ -132,13 +139,9 @@ describe Chef::Resource::Service::Aixinit, :requires_root, :aix_only do
new_resource.priority(75)
end
- after do
- delete_files(search_symlinks(2,'S',75))
- end
-
it "creates a symlink with status S and a priority" do
new_resource.run_action(:enable)
- expect(Dir.glob(search_symlinks(2,'S',75))).to eq(["/etc/rc.d/rc2.d/S75chef"])
+ valide_symlinks(["/etc/rc.d/rc2.d/S75chefinittest"], 2,'S',75)
end
end
@@ -148,58 +151,61 @@ describe Chef::Resource::Service::Aixinit, :requires_root, :aix_only do
new_resource.priority(priority)
end
- after do
- delete_files(search_symlinks(2,'S',new_resource.priority))
- end
-
it "create symlink with status start (S) or stop (K) and a priority " do
new_resource.run_action(:enable)
- expect(Dir.glob(search_symlinks(2,'S',new_resource.priority))).to eq(["/etc/rc.d/rc2.d/S20chef", "/etc/rc.d/rc3.d/K10chef"])
+ valide_symlinks(["/etc/rc.d/rc2.d/S20chefinittest", "/etc/rc.d/rc3.d/K10chefinittest"], 2,'S',new_resource.priority)
end
end
end
describe "disable_service" do
+
context "when the service doesn't set a priority" do
+ before do
+ File.symlink("/etc/rc.d/init.d/chefinittest", "/etc/rc.d/rc2.d/Schefinittest")
+ end
+
after do
- delete_files(search_symlinks(2,'S'))
+ File.delete("/etc/rc.d/rc2.d/Schefinittest") if File.exists?("/etc/rc.d/rc2.d/chefinittest")
end
- it "creates symlink with status S" do
+ it "creates symlink with status K" do
new_resource.run_action(:disable)
- expect(Dir.glob(search_symlinks(2,'K'))).to eq(["/etc/rc.d/rc2.d/Kchef"])
+ valide_symlinks(["/etc/rc.d/rc2.d/Kchefinittest"], 2,'K')
end
end
context "when the service sets a simple priority (integer)" do
before do
- @new_resource.priority(75)
+ new_resource.priority(75)
+ File.symlink("/etc/rc.d/init.d/chefinittest", "/etc/rc.d/rc2.d/Schefinittest")
end
after do
- delete_files(search_symlinks(2,'K',25))
+ File.delete("/etc/rc.d/rc2.d/Schefinittest") if File.exists?("/etc/rc.d/rc2.d/chefinittest")
end
it "creates a symlink with status K and a priority" do
- new_resource.run_action(:enable)
- expect(Dir.glob(search_symlinks(2,'K',25))).to eq(["/etc/rc.d/rc2.d/K25chef"])
+ new_resource.run_action(:disable)
+ valide_symlinks(["/etc/rc.d/rc2.d/K25chefinittest"], 2,'K',25)
end
end
context "when the service sets complex priorities (hash)" do
before do
@priority = {2 => [:stop, 20], 3 => [:start, 10]}
- @new_resource.priority(@priority)
+ new_resource.priority(@priority)
+ File.symlink("/etc/rc.d/init.d/chefinittest", "/etc/rc.d/rc2.d/Schefinittest")
end
after do
- delete_files(search_symlinks(2,'k',80))
+ File.delete("/etc/rc.d/rc2.d/Schefinittest") if File.exists?("/etc/rc.d/rc2.d/chefinittest")
end
it "create symlink with status stop (K) and a priority " do
- new_resource.run_action(:enable)
- expect(Dir.glob(search_symlinks(2,'K',80))).to eq(["/etc/rc.d/rc2.d/K80chef"])
+ new_resource.run_action(:disable)
+ valide_symlinks(["/etc/rc.d/rc2.d/K80chefinittest"], 2,'K',80)
end
end
end
-end
+end \ No newline at end of file
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 7c11957997..29e32a395c 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -113,6 +113,7 @@ RSpec.configure do |config|
config.filter_run_excluding :solaris_only => true unless solaris?
config.filter_run_excluding :system_windows_service_gem_only => true unless system_windows_service_gem?
config.filter_run_excluding :unix_only => true unless unix?
+ config.filter_run_excluding :aix_only => true unless aix?
config.filter_run_excluding :supports_cloexec => true unless supports_cloexec?
config.filter_run_excluding :selinux_only => true unless selinux_enabled?
config.filter_run_excluding :ruby_18_only => true unless ruby_18?