summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-09-15 13:06:35 -0700
committerGitHub <noreply@github.com>2016-09-15 13:06:35 -0700
commit38c57100077be927141188eac883b925d5bb58a3 (patch)
treee822d7ac3ce2cd4d4630343c2182de72cf3f094a
parentf29272a46f0cec2187681322859e2a641d208b37 (diff)
parent982ec1a40fa7ad79337b2bd780d976b14d1de275 (diff)
downloadchef-38c57100077be927141188eac883b925d5bb58a3.tar.gz
Merge pull request #5322 from chef/lcg/manage-home-fix
revert supports[:manage_home] behavior
-rw-r--r--lib/chef/provider/user/linux.rb18
-rw-r--r--lib/chef/resource/user.rb14
-rw-r--r--lib/chef/resource/user/linux_user.rb14
-rw-r--r--spec/unit/provider/user/dscl_spec.rb4
-rw-r--r--spec/unit/provider/user/linux_spec.rb42
-rw-r--r--spec/unit/provider/user/pw_spec.rb2
6 files changed, 72 insertions, 22 deletions
diff --git a/lib/chef/provider/user/linux.rb b/lib/chef/provider/user/linux.rb
index f09d86e98c..4a2491d806 100644
--- a/lib/chef/provider/user/linux.rb
+++ b/lib/chef/provider/user/linux.rb
@@ -52,14 +52,14 @@ class Chef
opts << "-s" << new_resource.shell if should_set?(:shell)
opts << "-u" << new_resource.uid if should_set?(:uid)
opts << "-d" << new_resource.home if updating_home?
- opts << "-o" if new_resource.non_unique
+ opts << "-o" if non_unique
opts
end
def usermod_options
opts = []
if updating_home?
- if new_resource.manage_home
+ if manage_home
opts << "-m"
end
end
@@ -69,7 +69,7 @@ class Chef
def useradd_options
opts = []
opts << "-r" if new_resource.system
- if new_resource.manage_home
+ if manage_home
opts << "-m"
else
opts << "-M"
@@ -79,7 +79,7 @@ class Chef
def userdel_options
opts = []
- opts << "-r" if new_resource.manage_home
+ opts << "-r" if manage_home
opts << "-f" if new_resource.force
opts
end
@@ -122,6 +122,16 @@ class Chef
# FIXME: should probably go on the current_resource
@locked
end
+
+ def non_unique
+ # XXX: THIS GOES AWAY IN CHEF-13 AND BECOMES JUST new_resource.non_unique
+ new_resource.non_unique || new_resource.supports[:non_unique]
+ end
+
+ def manage_home
+ # XXX: THIS GOES AWAY IN CHEF-13 AND BECOMES JUST new_resource.manage_home
+ new_resource.manage_home || new_resource.supports[:manage_home]
+ end
end
end
end
diff --git a/lib/chef/resource/user.rb b/lib/chef/resource/user.rb
index a07ce8b24b..06dfe95bd4 100644
--- a/lib/chef/resource/user.rb
+++ b/lib/chef/resource/user.rb
@@ -155,6 +155,20 @@ class Chef
:kind_of => [ TrueClass, FalseClass ]
)
end
+
+ def supports(args = {})
+ if args.key?(:manage_home)
+ Chef.log_deprecation "supports { manage_home: #{args[:manage_home]} } on the user resource is deprecated and will be removed in Chef 13, set manage_home: #{args[:manage_home]} instead"
+ end
+ if args.key?(:non_unique)
+ Chef.log_deprecation "supports { non_unique: #{args[:non_unique]} } on the user resource is deprecated and will be removed in Chef 13, set non_unique: #{args[:non_unique]} instead"
+ end
+ super
+ end
+
+ def supports=(args)
+ supports(args)
+ end
end
end
end
diff --git a/lib/chef/resource/user/linux_user.rb b/lib/chef/resource/user/linux_user.rb
index 23d6129373..ec60ac89bf 100644
--- a/lib/chef/resource/user/linux_user.rb
+++ b/lib/chef/resource/user/linux_user.rb
@@ -29,22 +29,12 @@ class Chef
def initialize(name, run_context = nil)
super
@supports = {
- manage_home: true,
- non_unique: true,
+ manage_home: false,
+ non_unique: false,
}
@manage_home = false
end
- def supports(args = {})
- Chef.log_deprecation "setting supports on the linux_user resource is deprecated"
- # setting is deliberately disabled
- super({})
- end
-
- def supports=(args)
- # setting is deliberately disabled
- supports({})
- end
end
end
end
diff --git a/spec/unit/provider/user/dscl_spec.rb b/spec/unit/provider/user/dscl_spec.rb
index dfaaa377d3..7b8be02f3a 100644
--- a/spec/unit/provider/user/dscl_spec.rb
+++ b/spec/unit/provider/user/dscl_spec.rb
@@ -219,6 +219,8 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30"
end
before do
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
new_resource.supports({ :manage_home => true })
new_resource.home("/Users/toor")
@@ -237,6 +239,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30"
end
it "moves the users home to the new location if it exists and the target location is different" do
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
new_resource.supports(:manage_home => true)
current_home = CHEF_SPEC_DATA + "/old_home_dir"
@@ -856,6 +859,7 @@ ea18e18b720e358e7fbe3cfbeaa561456f6ba008937a30")
describe "when Chef is removing the user" do
it "removes the user from the groups and deletes home directory when the resource is configured to manage home" do
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
new_resource.supports({ :manage_home => true })
expect(provider).to receive(:run_dscl).with("list /Groups").and_return("my_group\nyour_group\nreal_group\n")
expect(provider).to receive(:run_dscl).with("read /Groups/my_group").and_raise(Chef::Exceptions::DsclCommandFailed) # Empty group
diff --git a/spec/unit/provider/user/linux_spec.rb b/spec/unit/provider/user/linux_spec.rb
index ac94592859..1c487c0de9 100644
--- a/spec/unit/provider/user/linux_spec.rb
+++ b/spec/unit/provider/user/linux_spec.rb
@@ -45,20 +45,50 @@ describe Chef::Provider::User::Linux do
@current_resource = Chef::Resource::User::LinuxUser.new("adam", @run_context)
end
- it "sets supports manage_home to true" do
- Chef::Config[:treat_deprecation_warnings_as_errors] = false
- expect( @new_resource.supports[:manage_home] ).to be true
+ it "supports manage_home does not exist", chef: ">= 13" do
+ expect( @new_resource.supports.key?(:manage_home) ).to be false
+ end
+
+ it "supports non_unique does not exist", chef: ">= 13" do
+ expect( @new_resource.supports.key?(:non_unique) ).to be false
+ end
+
+ # supports is a method on the superclass so can't totally be removed, but we should aggressively NOP it to decisively break it
+ it "disables the supports API", chef: ">= 13" do
+ @new_resource.supports( { manage_home: true } )
+ expect( @new_resource.supports.key?(:manage_home) ).to be false
+ end
+
+ it "sets supports manage_home to false" do
+ expect( @new_resource.supports[:manage_home] ).to be false
+ end
+
+ it "sets supports non-unique to false" do
+ expect( @new_resource.supports[:non_unique] ).to be false
end
- it "sets supports non-unique to true" do
+ it "throws a deprecation warning on setting supports[:manage_home]" do
Chef::Config[:treat_deprecation_warnings_as_errors] = false
- expect( @new_resource.supports[:non_unique] ).to be true
+ expect(Chef).to receive(:log_deprecation).with("supports { manage_home: true } on the user resource is deprecated and will be removed in Chef 13, set manage_home: true instead")
+ @new_resource.supports( { :manage_home => true } )
end
- it "defaults manage_home to true" do
+ it "defaults manage_home to false" do
expect( @new_resource.manage_home ).to be false
end
+ it "supports[:manage_home] (incorectly) acts like manage_home" do
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
+ @new_resource.supports({ manage_home: true })
+ expect( provider.useradd_options ).to eql(["-m"])
+ end
+
+ it "supports[:manage_home] does not change behavior of manage_home: false", chef: ">= 13" do
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
+ @new_resource.supports({ manage_home: true })
+ expect( provider.useradd_options ).to eql(["-M"])
+ end
+
it "by default manage_home is false and we use -M" do
expect( provider.useradd_options ).to eql(["-M"])
end
diff --git a/spec/unit/provider/user/pw_spec.rb b/spec/unit/provider/user/pw_spec.rb
index 624bcfc67d..fb7c9211a1 100644
--- a/spec/unit/provider/user/pw_spec.rb
+++ b/spec/unit/provider/user/pw_spec.rb
@@ -32,6 +32,8 @@ describe Chef::Provider::User::Pw do
@new_resource.shell "/usr/bin/zsh"
@new_resource.password "abracadabra"
+ # XXX: rip out in Chef-13
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
@new_resource.supports :manage_home => true
@current_resource = Chef::Resource::User::PwUser.new("adam")