summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2015-03-11 12:20:42 -0700
committerJay Mundrawala <jdmundrawala@gmail.com>2015-03-12 15:04:51 -0700
commitbea90a125d42931402c430ccb5fc5f54f84e5ef3 (patch)
tree529d50cbb0b6b442ed125e2af16f99c06cbe5338
parentf400002d1a68b8ee672dea92ddfc6ff15624d9d2 (diff)
downloadchef-bea90a125d42931402c430ccb5fc5f54f84e5ef3.tar.gz
Cleanup user directories if state was leftover from previous run
We are seeing failures in our CI relating to state not being cleaned up in a previous run: ``` 1) Chef::Provider::User::Useradd action :create when the user already exists and home directory is updated and manage_home is enabled moves the home directory to the new location Failure/Error: user_resource.run_action(:create) Mixlib::ShellOut::ShellCommandFailed: user[TEST USER RESOURCE] (dynamically defined) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '12' ---- Begin output of ["usermod", "-d", "/home/bar", "-m", "cf-test"] ---- STDOUT: STDERR: usermod: directory /home/bar exists ---- End output of ["usermod", "-d", "/home/bar", "-m", "cf-test"] ---- Ran ["usermod", "-d", "/home/bar", "-m", "cf-test"] returned 12 # ./lib/chef/mixin/shell_out.rb:56:in `shell_out!' # ./lib/chef/provider/user/useradd.rb:42:in `manage_user' # ./lib/chef/provider/user.rb:137:in `block in action_create' # ./lib/chef/mixin/why_run.rb:52:in `call' # ./lib/chef/mixin/why_run.rb:52:in `add_action' # ./lib/chef/provider.rb:180:in `converge_by' # ./lib/chef/provider/user.rb:136:in `action_create' # ./lib/chef/provider.rb:145:in `run_action' # ./lib/chef/resource.rb:561:in `run_action' # ./spec/functional/resource/user/useradd_spec.rb:336:in `block (4 levels) in <top (required)>' ```
-rw-r--r--spec/functional/resource/user/useradd_spec.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/spec/functional/resource/user/useradd_spec.rb b/spec/functional/resource/user/useradd_spec.rb
index 852f2eb083..ceae81aab9 100644
--- a/spec/functional/resource/user/useradd_spec.rb
+++ b/spec/functional/resource/user/useradd_spec.rb
@@ -77,9 +77,19 @@ describe Chef::Provider::User::Useradd, metadata do
end
end
+ def try_cleanup
+ ['/home/foo', '/home/bar'].each do |f|
+ shell_out("rm", "-r", f)
+ end
+ ['cf-test'].each do |u|
+ shell_out("userdel", "-r", username)
+ end
+ end
+
before do
# Silence shell_out live stream
Chef::Log.level = :warn
+ try_cleanup
end
after do