summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2012-10-16 15:21:12 -0700
committerBryan McLellan <btm@opscode.com>2012-10-17 11:00:13 -0700
commit6745c7b3b56e5dee5e3ef97747940009f26b0412 (patch)
treec91c8ce2465b8352d4a4b11e273b79c632805380
parentb7aa405bea475de3ccb4342043c40abea569322a (diff)
downloadchef-6745c7b3b56e5dee5e3ef97747940009f26b0412.tar.gz
[CHEF-1804] Add deprecation notice to 10.x tree for implicit set
This will trigger a warning when using code like node["foo"] = "value" Warnings can be deactivated by setting Chef::Config[:chef11_deprecation_warnings] to false
-rw-r--r--chef/lib/chef/config.rb3
-rw-r--r--chef/lib/chef/node.rb2
-rw-r--r--chef/lib/chef/node/attribute.rb19
3 files changed, 22 insertions, 2 deletions
diff --git a/chef/lib/chef/config.rb b/chef/lib/chef/config.rb
index e16d301c3b..6817ab008a 100644
--- a/chef/lib/chef/config.rb
+++ b/chef/lib/chef/config.rb
@@ -303,6 +303,9 @@ class Chef
cache_type "BasicFile"
cache_options({ :path => platform_specific_path("/var/chef/cache/checksums"), :skip_expires => true })
+ # Set to false to silence Chef 11 deprecation warnings:
+ chef11_deprecation_warnings true
+
# Arbitrary knife configuration data
knife Hash.new
diff --git a/chef/lib/chef/node.rb b/chef/lib/chef/node.rb
index d8cbfe5e18..76eb593838 100644
--- a/chef/lib/chef/node.rb
+++ b/chef/lib/chef/node.rb
@@ -397,7 +397,7 @@ class Chef
# Lazy initializer for tags attribute
def tags
- self[:tags] = [] unless attribute?(:tags)
+ self.set[:tags] = [] unless attribute?(:tags)
self[:tags]
end
diff --git a/chef/lib/chef/node/attribute.rb b/chef/lib/chef/node/attribute.rb
index 66fc31cd89..558163b904 100644
--- a/chef/lib/chef/node/attribute.rb
+++ b/chef/lib/chef/node/attribute.rb
@@ -318,7 +318,24 @@ class Chef
def []=(key, value)
# If we don't have one, then we'll pretend we're normal
- @set_type ||= :normal
+ if @set_type.nil?
+ @set_type = :normal
+ warning=<<-W
+Setting attributes without specifying a precedence is deprecated and will be
+removed in Chef 11.0. To set attributes at normal precedence, change code like:
+`node["key"] = "value"` # Not this
+to:
+`node.set["key"] = "value"` # This
+
+Called from:
+W
+
+ warning_with_line_nrs = caller[0...3].inject(warning) do |msg, source_line|
+ msg << " #{source_line}\n"
+ end
+
+ Chef::Log.warn(warning_with_line_nrs) if Chef::Config[:chef11_deprecation_warnings]
+ end
if set_unless_value_present
if get_value(set_type_hash, key) != nil