Skip to content

Commit fa39504

Browse files
Lee JensenLee Jensen
authored andcommitted
fixes chef-33, adds support for gentoo
1 parent 192484c commit fa39504

3 files changed

Lines changed: 144 additions & 1 deletion

File tree

chef/lib/chef/platform.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ class Platform
3838
:redhat => {},
3939
:gentoo => {
4040
:default => {
41-
:package => Chef::Provider::Package::Portage
41+
:package => Chef::Provider::Package::Portage,
42+
:service => Chef::Provider::Service::Gentoo
4243
}
4344
},
4445
:solaris => {},
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#
2+
# Author:: Lee Jensen (<ljensen@engineyard.com>)
3+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
4+
# License:: Apache License, Version 2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
require 'chef/provider/service'
20+
require 'chef/mixin/command'
21+
22+
class Chef
23+
class Provider
24+
class Service
25+
class Gentoo < Chef::Provider::Service::Init
26+
def load_current_resource
27+
super
28+
29+
raise Chef::Exception::Service unless ::File.exists?("/sbin/rc-update")
30+
31+
IO.popen('/sbin/rc-update -s default') do |io|
32+
io.each_line do |line|
33+
if line.match(/^\s*#{@current_resource.service_name}\s+/)
34+
@current_resource.enabled true
35+
end
36+
end
37+
end
38+
39+
@current_resource
40+
end
41+
42+
def enable_service(name)
43+
run_command(:command => "/sbin/rc-update add #{name} default")
44+
end
45+
46+
def disable_service(name)
47+
run_command(:command => "/sbin/rc-update del #{name} default")
48+
end
49+
end
50+
end
51+
end
52+
end
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#
2+
# Author:: Lee Jensen (<ljensen@engineyard.com>)
3+
# Copyright:: Copyright (c) 2008 Opscode, Inc.
4+
# License:: Apache License, Version 2.0
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "spec_helper"))
20+
21+
describe Chef::Provider::Service::Gentoo do
22+
before(:each) do
23+
@node = mock("Chef::Node", :null_object => true)
24+
25+
resource_opts = { :null_object => true, :name => 'chef', :service_name => 'chef', :enabled => false, :running => nil }
26+
@new_resource = mock("Chef::Resource::Service", resource_opts)
27+
@current_resource = mock("Chef::Resource::Service", resource_opts)
28+
29+
@provider = Chef::Provider::Service::Gentoo.new(@node, @new_resource)
30+
Chef::Resource::Service.stub!(:new).and_return(@current_resource)
31+
File.stub!(:exists?).and_return(true)
32+
33+
@io = mock("IO")
34+
IO.stub!(:popen).and_return(@io)
35+
@io.stub!(:each_line).and_yield(" gfs | default ")
36+
end
37+
38+
describe "load_current_resource" do
39+
it "should raise Chef::Exception::Service if /sbin/rc-update does not exist" do
40+
File.should_receive(:exists?).with("/sbin/rc-update").and_return(false)
41+
lambda { @provider.load_current_resource }.should raise_error(Chef::Exception::Service)
42+
end
43+
44+
it "should set enabled true if rc-update indicates service is in default runlevel" do
45+
IO.should_receive(:popen).with("/sbin/rc-update -s default").and_yield(@io)
46+
@io.should_receive(:each_line).
47+
and_yield(' gfs | default ').
48+
and_yield(' chef | default ').
49+
and_yield('monit | default ').
50+
and_yield('mysql | default ')
51+
52+
@current_resource.should_receive(:enabled).with(true)
53+
@provider.load_current_resource
54+
end
55+
56+
it "should set enabled false if rc-update indicates service is not in default runlevel" do
57+
IO.should_receive(:popen).with("/sbin/rc-update -s default").and_yield(@io)
58+
@io.should_receive(:each_line).
59+
and_yield(' gfs | default ').
60+
and_yield('notchef | default ').
61+
and_yield(' monit | default ').
62+
and_yield(' mysql | default ')
63+
64+
@provider.load_current_resource
65+
@current_resource.enabled.should be_false
66+
end
67+
68+
it "should return the current_resource" do
69+
@provider.load_current_resource.should == @current_resource
70+
end
71+
end
72+
73+
describe "action_methods" do
74+
before(:each) { @provider.stub!(:load_current_resource).and_return(@current_resource) }
75+
76+
describe Chef::Provider::Service::Gentoo, "enable_service" do
77+
it "should call rc-update add *service* default" do
78+
@provider.should_receive(:run_command).with({:command => "/sbin/rc-update add chef default"})
79+
@provider.enable_service('chef')
80+
end
81+
end
82+
83+
describe Chef::Provider::Service::Gentoo, "disable_service" do
84+
it "should call rc-update del *service* default" do
85+
@provider.should_receive(:run_command).with({:command => "/sbin/rc-update del chef default"})
86+
@provider.disable_service('chef')
87+
end
88+
end
89+
end
90+
end

0 commit comments

Comments
 (0)