diff options
author | Serdar Sutay <serdar@opscode.com> | 2014-10-21 11:14:19 -0700 |
---|---|---|
committer | Serdar Sutay <serdar@opscode.com> | 2014-10-21 11:14:19 -0700 |
commit | eeb45770585a50d78e412682b0ae44524e29e727 (patch) | |
tree | c1d2e00403722fa111e6bd01d2f56bc0ccabe790 /spec/functional | |
parent | ccb220a72ba07a9b2cbabba25f88edb7e7064d7b (diff) | |
parent | 09fbf4a6efacad4c635531b005dbc5832e8c03c8 (diff) | |
download | chef-eeb45770585a50d78e412682b0ae44524e29e727.tar.gz |
Merge pull request #2028 from ClogenyTechnologies/kd/aix-service
aix service provider
Diffstat (limited to 'spec/functional')
-rwxr-xr-x | spec/functional/assets/chefinittest | 34 | ||||
-rwxr-xr-x | spec/functional/assets/testchefsubsys | 11 | ||||
-rwxr-xr-x | spec/functional/resource/aix_service_spec.rb | 136 | ||||
-rwxr-xr-x | spec/functional/resource/aixinit_service_spec.rb | 211 |
4 files changed, 392 insertions, 0 deletions
diff --git a/spec/functional/assets/chefinittest b/spec/functional/assets/chefinittest new file mode 100755 index 0000000000..79e064cd5f --- /dev/null +++ b/spec/functional/assets/chefinittest @@ -0,0 +1,34 @@ +#!/bin/ksh + +function create_chef_txt { + touch /tmp/chefinittest.txt +} + +function delete_chef_txt { + rm /tmp/chefinittest.txt +} + +function rename_chef_txt { + mv /tmp/chefinittest.txt /tmp/$1 +} + +case "$1" in +start ) + create_chef_txt + ;; +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 ) + rename_chef_txt "chefinittest_restart.txt" + ;; +* ) + echo "Usage: $0 (start | stop | restart | reload)" + exit 1 +esac diff --git a/spec/functional/assets/testchefsubsys b/spec/functional/assets/testchefsubsys new file mode 100755 index 0000000000..e9ff30d4aa --- /dev/null +++ b/spec/functional/assets/testchefsubsys @@ -0,0 +1,11 @@ +#!/bin/bash +# trapchild + +sleep 120 & + +pid="$!" + +trap 'echo I am going down, so killing off my processes..; kill $pid; exit' SIGHUP SIGINT + SIGQUIT SIGTERM + +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 new file mode 100755 index 0000000000..6008fdea8f --- /dev/null +++ b/spec/functional/resource/aix_service_spec.rb @@ -0,0 +1,136 @@ +# encoding: UTF-8 +# +# Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>) +# Copyright:: Copyright (c) 2014 Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' +require 'functional/resource/base' +require 'chef/mixin/shell_out' + +shared_examples "src service" do + + include Chef::Mixin::ShellOut + + def service_should_be_started + expect(shell_out!("lssrc -a | grep #{new_resource.service_name}").stdout.split(' ').last).to eq("active") + end + + def service_should_be_stopped + expect(shell_out!("lssrc -a | grep #{new_resource.service_name}").stdout.split(' ').last).to eq("inoperative") + end + + def get_service_pid + args = shell_out!("lssrc -a | grep #{new_resource.service_name}").stdout.split(' ') + if args.length == 3 + args[1] + else + args[2] + end + end + + describe "start service" do + it "should start the service" do + new_resource.run_action(:start) + service_should_be_started + end + end + + describe "stop service" do + before do + new_resource.run_action(:start) + end + + it "should stop the service" do + new_resource.run_action(:stop) + 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_should_be_started + end + end +end + +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 + + 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 new file mode 100755 index 0000000000..a99309187c --- /dev/null +++ b/spec/functional/resource/aixinit_service_spec.rb @@ -0,0 +1,211 @@ +# encoding: UTF-8 +# +# Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>) +# Copyright:: Copyright (c) 2014 Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' +require 'functional/resource/base' +require 'chef/mixin/shell_out' +require 'fileutils' + +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 + end + + def service_should_be_stopped(file_name) + expect(File.exists?("/tmp/#{file_name}")).to be_false + end + + def valide_symlinks(expected_output, run_level = nil, status = nil, priority = nil) + directory = [] + if priority.is_a?Hash + priority.each do |level,o| + 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}" + end + expect(Dir.glob(directory)).to eq(expected_output) + File.delete(*directory) + end + + def delete_test_files + 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 + + let(:provider) do + provider = new_resource.provider_for_action(new_resource.action) + provider + end + + before(:all) do + 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") if File.exists?("/etc/rc.d/init.d/chefinittest") + end + + before(:each) do + delete_test_files + end + + after(:each) do + delete_test_files + end + + describe "start service" do + it "should start the service" do + new_resource.run_action(:start) + service_should_be_started("chefinittest.txt") + end + end + + describe "stop service" do + before do + new_resource.run_action(:start) + end + + it "should stop the service" do + new_resource.run_action(:stop) + 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_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_should_be_started("chefinittest_reload.txt") + end + end + + describe "enable service" do + + context "when the service doesn't set a priority" do + it "creates symlink with status S" do + new_resource.run_action(:enable) + valide_symlinks(["/etc/rc.d/rc2.d/Schefinittest"],2,'S') + end + end + + context "when the service sets a simple priority (integer)" do + before do + new_resource.priority(75) + end + + it "creates a symlink with status S and a priority" do + new_resource.run_action(:enable) + valide_symlinks(["/etc/rc.d/rc2.d/S75chefinittest"], 2,'S',75) + end + end + + context "when the service sets complex priorities (hash)" do + before do + priority = {2 => [:start, 20], 3 => [:stop, 10]} + new_resource.priority(priority) + end + + it "create symlink with status start (S) or stop (K) and a priority " do + new_resource.run_action(:enable) + 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 + File.delete("/etc/rc.d/rc2.d/Schefinittest") if File.exists?("/etc/rc.d/rc2.d/chefinittest") + end + + it "creates symlink with status K" do + new_resource.run_action(:disable) + 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) + File.symlink("/etc/rc.d/init.d/chefinittest", "/etc/rc.d/rc2.d/Schefinittest") + end + + after do + 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(: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) + File.symlink("/etc/rc.d/init.d/chefinittest", "/etc/rc.d/rc2.d/Schefinittest") + end + + after do + 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(:disable) + valide_symlinks(["/etc/rc.d/rc2.d/K80chefinittest"], 2,'K',80) + end + end + end +end
\ No newline at end of file |