diff options
author | Mal Graty <mal.graty@googlemail.com> | 2018-05-16 19:07:11 +0100 |
---|---|---|
committer | Mal Graty <mal.graty@googlemail.com> | 2018-05-19 00:35:58 +0100 |
commit | 3071b022ccb88a0c3298ebf613c0109f97ff4b55 (patch) | |
tree | b3b674c06eead93b03f78ab5f5ea0da2e2187eae | |
parent | d436e257b5666163e02608c4afeada60e231fa88 (diff) | |
download | chef-3071b022ccb88a0c3298ebf613c0109f97ff4b55.tar.gz |
Contextualise daemon-reload calls
Ensure daemon-reload is called in the correct context for user units.
Signed-off-by: Mal Graty <mal.graty@googlemail.com>
-rw-r--r-- | lib/chef/provider/systemd_unit.rb | 2 | ||||
-rw-r--r-- | spec/unit/provider/systemd_unit_spec.rb | 123 |
2 files changed, 85 insertions, 40 deletions
diff --git a/lib/chef/provider/systemd_unit.rb b/lib/chef/provider/systemd_unit.rb index 124f255c3a..0c02b4491c 100644 --- a/lib/chef/provider/systemd_unit.rb +++ b/lib/chef/provider/systemd_unit.rb @@ -219,7 +219,7 @@ class Chef end def daemon_reload - shell_out_with_systems_locale!("#{systemctl_path} daemon-reload") + shell_out_with_systems_locale!("#{systemctl_cmd} daemon-reload", systemctl_opts) end def systemctl_execute!(action, unit) diff --git a/spec/unit/provider/systemd_unit_spec.rb b/spec/unit/provider/systemd_unit_spec.rb index ce04b6c84c..c1fe08ff94 100644 --- a/spec/unit/provider/systemd_unit_spec.rb +++ b/spec/unit/provider/systemd_unit_spec.rb @@ -280,49 +280,53 @@ describe Chef::Provider::SystemdUnit do provider.action_create end - it "triggers a daemon-reload when creating a unit with triggers_reload" do - allow(provider).to receive(:manage_unit_file).with(:create) - expect(new_resource.triggers_reload).to eq true - allow(provider).to receive(:shell_out_with_systems_locale!) - expect(provider).to receive(:shell_out_with_systems_locale!) - .with("#{systemctl_path} daemon-reload") - provider.action_create - end + context "when a user is specified" do + it "triggers a daemon-reload when creating a unit with triggers_reload" do + new_resource.user("joe") + allow(provider).to receive(:manage_unit_file).with(:create) + expect(new_resource.triggers_reload).to eq true + allow(provider).to receive(:shell_out_with_systems_locale!) + expect(provider).to receive(:shell_out_with_systems_locale!) + .with("#{systemctl_path} --user daemon-reload", user_cmd_opts) + provider.action_create + end - it "triggers a daemon-reload when deleting a unit with triggers_reload" do - allow(File).to receive(:exist?) - .with(unit_path_system) - .and_return(true) - allow(provider).to receive(:manage_unit_file).with(:delete) - expect(new_resource.triggers_reload).to eq true - allow(provider).to receive(:shell_out_with_systems_locale!) - expect(provider).to receive(:shell_out_with_systems_locale!) - .with("#{systemctl_path} daemon-reload") - provider.action_delete - end + it "triggers a daemon-reload when deleting a unit with triggers_reload" do + new_resource.user("joe") + allow(File).to receive(:exist?) + .with(unit_path_user) + .and_return(true) + allow(provider).to receive(:manage_unit_file).with(:delete) + expect(new_resource.triggers_reload).to eq true + allow(provider).to receive(:shell_out_with_systems_locale!) + expect(provider).to receive(:shell_out_with_systems_locale!) + .with("#{systemctl_path} --user daemon-reload", user_cmd_opts) + provider.action_delete + end - it "does not trigger a daemon-reload when creating a unit without triggers_reload" do - new_resource.triggers_reload(false) - allow(provider).to receive(:manage_unit_file).with(:create) - allow(provider).to receive(:shell_out_with_systems_locale!) - expect(provider).to_not receive(:shell_out_with_systems_locale!) - .with("#{systemctl_path} daemon-reload") - provider.action_create - end + it "does not trigger a daemon-reload when creating a unit without triggers_reload" do + new_resource.user("joe") + new_resource.triggers_reload(false) + allow(provider).to receive(:manage_unit_file).with(:create) + allow(provider).to receive(:shell_out_with_systems_locale!) + expect(provider).to_not receive(:shell_out_with_systems_locale!) + .with("#{systemctl_path} --user daemon-reload", user_cmd_opts) + provider.action_create + end - it "does not trigger a daemon-reload when deleting a unit without triggers_reload" do - new_resource.triggers_reload(false) - allow(File).to receive(:exist?) - .with(unit_path_system) - .and_return(true) - allow(provider).to receive(:manage_unit_file).with(:delete) - allow(provider).to receive(:shell_out_with_systems_locale!) - expect(provider).to_not receive(:shell_out_with_systems_locale!) - .with("#{systemctl_path} daemon-reload") - provider.action_delete - end + it "does not trigger a daemon-reload when deleting a unit without triggers_reload" do + new_resource.user("joe") + new_resource.triggers_reload(false) + allow(File).to receive(:exist?) + .with(unit_path_user) + .and_return(true) + allow(provider).to receive(:manage_unit_file).with(:delete) + allow(provider).to receive(:shell_out_with_systems_locale!) + expect(provider).to_not receive(:shell_out_with_systems_locale!) + .with("#{systemctl_path} --user daemon-reload", user_cmd_opts) + provider.action_delete + end - context "when a user is specified" do it "deletes the file when it exists" do new_resource.user("joe") allow(File).to receive(:exist?) @@ -364,6 +368,47 @@ describe Chef::Provider::SystemdUnit do end context "when no user is specified" do + it "triggers a daemon-reload when creating a unit with triggers_reload" do + allow(provider).to receive(:manage_unit_file).with(:create) + expect(new_resource.triggers_reload).to eq true + allow(provider).to receive(:shell_out_with_systems_locale!) + expect(provider).to receive(:shell_out_with_systems_locale!) + .with("#{systemctl_path} --system daemon-reload", {}) + provider.action_create + end + + it "triggers a daemon-reload when deleting a unit with triggers_reload" do + allow(File).to receive(:exist?) + .with(unit_path_system) + .and_return(true) + allow(provider).to receive(:manage_unit_file).with(:delete) + expect(new_resource.triggers_reload).to eq true + allow(provider).to receive(:shell_out_with_systems_locale!) + expect(provider).to receive(:shell_out_with_systems_locale!) + .with("#{systemctl_path} --system daemon-reload", {}) + provider.action_delete + end + + it "does not trigger a daemon-reload when creating a unit without triggers_reload" do + new_resource.triggers_reload(false) + allow(provider).to receive(:manage_unit_file).with(:create) + allow(provider).to receive(:shell_out_with_systems_locale!) + expect(provider).to_not receive(:shell_out_with_systems_locale!) + .with("#{systemctl_path} --system daemon-reload", {}) + provider.action_create + end + + it "does not trigger a daemon-reload when deleting a unit without triggers_reload" do + new_resource.triggers_reload(false) + allow(File).to receive(:exist?) + .with(unit_path_system) + .and_return(true) + allow(provider).to receive(:manage_unit_file).with(:delete) + allow(provider).to receive(:shell_out_with_systems_locale!) + expect(provider).to_not receive(:shell_out_with_systems_locale!) + .with("#{systemctl_path} --system daemon-reload", {}) + provider.action_delete + end it "deletes the file when it exists" do allow(File).to receive(:exist?) .with(unit_path_system) |