summaryrefslogtreecommitdiff
path: root/spec/unit/provider/service
diff options
context:
space:
mode:
authorPhil Dibowitz <phil@ipom.com>2019-11-01 17:59:04 -0700
committerPhil Dibowitz <phil@ipom.com>2019-11-04 15:46:07 -0800
commitd1305e8f114f89bf4a518afbdebba23544f73fd5 (patch)
tree7f0d35902dc6168dfef292dd838167a0eb257562 /spec/unit/provider/service
parenta16e94afeefe34abe1c57e6c4f44e25721db7082 (diff)
downloadchef-d1305e8f114f89bf4a518afbdebba23544f73fd5.tar.gz
Fix enable on indirect units
This follows this `is_masked` path to ensure we don't try to enable OR disable systemd units if they are indirect Fixes #9041 Signed-off-by: Phil Dibowitz <phil@ipom.com>
Diffstat (limited to 'spec/unit/provider/service')
-rw-r--r--spec/unit/provider/service/systemd_service_spec.rb28
1 files changed, 26 insertions, 2 deletions
diff --git a/spec/unit/provider/service/systemd_service_spec.rb b/spec/unit/provider/service/systemd_service_spec.rb
index 15b79922b0..983d524d25 100644
--- a/spec/unit/provider/service/systemd_service_spec.rb
+++ b/spec/unit/provider/service/systemd_service_spec.rb
@@ -36,11 +36,11 @@ describe Chef::Provider::Service::Systemd do
let(:provider) { Chef::Provider::Service::Systemd.new(new_resource, run_context) }
let(:shell_out_success) do
- double("shell_out", exitstatus: 0, error?: false)
+ double("shell_out", exitstatus: 0, error?: false, stdout: "")
end
let(:shell_out_failure) do
- double("shell_out", exitstatus: 1, error?: true)
+ double("shell_out", exitstatus: 1, error?: true, stdout: "")
end
let(:current_resource) { Chef::Resource::Service.new(service_name) }
@@ -56,6 +56,7 @@ describe Chef::Provider::Service::Systemd do
allow(provider).to receive(:is_active?).and_return(false)
allow(provider).to receive(:is_enabled?).and_return(false)
allow(provider).to receive(:is_masked?).and_return(false)
+ allow(provider).to receive(:is_indirect?).and_return(false)
end
it "should create a current resource with the name of the new resource" do
@@ -359,6 +360,29 @@ describe Chef::Provider::Service::Systemd do
expect(provider.is_masked?).to be false
end
end
+
+ describe "is_indirect?" do
+ before(:each) do
+ provider.current_resource = current_resource
+ current_resource.service_name(service_name)
+ allow(provider).to receive(:which).with("systemctl").and_return(systemctl_path.to_s)
+ end
+
+ it "should return true if '#{systemctl_path} --system is-enabled service_name' returns 'indirect'" do
+ expect(provider).to receive(:shell_out).with("#{systemctl_path} --system is-enabled #{service_name_escaped}", {}).and_return(double(stdout: "indirect", exitstatus: shell_out_success))
+ expect(provider.is_indirect?).to be true
+ end
+
+ it "should return false if '#{systemctl_path} --system is-enabled service_name' returns 0 and outputs something other than 'indirect'" do
+ expect(provider).to receive(:shell_out).with("#{systemctl_path} --system is-enabled #{service_name_escaped}", {}).and_return(double(stdout: "enabled", exitstatus: shell_out_success))
+ expect(provider.is_indirect?).to be false
+ end
+
+ it "should return false if '#{systemctl_path} --system is-enabled service_name' returns anything except 0 and outputs somethign other than 'indirect''" do
+ expect(provider).to receive(:shell_out).with("#{systemctl_path} --system is-enabled #{service_name_escaped}", {}).and_return(double(stdout: "enabled", exitstatus: shell_out_failure))
+ expect(provider.is_indirect?).to be false
+ end
+ end
end
end
end