|
38 | 38 | File.should_receive(:exists?).with("/usr/sbin/update-rc.d").and_return(false) |
39 | 39 | lambda { @provider.assert_update_rcd_available }.should raise_error(Chef::Exceptions::Service) |
40 | 40 | end |
41 | | - |
42 | | - describe "when update-rc.d shows the init script linked to rc*.d/" do |
| 41 | + |
| 42 | + describe "when using squeeze/earlier and update-rc.d shows the init script linked to rc*.d/" do |
43 | 43 | before do |
44 | 44 | @provider.stub!(:run_command) |
45 | 45 | @provider.stub!(:assert_update_rcd_available) |
46 | 46 | @status = mock("Status", :exitstatus => 0) |
47 | | - |
48 | | - result=<<-UPDATE_RC_D_SUCCESS |
49 | | -update-rc.d: using dependency based boot sequencing |
| 47 | + |
| 48 | + @stdout = StringIO.new("update-rc.d: using dependency based boot sequencing") |
| 49 | + result2=<<-UPDATE_RC_D_SUCCESS |
50 | 50 | insserv: remove service /etc/init.d/../rc0.d/K20chef-client |
51 | 51 | insserv: remove service /etc/init.d/../rc1.d/K20chef-client |
52 | 52 | insserv: remove service /etc/init.d/../rc2.d/S20chef-client |
53 | 53 | insserv: remove service /etc/init.d/../rc3.d/S20chef-client |
54 | 54 | insserv: remove service /etc/init.d/../rc4.d/S20chef-client |
55 | 55 | insserv: remove service /etc/init.d/../rc5.d/S20chef-client |
56 | 56 | insserv: remove service /etc/init.d/../rc6.d/K20chef-client |
57 | | - UPDATE_RC_D_SUCCESS |
58 | | - @stdout = StringIO.new(result) |
59 | | - @stderr = StringIO.new(result) |
| 57 | +insserv: dryrun, not creating .depend.boot, .depend.start, and .depend.stop |
| 58 | +UPDATE_RC_D_SUCCESS |
| 59 | + @stderr = StringIO.new(result2) |
60 | 60 | @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) |
61 | 61 | end |
62 | 62 |
|
63 | 63 | it "says the service is enabled" do |
64 | 64 | @provider.service_currently_enabled?.should be_true |
65 | 65 | end |
66 | | - |
| 66 | + |
67 | 67 | it "stores the 'enabled' state" do |
68 | 68 | Chef::Resource::Service.stub!(:new).and_return(@current_resource) |
69 | 69 | @provider.load_current_resource.should equal(@current_resource) |
|
81 | 81 | "5"=>[:start, "20"]} |
82 | 82 | @provider.current_resource.priority.should == expected_priorities |
83 | 83 | end |
84 | | - |
85 | 84 | end |
86 | 85 |
|
87 | | - describe "when update-rc.d shows the init script isn't linked to rc*.d" do |
| 86 | + describe "when using squeeze/earlier and update-rc.d shows the init script isn't linked to rc*.d" do |
88 | 87 | before do |
89 | 88 | @provider.stub!(:run_command) |
90 | 89 | @provider.stub!(:assert_update_rcd_available) |
91 | 90 | @status = mock("Status", :exitstatus => 0) |
92 | | - result = "update-rc.d: using dependency based boot sequencing" |
| 91 | + @stdout = StringIO.new("update-rc.d: using dependency based boot sequencing") |
| 92 | + @stderr = StringIO.new("") |
| 93 | + @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) |
| 94 | + end |
| 95 | + |
| 96 | + it "says the service is disabled" do |
| 97 | + @provider.service_currently_enabled?.should be_false |
| 98 | + end |
| 99 | + |
| 100 | + it "stores the 'disabled' state" do |
| 101 | + Chef::Resource::Service.stub!(:new).and_return(@current_resource) |
| 102 | + @provider.load_current_resource.should equal(@current_resource) |
| 103 | + @current_resource.enabled.should be_false |
| 104 | + end |
| 105 | + end |
| 106 | + |
| 107 | + describe "when using lenny/older and update-rc.d shows the init script linked to rc*.d/" do |
| 108 | + before do |
| 109 | + @provider.stub!(:run_command) |
| 110 | + @provider.stub!(:assert_update_rcd_available) |
| 111 | + @status = mock("Status", :exitstatus => 0) |
| 112 | + |
| 113 | + result=<<-UPDATE_RC_D_SUCCESS |
| 114 | + Removing any system startup links for /etc/init.d/chef ... |
| 115 | + /etc/rc0.d/K20chef |
| 116 | + /etc/rc1.d/K20chef |
| 117 | + /etc/rc2.d/S20chef |
| 118 | + /etc/rc3.d/S20chef |
| 119 | + /etc/rc4.d/S20chef |
| 120 | + /etc/rc5.d/S20chef |
| 121 | + /etc/rc6.d/K20chef |
| 122 | +UPDATE_RC_D_SUCCESS |
93 | 123 | @stdout = StringIO.new(result) |
94 | | - @stderr = StringIO.new(result) |
| 124 | + @stderr = StringIO.new("") |
| 125 | + @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) |
| 126 | + end |
| 127 | + |
| 128 | + it "says the service is enabled" do |
| 129 | + @provider.service_currently_enabled?.should be_true |
| 130 | + end |
| 131 | + |
| 132 | + it "stores the 'enabled' state" do |
| 133 | + Chef::Resource::Service.stub!(:new).and_return(@current_resource) |
| 134 | + @provider.load_current_resource.should equal(@current_resource) |
| 135 | + @current_resource.enabled.should be_true |
| 136 | + end |
| 137 | + |
| 138 | + it "stores the start/stop priorities of the service" do |
| 139 | + @provider.load_current_resource |
| 140 | + expected_priorities = {"6"=>[:stop, "20"], |
| 141 | + "0"=>[:stop, "20"], |
| 142 | + "1"=>[:stop, "20"], |
| 143 | + "2"=>[:start, "20"], |
| 144 | + "3"=>[:start, "20"], |
| 145 | + "4"=>[:start, "20"], |
| 146 | + "5"=>[:start, "20"]} |
| 147 | + @provider.current_resource.priority.should == expected_priorities |
| 148 | + end |
| 149 | + end |
| 150 | + |
| 151 | + describe "when using lenny/older and update-rc.d shows the init script isn't linked to rc*.d" do |
| 152 | + before do |
| 153 | + @provider.stub!(:run_command) |
| 154 | + @provider.stub!(:assert_update_rcd_available) |
| 155 | + @status = mock("Status", :exitstatus => 0) |
| 156 | + @stdout = StringIO.new(" Removing any system startup links for /etc/init.d/chef ...") |
| 157 | + @stderr = StringIO.new("") |
95 | 158 | @provider.stub!(:popen4).and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) |
96 | 159 | end |
97 | 160 |
|
|
105 | 168 | @current_resource.enabled.should be_false |
106 | 169 | end |
107 | 170 | end |
108 | | - |
| 171 | + |
109 | 172 | describe "when update-rc.d fails" do |
110 | 173 | before do |
111 | 174 | @status = mock("Status", :exitstatus => -1) |
|
115 | 178 | it "raises an error" do |
116 | 179 | lambda { @provider.service_currently_enabled? }.should raise_error(Chef::Exceptions::Service) |
117 | 180 | end |
118 | | - |
119 | 181 | end |
120 | 182 |
|
121 | 183 | describe "when enabling a service without priority" do |
|
148 | 210 | end |
149 | 211 |
|
150 | 212 | describe "when disabling a service" do |
151 | | - |
152 | 213 | it "should call update-rc.d 'service_name' disable" do |
153 | 214 | @provider.should_receive(:run_command).with({:command => "/usr/sbin/update-rc.d #{@new_resource.service_name} disable"}) |
154 | 215 | @provider.disable_service() |
|
0 commit comments