summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2020-02-10 10:31:46 -0800
committerGitHub <noreply@github.com>2020-02-10 10:31:46 -0800
commita1a1887268ef04b8fdffb3ce0b9aa6c4d3e2412f (patch)
treec4a7a9f711e13ddd65f928ea20f9b762d7446541 /spec
parentec138c42552d11c228ed5456685a4552f7a66c6d (diff)
parentec177edf55504e56de1ba1319f5eca8351614e46 (diff)
downloadchef-a1a1887268ef04b8fdffb3ce0b9aa6c4d3e2412f.tar.gz
Merge pull request #8884 from robuye/debian-update-rcd
update syntax of `update-rc.d` commands in enable & disable actions
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/provider/service/debian_service_spec.rb171
1 files changed, 145 insertions, 26 deletions
diff --git a/spec/unit/provider/service/debian_service_spec.rb b/spec/unit/provider/service/debian_service_spec.rb
index 5f89605b2e..a69909107c 100644
--- a/spec/unit/provider/service/debian_service_spec.rb
+++ b/spec/unit/provider/service/debian_service_spec.rb
@@ -183,21 +183,21 @@ describe Chef::Provider::Service::Debian do
describe "enable_service" do
let(:service_name) { @new_resource.service_name }
context "when the service doesn't set a priority" do
- it "calls update-rc.d 'service_name' defaults" do
+ it "assumes default priority 20 and calls update-rc.d remove => defaults 20 80" do
expect_commands(@provider, [
"/usr/sbin/update-rc.d -f #{service_name} remove",
- "/usr/sbin/update-rc.d #{service_name} defaults",
+ "/usr/sbin/update-rc.d #{service_name} defaults 20 80",
])
@provider.enable_service
end
end
- context "when the service sets a simple priority" do
+ context "when the service sets a simple priority 75" do
before do
@new_resource.priority(75)
end
- it "calls update-rc.d 'service_name' defaults" do
+ it "calls update-rc.d remove => defaults 75 25" do
expect_commands(@provider, [
"/usr/sbin/update-rc.d -f #{service_name} remove",
"/usr/sbin/update-rc.d #{service_name} defaults 75 25",
@@ -206,45 +206,164 @@ describe Chef::Provider::Service::Debian do
end
end
- context "when the service sets complex priorities" do
+ context "when the service sets complex priorities using Hash" do
before do
@new_resource.priority(2 => [:start, 20], 3 => [:stop, 55])
end
- it "calls update-rc.d 'service_name' with those priorities" do
- expect_commands(@provider, [
- "/usr/sbin/update-rc.d -f #{service_name} remove",
- "/usr/sbin/update-rc.d #{service_name} start 20 2 . stop 55 3 . ",
- ])
- @provider.enable_service
+ context "when modern update-rc.d is detected" do
+ before do
+ expect(@provider).to receive(:use_legacy_update_rc_d?).and_return(false)
+ end
+
+ it "calls update-rc.d remove => defaults => enable|disable <runlevel>" do
+ expect_commands(@provider, [
+ "/usr/sbin/update-rc.d -f #{service_name} remove",
+ "/usr/sbin/update-rc.d #{service_name} defaults",
+ "/usr/sbin/update-rc.d #{service_name} enable 2",
+ "/usr/sbin/update-rc.d #{service_name} disable 3",
+ ])
+ @provider.enable_service
+ end
+ end
+
+ context "when legacy update-rc.d is detected" do
+ before do
+ expect(@provider).to receive(:use_legacy_update_rc_d?).and_return(true)
+ end
+
+ it "calls update-rc.d remove => start|stop <priority> <levels> ." do
+ expect_commands(@provider, [
+ "/usr/sbin/update-rc.d -f #{service_name} remove",
+ "/usr/sbin/update-rc.d #{service_name} start 20 2 . stop 55 3 . ",
+ ])
+ @provider.disable_service
+ end
end
end
end
describe "disable_service" do
let(:service_name) { @new_resource.service_name }
- context "when the service doesn't set a priority" do
- it "calls update-rc.d -f 'service_name' remove + stop with default priority" do
- expect_commands(@provider, [
- "/usr/sbin/update-rc.d -f #{service_name} remove",
- "/usr/sbin/update-rc.d -f #{service_name} stop 80 2 3 4 5 .",
- ])
- @provider.disable_service
+
+ context "when modern update-rc.d is detected" do
+ before do
+ expect(@provider).to receive(:use_legacy_update_rc_d?).and_return(false)
+ end
+
+ context "when the service doesn't set a priority" do
+ it "calls update-rc.d remove => defaults => disable" do
+ expect_commands(@provider, [
+ "/usr/sbin/update-rc.d -f #{service_name} remove",
+ "/usr/sbin/update-rc.d #{service_name} defaults",
+ "/usr/sbin/update-rc.d #{service_name} disable",
+ ])
+ @provider.disable_service
+ end
+ end
+
+ context "when the service sets a simple priority 75" do
+ before do
+ @new_resource.priority(75)
+ end
+
+ it "ignores priority and calls update-rc.d remove => defaults => disable" do
+ expect_commands(@provider, [
+ "/usr/sbin/update-rc.d -f #{service_name} remove",
+ "/usr/sbin/update-rc.d #{service_name} defaults",
+ "/usr/sbin/update-rc.d #{service_name} disable",
+ ])
+ @provider.disable_service
+ end
+ end
+
+ context "when the service sets complex priorities using Hash" do
+ before do
+ @new_resource.priority(2 => [:start, 20], 3 => [:stop, 55])
+ end
+
+ it "ignores priority and calls update-rc.d remove => defaults => enable|disable <runlevel>" do
+ expect_commands(@provider, [
+ "/usr/sbin/update-rc.d -f #{service_name} remove",
+ "/usr/sbin/update-rc.d #{service_name} defaults",
+ "/usr/sbin/update-rc.d #{service_name} enable 2",
+ "/usr/sbin/update-rc.d #{service_name} disable 3",
+ ])
+ @provider.disable_service
+ end
end
end
- context "when the service sets a simple priority" do
+ context "when legacy update-rc.d is detected" do
before do
- @new_resource.priority(75)
+ expect(@provider).to receive(:use_legacy_update_rc_d?).and_return(true)
end
- it "calls update-rc.d -f 'service_name' remove + stop with the specified priority" do
- expect_commands(@provider, [
- "/usr/sbin/update-rc.d -f #{service_name} remove",
- "/usr/sbin/update-rc.d -f #{service_name} stop #{100 - @new_resource.priority} 2 3 4 5 .",
- ])
- @provider.disable_service
+ context "when the service doesn't set a priority" do
+ it "assumes default priority 20 and calls update-rc.d remove => stop 80 2 3 4 5 ." do
+ expect_commands(@provider, [
+ "/usr/sbin/update-rc.d -f #{service_name} remove",
+ "/usr/sbin/update-rc.d -f #{service_name} stop 80 2 3 4 5 .",
+ ])
+ @provider.disable_service
+ end
+ end
+
+ context "when the service sets a simple priority 75" do
+ before do
+ @new_resource.priority(75)
+ end
+
+ it "reverses priority and calls update-rc.d remove => stop 25 2 3 4 5 ." do
+ expect_commands(@provider, [
+ "/usr/sbin/update-rc.d -f #{service_name} remove",
+ "/usr/sbin/update-rc.d -f #{service_name} stop #{100 - @new_resource.priority} 2 3 4 5 .",
+ ])
+ @provider.disable_service
+ end
end
+
+ context "when the service sets complex priorities using Hash" do
+ before do
+ @new_resource.priority(2 => [:start, 20], 3 => [:stop, 55])
+ end
+
+ it "calls update-rc.d remove => start|stop <priority> <levels> ." do
+ expect_commands(@provider, [
+ "/usr/sbin/update-rc.d -f #{service_name} remove",
+ "/usr/sbin/update-rc.d #{service_name} start 20 2 . stop 55 3 . ",
+ ])
+ @provider.disable_service
+ end
+ end
+ end
+ end
+
+ describe "use_legacy_update_rc_d?" do
+ let(:dpkg_query_cmd) { "dpkg-query -W --showformat '${Version}' sysv-rc" }
+
+ it "is true when svsv-rc package version < 2.88 is installed" do
+ shellout_result = double(stdout: "2.86.ds1-34\n")
+ expect(@provider).to receive(:shell_out!).with(dpkg_query_cmd).and_return(shellout_result)
+ expect(@provider.use_legacy_update_rc_d?).to eq(true)
+ end
+
+ it "is true when sysv-rc is 2.88 and patch level < ('dsf-')42" do
+ shellout_result = double(stdout: "2.88.dsf-41\n")
+ expect(@provider).to receive(:shell_out!).with(dpkg_query_cmd).and_return(shellout_result)
+ expect(@provider.use_legacy_update_rc_d?).to eq(true)
+ end
+
+ it "is false when sysv-rc package version >= 2.88 is installed" do
+ shellout_result = double(stdout: "2.88dsf-59.9\n")
+ expect(@provider).to receive(:shell_out!).with(dpkg_query_cmd).and_return(shellout_result)
+ expect(@provider.use_legacy_update_rc_d?).to eq(false)
+ end
+
+ it "is false when sysv-rc package is not installed" do
+ shellout_result = double(stdout: "\n")
+ expect(@provider).to receive(:shell_out!).with(dpkg_query_cmd).and_return(shellout_result)
+ expect(@provider.use_legacy_update_rc_d?).to eq(false)
end
end
end