summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeha Pansare <neha.pansare@progress.com>2022-05-30 17:00:17 +0530
committerNeha Pansare <neha.pansare@progress.com>2022-06-09 16:35:15 +0530
commitf080820017d7d14e6c3ede91f670f8957f197547 (patch)
treea82c75a33d5b9f480e1ccc8bb97dfdffa61fa1c9
parent6aa802d4886f96807a7f96bd9f91b256c5f18f3f (diff)
downloadchef-neha-p6/fix_systemd.tar.gz
Fix issue in returning masked? status of a resource to consider both 'masked' and 'bad' as UnitFileState values, add corresponding test cases, removed unused variables defined in spec fileneha-p6/fix_systemd
Signed-off-by: Neha Pansare <neha.pansare@progress.com>
-rw-r--r--lib/chef/provider/systemd_unit.rb3
-rw-r--r--spec/unit/provider/systemd_unit_spec.rb36
2 files changed, 18 insertions, 21 deletions
diff --git a/lib/chef/provider/systemd_unit.rb b/lib/chef/provider/systemd_unit.rb
index c0e0aee93c..ac380cd768 100644
--- a/lib/chef/provider/systemd_unit.rb
+++ b/lib/chef/provider/systemd_unit.rb
@@ -236,7 +236,8 @@ class Chef
def masked?
# Note: masked-runtime is excluded, because runtime is volatile, and
# because masked-runtime is not masked.
- systemd_unit_status["UnitFileState"] == "masked"
+ # Unit status of a masked resource is "bad"
+ %w{masked bad}.include?(systemd_unit_status["UnitFileState"])
end
def static?
diff --git a/spec/unit/provider/systemd_unit_spec.rb b/spec/unit/provider/systemd_unit_spec.rb
index 85ab87e722..ba8654863d 100644
--- a/spec/unit/provider/systemd_unit_spec.rb
+++ b/spec/unit/provider/systemd_unit_spec.rb
@@ -60,26 +60,6 @@ describe Chef::Provider::SystemdUnit, :linux_only do
double("shell_out", exitstatus: 0, error?: false)
end
- let(:shell_out_failure) do
- double("shell_out", exitstatus: 1, error?: true)
- end
-
- let(:shell_out_masked) do
- double("shell_out", exitstatus: 0, error?: false, stdout: "masked")
- end
-
- let(:shell_out_static) do
- double("shell_out", exitstatus: 0, error?: false, stdout: "static")
- end
-
- let(:shell_out_disabled) do
- double("shell_out", exitstatus: 1, error?: true, stdout: "disabled")
- end
-
- let(:shell_out_indirect) do
- double("shell_out", exitstatus: 0, error?: true, stdout: "indirect")
- end
-
before(:each) do
allow(Etc).to receive(:getpwnam).and_return(OpenStruct.new(uid: 1000))
allow(Chef::Resource::SystemdUnit).to receive(:new)
@@ -932,6 +912,11 @@ describe Chef::Provider::SystemdUnit, :linux_only do
UnitFileState=masked
STDOUT
+ bad_and_active = <<-STDOUT
+ ActiveState=active
+ UnitFileState=bad
+ STDOUT
+
context "when a user is specified" do
it "returns true when the unit is masked" do
current_resource.user(user_name)
@@ -944,6 +929,12 @@ describe Chef::Provider::SystemdUnit, :linux_only do
with_systemctl_show(systemctl_path, "--user", user_cmd_opts, enabled_and_active)
expect(provider.masked?).to be false
end
+
+ it "returns true when unit is masked and bad" do
+ current_resource.user(user_name)
+ with_systemctl_show(systemctl_path, "--user", user_cmd_opts, bad_and_active)
+ expect(provider.masked?).to be true
+ end
end
context "when no user is specified" do
@@ -956,6 +947,11 @@ describe Chef::Provider::SystemdUnit, :linux_only do
with_systemctl_show(systemctl_path, "--system", {}, enabled_and_active)
expect(provider.masked?).to be false
end
+
+ it "returns true when the unit is masked and bad" do
+ with_systemctl_show(systemctl_path, "--system", {}, bad_and_active)
+ expect(provider.masked?).to be true
+ end
end
end