summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@chef.io>2019-12-04 12:16:44 -0800
committerGitHub <noreply@github.com>2019-12-04 12:16:44 -0800
commitff38e668ac90885dc5d5a275d2fec2124b12b603 (patch)
treed7948df0053f8bef442b53ee326ae7d17b025729
parentebbd017388ec047caec4c2721978afcaba10a861 (diff)
parent01ede5b9adca09d68788d3627b2036e1d038a468 (diff)
downloadchef-ff38e668ac90885dc5d5a275d2fec2124b12b603.tar.gz
Resolve non-zero "success" error code issues with linux_user re… (#9105)
Resolve non-zero "success" error code issues with linux_user resource
-rw-r--r--lib/chef/provider/user/linux.rb7
-rw-r--r--spec/support/shared/unit/provider/useradd_based_user_provider.rb24
2 files changed, 22 insertions, 9 deletions
diff --git a/lib/chef/provider/user/linux.rb b/lib/chef/provider/user/linux.rb
index d27dbcabd4..224c9f9803 100644
--- a/lib/chef/provider/user/linux.rb
+++ b/lib/chef/provider/user/linux.rb
@@ -28,7 +28,12 @@ class Chef
end
def manage_user
- shell_out!("usermod", universal_options, usermod_options, new_resource.username)
+ manage_u = shell_out("usermod", universal_options, usermod_options, new_resource.username, returns: [0, 12])
+ if manage_u.exitstatus == 12 && manage_u.stderr !~ /exists/
+ raise Chef::Exceptions::User, "Unable to modify home directory for #{new_resource.username}"
+ end
+
+ manage_u.error!
end
def remove_user
diff --git a/spec/support/shared/unit/provider/useradd_based_user_provider.rb b/spec/support/shared/unit/provider/useradd_based_user_provider.rb
index a30f543e72..99933991a9 100644
--- a/spec/support/shared/unit/provider/useradd_based_user_provider.rb
+++ b/spec/support/shared/unit/provider/useradd_based_user_provider.rb
@@ -159,7 +159,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
"-u", "1000",
"-d", "/Users/mud",
"-m",
- "adam" ])
+ "adam"])
expect(provider).to receive(:shell_out_compacted!).with(*command).and_return(true)
provider.create_user
end
@@ -180,7 +180,7 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
command.concat([ "-s", "/usr/bin/zsh",
"-u", "1000",
"-r", "-m",
- "adam" ])
+ "adam"])
expect(provider).to receive(:shell_out_compacted!).with(*command).and_return(true)
provider.create_user
end
@@ -190,10 +190,15 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
end
describe "when managing a user" do
+ let(:manage_u_status) do
+ double("Mixlib::ShellOut command", exitstatus: 0, stdout: @stdout, stderr: @stderr, error!: nil)
+ end
+
before(:each) do
provider.new_resource.manage_home true
provider.new_resource.home "/Users/mud"
provider.new_resource.gid "23"
+ @stderr = ""
end
# CHEF-3423, -m must come before the username
@@ -203,8 +208,9 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
"-g", "23",
"-d", "/Users/mud",
"-m",
- "adam" ]
- expect(provider).to receive(:shell_out_compacted!).with(*command).and_return(true)
+ "adam"]
+ command.concat([ { returns: [0, 12] } ])
+ expect(provider).to receive(:shell_out_compacted).with(*command).and_return(manage_u_status)
provider.manage_user
end
@@ -214,8 +220,9 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
"-g", "23",
"-d", "/Users/mud",
"-m",
- "adam" ]
- expect(provider).to receive(:shell_out_compacted!).with(*command).and_return(true)
+ "adam"]
+ command.concat([ { returns: [0, 12] } ])
+ expect(provider).to receive(:shell_out_compacted).with(*command).and_return(manage_u_status)
provider.manage_user
end
@@ -223,8 +230,9 @@ shared_examples_for "a useradd-based user provider" do |supported_useradd_option
expect(provider).to receive(:updating_home?).at_least(:once).and_return(false)
command = ["usermod",
"-g", "23",
- "adam" ]
- expect(provider).to receive(:shell_out_compacted!).with(*command).and_return(true)
+ "adam"]
+ command.concat([ { returns: [0, 12] } ])
+ expect(provider).to receive(:shell_out_compacted).with(*command).and_return(manage_u_status)
provider.manage_user
end
end