summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-03-07 11:11:00 -0800
committerGitHub <noreply@github.com>2017-03-07 11:11:00 -0800
commit7c84993e32e97918e833883721bbd3138a0e72f8 (patch)
treea1afc2127e47ec5c92fb8e292e58daccf9a518ae
parent59de4e0d67abcd767d8c2c80d86405ac030654fb (diff)
parentd12f5530df65a3a53d1e1e568ace0e49ffcf195f (diff)
downloadchef-7c84993e32e97918e833883721bbd3138a0e72f8.tar.gz
Merge pull request #5863 from chef/lcg/remove-supports
CHEF-13: remove supports API from Chef::Resource
-rw-r--r--RELEASE_NOTES.md4
-rw-r--r--lib/chef/resource.rb24
-rw-r--r--lib/chef/resource/mount.rb17
-rw-r--r--lib/chef/resource/service.rb18
-rw-r--r--lib/chef/resource/user.rb4
-rw-r--r--spec/unit/provider/user/linux_spec.rb4
-rw-r--r--spec/unit/resource/service_spec.rb6
-rw-r--r--spec/unit/resource_spec.rb20
8 files changed, 22 insertions, 75 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index f58c2f0950..db8732c32b 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -49,3 +49,7 @@ PolicyFile users on Chef-13 should be using Chef Server 12.3 or higher.
The remediation is removing the self-dependency `depends` line in the metadata.
+### Removed `supports` API from Chef::Resource
+
+Retained only for the service resource (where it makes some sense) and for the mount resource.
+
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 40911cd2cc..f9fb5926aa 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -138,7 +138,6 @@ class Chef
@action = self.class.default_action
@updated = false
@updated_by_last_action = false
- @supports = {}
@ignore_failure = false
@retries = 0
@retry_delay = 2
@@ -955,29 +954,6 @@ class Chef
end
#
- # Sets a list of capabilities of the real resource. For example, `:remount`
- # (for filesystems) and `:restart` (for services).
- #
- # TODO Calling resource.supports({}) will not set this to empty; it will do
- # a get instead. That's wrong.
- #
- # @param args Hash{Symbol=>Boolean} If non-empty, sets the capabilities of
- # this resource. Default: {}
- # @return Hash{Symbol=>Boolean} An array of things this resource supports.
- #
- def supports(args = {})
- if args.any?
- @supports = args
- else
- @supports
- end
- end
-
- def supports=(args)
- supports(args)
- end
-
- #
# A hook called after a resource is created. Meant to be overriden by
# subclasses.
#
diff --git a/lib/chef/resource/mount.rb b/lib/chef/resource/mount.rb
index 3e35325246..2aca8432dd 100644
--- a/lib/chef/resource/mount.rb
+++ b/lib/chef/resource/mount.rb
@@ -1,7 +1,7 @@
#
# Author:: Joshua Timberman (<joshua@chef.io>)
# Author:: Tyler Cloke (<tyler@chef.io>)
-# Copyright:: Copyright 2009-2016, Chef Software Inc.
+# Copyright:: Copyright 2009-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,6 +30,10 @@ class Chef
default_action :mount
allowed_actions :mount, :umount, :unmount, :remount, :enable, :disable
+ # this is a poor API please do not re-use this pattern
+ property :supports, Hash, default: { remount: false },
+ coerce: proc { |x| x.is_a?(Array) ? x.each_with_object({}) { |i, m| m[i] = true } : x }
+
def initialize(name, run_context = nil)
super
@mount_point = name
@@ -42,7 +46,6 @@ class Chef
@pass = 2
@mounted = false
@enabled = false
- @supports = { :remount => false }
@username = nil
@password = nil
@domain = nil
@@ -140,16 +143,6 @@ class Chef
)
end
- def supports(args = {})
- if args.is_a? Array
- args.each { |arg| @supports[arg] = true }
- elsif args.any?
- @supports = args
- else
- @supports
- end
- end
-
def username(arg = nil)
set_or_return(
:username,
diff --git a/lib/chef/resource/service.rb b/lib/chef/resource/service.rb
index 1ca4b84af0..d9f0969ecb 100644
--- a/lib/chef/resource/service.rb
+++ b/lib/chef/resource/service.rb
@@ -1,7 +1,7 @@
#
# Author:: AJ Christensen (<aj@hjksolutions.com>)
# Author:: Tyler Cloke (<tyler@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software, Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,6 +30,10 @@ class Chef
allowed_actions :enable, :disable, :start, :stop, :restart, :reload,
:mask, :unmask
+ # this is a poor API please do not re-use this pattern
+ property :supports, Hash, default: { restart: nil, reload: nil, status: nil },
+ coerce: proc { |x| x.is_a?(Array) ? x.each_with_object({}) { |i, m| m[i] = true } : x }
+
def initialize(name, run_context = nil)
super
@service_name = name
@@ -48,7 +52,6 @@ class Chef
@timeout = nil
@run_levels = nil
@user = nil
- @supports = { :restart => nil, :reload => nil, :status => nil }
end
def service_name(arg = nil)
@@ -201,17 +204,6 @@ class Chef
:kind_of => [ String ]
)
end
-
- def supports(args = {})
- if args.is_a? Array
- args.each { |arg| @supports[arg] = true }
- elsif args.any?
- @supports = args
- else
- @supports
- end
- end
-
end
end
end
diff --git a/lib/chef/resource/user.rb b/lib/chef/resource/user.rb
index 288335a599..a1e315ef50 100644
--- a/lib/chef/resource/user.rb
+++ b/lib/chef/resource/user.rb
@@ -151,10 +151,6 @@ class Chef
:kind_of => [ TrueClass, FalseClass ]
)
end
-
- def supports(args = {})
- raise Chef::Exceptions::User, "calling supports on a user resource is no longer supported in Chef-13, you probably need to use the manage_home or non_unique properties directly"
- end
end
end
end
diff --git a/spec/unit/provider/user/linux_spec.rb b/spec/unit/provider/user/linux_spec.rb
index 063ca934c3..5092c8f4b9 100644
--- a/spec/unit/provider/user/linux_spec.rb
+++ b/spec/unit/provider/user/linux_spec.rb
@@ -46,11 +46,11 @@ describe Chef::Provider::User::Linux do
end
it "throws an error when trying to set supports manage_home: true" do
- expect { @new_resource.supports( manage_home: true ) }.to raise_error(Chef::Exceptions::User)
+ expect { @new_resource.supports( manage_home: true ) }.to raise_error(NoMethodError)
end
it "throws an error when trying to set supports non_unique: true" do
- expect { @new_resource.supports( non_unique: true ) }.to raise_error(Chef::Exceptions::User)
+ expect { @new_resource.supports( non_unique: true ) }.to raise_error(NoMethodError)
end
it "defaults manage_home to false" do
diff --git a/spec/unit/resource/service_spec.rb b/spec/unit/resource/service_spec.rb
index 7aadc55532..8d661e2a7a 100644
--- a/spec/unit/resource/service_spec.rb
+++ b/spec/unit/resource/service_spec.rb
@@ -1,7 +1,7 @@
#
# Author:: AJ Christensen (<aj@hjksolutions.com>)
# Author:: Tyler Cloke (<tyler@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software, Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -146,13 +146,13 @@ describe Chef::Resource::Service do
it "should allow you to set what features this resource supports as a array" do
support_array = [ :status, :restart ]
- support_hash = { :status => true, :restart => true, :reload => nil }
+ support_hash = { :status => true, :restart => true }
@resource.supports(support_array)
expect(@resource.supports).to eq(support_hash)
end
it "should allow you to set what features this resource supports as a hash" do
- support_hash = { :status => true, :restart => true, :reload => false }
+ support_hash = { :status => true, :restart => true }
@resource.supports(support_hash)
expect(@resource.supports).to eq(support_hash)
end
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index 2f75ba0241..0f8540b855 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -3,7 +3,7 @@
# Author:: Christopher Walters (<cw@chef.io>)
# Author:: Tim Hinderliter (<tim@chef.io>)
# Author:: Seth Chisamore (<schisamo@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software Inc.
+# Copyright:: Copyright 2008-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -192,7 +192,6 @@ describe Chef::Resource do
describe "load_from" do
let(:prior_resource) do
prior_resource = Chef::Resource.new("funk")
- prior_resource.supports(:funky => true)
prior_resource.source_line
prior_resource.allowed_actions << :funkytown
prior_resource.action(:funkytown)
@@ -205,7 +204,6 @@ describe Chef::Resource do
it "should load the attributes of a prior resource" do
resource.load_from(prior_resource)
- expect(resource.supports).to eq({ :funky => true })
end
it "should not inherit the action from the prior resource" do
@@ -481,7 +479,7 @@ describe Chef::Resource do
let(:resource_class) { Class.new(Chef::Resource) { property :a, default: 1 } }
it "should include the default in the hash" do
expect(resource.to_hash.keys.sort).to eq([:a, :allowed_actions, :params, :provider, :updated,
- :updated_by_last_action, :before, :supports,
+ :updated_by_last_action, :before,
:noop, :ignore_failure, :name, :source_line,
:action, :retries, :retry_delay, :elapsed_time,
:default_guard_interpreter, :guard_interpreter, :sensitive].sort)
@@ -493,7 +491,7 @@ describe Chef::Resource do
it "should convert to a hash" do
hash = resource.to_hash
expected_keys = [ :allowed_actions, :params, :provider, :updated,
- :updated_by_last_action, :before, :supports,
+ :updated_by_last_action, :before,
:noop, :ignore_failure, :name, :source_line,
:action, :retries, :retry_delay, :elapsed_time,
:default_guard_interpreter, :guard_interpreter, :sensitive ]
@@ -512,18 +510,6 @@ describe Chef::Resource do
end
end
- describe "supports" do
- it "should allow you to set what features this resource supports" do
- support_hash = { :one => :two }
- resource.supports(support_hash)
- expect(resource.supports).to eql(support_hash)
- end
-
- it "should return the current value of supports" do
- expect(resource.supports).to eq({})
- end
- end
-
describe "ignore_failure" do
it "should default to throwing an error if a provider fails for a resource" do
expect(resource.ignore_failure).to eq(false)