summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2012-10-04 09:25:22 -0700
committerdanielsdeleo <dan@opscode.com>2012-10-04 09:25:22 -0700
commit1c978db9dd37ad9474d6392e35ce1713efe8664f (patch)
tree76a67cdef3ef59013ee613560952334caec14f33
parent4606039250c985ec7dc8fa32b47ee295e6e0b41a (diff)
downloadchef-1c978db9dd37ad9474d6392e35ce1713efe8664f.tar.gz
[CHEF-3197] don't set node attrs via method missing
* default attributes can still be set via method missing, but you need to use node.some_attr = "value" * aliased chef_environment as environment. Some of the tests assumed 'environment' was the correct method.
-rw-r--r--chef/lib/chef/node.rb5
-rw-r--r--chef/lib/chef/node/attribute.rb4
-rw-r--r--chef/spec/data/cookbooks/openldap/attributes/default.rb18
-rw-r--r--chef/spec/data/cookbooks/openldap/attributes/smokey.rb2
-rw-r--r--chef/spec/data/nodes/default.rb6
-rw-r--r--chef/spec/data/nodes/test.example.com.rb6
-rw-r--r--chef/spec/data/nodes/test.rb6
-rw-r--r--chef/spec/data/run_context/cookbooks/test/attributes/george.rb2
-rw-r--r--chef/spec/unit/lwrp_spec.rb4
-rw-r--r--chef/spec/unit/node/attribute_spec.rb6
-rw-r--r--chef/spec/unit/node_spec.rb10
-rw-r--r--chef/spec/unit/platform_spec.rb16
-rw-r--r--chef/spec/unit/provider/ohai_spec.rb2
-rw-r--r--chef/spec/unit/recipe_spec.rb4
-rw-r--r--chef/spec/unit/resource_spec.rb4
-rw-r--r--chef/spec/unit/runner_spec.rb4
16 files changed, 48 insertions, 51 deletions
diff --git a/chef/lib/chef/node.rb b/chef/lib/chef/node.rb
index d8cbfe5e18..c1cf93ccfa 100644
--- a/chef/lib/chef/node.rb
+++ b/chef/lib/chef/node.rb
@@ -233,6 +233,8 @@ class Chef
)
end
+ alias :environment :chef_environment
+
# Used by the DSL
def attribute
construct_attributes
@@ -339,8 +341,7 @@ class Chef
construct_attributes.each_attribute(&block)
end
- # Encouraged to only get used for lookups - while you can do sets from here, it's not as explicit
- # as using the normal/default/override interface.
+ # Only works for attribute fetches, setting is no longer supported
def method_missing(symbol, *args)
attrs = construct_attributes
attrs.send(symbol, *args)
diff --git a/chef/lib/chef/node/attribute.rb b/chef/lib/chef/node/attribute.rb
index 66fc31cd89..ccd87a1d77 100644
--- a/chef/lib/chef/node/attribute.rb
+++ b/chef/lib/chef/node/attribute.rb
@@ -427,9 +427,11 @@ class Chef
else
raise ArgumentError, "Attribute #{symbol} is not defined!" unless auto_vivifiy_on_read
end
- else
+ elsif symbol.to_s =~ /=$/
key_to_set = symbol.to_s[/^(.+)=$/, 1] || symbol
self[key_to_set] = (args.length == 1 ? args[0] : args)
+ else
+ raise NoMethodError, "Undefined node attribute or method `#{symbol}' on `node'"
end
end
diff --git a/chef/spec/data/cookbooks/openldap/attributes/default.rb b/chef/spec/data/cookbooks/openldap/attributes/default.rb
index 204ae9ed77..529e73ff83 100644
--- a/chef/spec/data/cookbooks/openldap/attributes/default.rb
+++ b/chef/spec/data/cookbooks/openldap/attributes/default.rb
@@ -1,15 +1,15 @@
chef_env ||= nil
case chef_env
when "prod"
- ldap_server "ops1prod"
- ldap_basedn "dc=hjksolutions,dc=com"
- ldap_replication_password "yes"
+ default[:ldap_server] = "ops1prod"
+ default[:ldap_basedn] = "dc=hjksolutions,dc=com"
+ default[:ldap_replication_password] = "yes"
when "corp"
- ldap_server "ops1prod"
- ldap_basedn "dc=hjksolutions,dc=com"
- ldap_replication_password "yougotit"
+ default[:ldap_server] = "ops1prod"
+ default[:ldap_basedn] = "dc=hjksolutions,dc=com"
+ default[:ldap_replication_password] = "yougotit"
else
- ldap_server "ops1prod"
- ldap_basedn "dc=hjksolutions,dc=com"
- ldap_replication_password "forsure"
+ default[:ldap_server] = "ops1prod"
+ default[:ldap_basedn] = "dc=hjksolutions,dc=com"
+ default[:ldap_replication_password] = "forsure"
end
diff --git a/chef/spec/data/cookbooks/openldap/attributes/smokey.rb b/chef/spec/data/cookbooks/openldap/attributes/smokey.rb
index 63f5b56c7f..4489c6a7ac 100644
--- a/chef/spec/data/cookbooks/openldap/attributes/smokey.rb
+++ b/chef/spec/data/cookbooks/openldap/attributes/smokey.rb
@@ -1 +1 @@
-smokey "robinson" \ No newline at end of file
+default[:smokey] = "robinson"
diff --git a/chef/spec/data/nodes/default.rb b/chef/spec/data/nodes/default.rb
index d2d3cfd409..1d6291f166 100644
--- a/chef/spec/data/nodes/default.rb
+++ b/chef/spec/data/nodes/default.rb
@@ -6,10 +6,10 @@ name "test.example.com-default"
##
# Nodes can set arbitrary arguments
##
-sunshine "in"
-something "else"
+default[:sunshine] = "in"
+default[:something] = "else"
##
# Nodes should have recipes
##
-recipes "operations-master", "operations-monitoring"
+run_list "operations-master", "operations-monitoring"
diff --git a/chef/spec/data/nodes/test.example.com.rb b/chef/spec/data/nodes/test.example.com.rb
index cfc323a3d3..b30e8489e0 100644
--- a/chef/spec/data/nodes/test.example.com.rb
+++ b/chef/spec/data/nodes/test.example.com.rb
@@ -6,12 +6,12 @@ name "test.example.com"
##
# Nodes can set arbitrary arguments
##
-sunshine "in"
-something "else"
+normal[:sunshine] = "in"
+normal[:something] = "else"
##
# Nodes should have recipes
##
-recipes "operations-master", "operations-monitoring"
+run_list "operations-master", "operations-monitoring"
chef_environment "dev"
diff --git a/chef/spec/data/nodes/test.rb b/chef/spec/data/nodes/test.rb
index e47c6cba55..e1301130d2 100644
--- a/chef/spec/data/nodes/test.rb
+++ b/chef/spec/data/nodes/test.rb
@@ -6,10 +6,10 @@ name "test.example.com-short"
##
# Nodes can set arbitrary arguments
##
-sunshine "in"
-something "else"
+default[:sunshine] = "in"
+default[:something] = "else"
##
# Nodes should have recipes
##
-recipes "operations-master", "operations-monitoring"
+run_list "operations-master", "operations-monitoring"
diff --git a/chef/spec/data/run_context/cookbooks/test/attributes/george.rb b/chef/spec/data/run_context/cookbooks/test/attributes/george.rb
index 5df9567761..8ea4454c79 100644
--- a/chef/spec/data/run_context/cookbooks/test/attributes/george.rb
+++ b/chef/spec/data/run_context/cookbooks/test/attributes/george.rb
@@ -1 +1 @@
-george "washington" \ No newline at end of file
+default[:george] = "washington"
diff --git a/chef/spec/unit/lwrp_spec.rb b/chef/spec/unit/lwrp_spec.rb
index 0bd45769d0..76be6ffa55 100644
--- a/chef/spec/unit/lwrp_spec.rb
+++ b/chef/spec/unit/lwrp_spec.rb
@@ -113,8 +113,8 @@ describe "LWRP" do
describe "Lightweight Chef::Provider" do
before do
@node = Chef::Node.new
- @node.platform(:ubuntu)
- @node.platform_version('8.10')
+ @node.automatic[:platform] = :ubuntu
+ @node.automatic[:platform_version] = '8.10'
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, Chef::CookbookCollection.new({}), @events)
@runner = Chef::Runner.new(@run_context)
diff --git a/chef/spec/unit/node/attribute_spec.rb b/chef/spec/unit/node/attribute_spec.rb
index a3c5fe749a..a48ca620f1 100644
--- a/chef/spec/unit/node/attribute_spec.rb
+++ b/chef/spec/unit/node/attribute_spec.rb
@@ -473,12 +473,6 @@ describe Chef::Node::Attribute do
@attributes.music.mastodon.should == "rocks"
end
- it "should behave like a []= lookup if the last method has an argument" do
- @attributes.music.mastodon(["dream", "still", "shining"])
- @attributes.reset
- @attributes.music.mastodon.should == ["dream", "still", "shining"]
- end
-
it "should allow the last method to set a value if it has an = sign on the end" do
@attributes.music.mastodon = [ "dream", "still", "shining" ]
@attributes.reset
diff --git a/chef/spec/unit/node_spec.rb b/chef/spec/unit/node_spec.rb
index 28ac4eef44..a7d44a2f62 100644
--- a/chef/spec/unit/node_spec.rb
+++ b/chef/spec/unit/node_spec.rb
@@ -167,12 +167,12 @@ describe Chef::Node do
end
it "should allow you to set an attribute via method_missing" do
- @node.sunshine "is bright"
+ @node.sunshine = "is bright"
@node.attribute[:sunshine].should eql("is bright")
end
it "should allow you get get an attribute via method_missing" do
- @node.sunshine "is bright"
+ @node.sunshine = "is bright"
@node.sunshine.should eql("is bright")
end
@@ -253,8 +253,8 @@ describe Chef::Node do
end
it "should allow you to iterate over attributes with each_attribute" do
- @node.sunshine "is bright"
- @node.canada "is a nice place"
+ @node.sunshine = "is bright"
+ @node.canada = "is a nice place"
seen_attributes = Hash.new
@node.each_attribute do |a,v|
seen_attributes[a] = v
@@ -446,7 +446,7 @@ describe Chef::Node do
@node.name.should eql("test.example.com-short")
@node.sunshine.should eql("in")
@node.something.should eql("else")
- @node.recipes.should == ["operations-master", "operations-monitoring"]
+ @node.run_list.should == ["operations-master", "operations-monitoring"]
end
it "should raise an exception if the file cannot be found or read" do
diff --git a/chef/spec/unit/platform_spec.rb b/chef/spec/unit/platform_spec.rb
index b3e14f1364..e45c29274f 100644
--- a/chef/spec/unit/platform_spec.rb
+++ b/chef/spec/unit/platform_spec.rb
@@ -129,8 +129,8 @@ describe Chef::Platform do
kitty = Chef::Resource::Cat.new("loulou")
node = Chef::Node.new
node.name("Intel")
- node.platform("mac_os_x")
- node.platform_version("9.2.2")
+ node[:platform] = "mac_os_x"
+ node[:platform_version] = "9.2.2"
Chef::Platform.find_provider_for_node(node, kitty).should eql("nice")
end
@@ -139,8 +139,8 @@ describe Chef::Platform do
kitty.stub!(:provider).and_return(Chef::Provider::File)
node = Chef::Node.new
node.name("Intel")
- node.platform("mac_os_x")
- node.platform_version("9.2.2")
+ node[:platform] = "mac_os_x"
+ node[:platform_version] = "9.2.2"
Chef::Platform.find_provider_for_node(node, kitty).should eql(Chef::Provider::File)
end
@@ -150,15 +150,15 @@ describe Chef::Platform do
Chef::Platform.platforms[:default].delete(:cat)
node = Chef::Node.new
node.name("Intel")
- node.platform("mac_os")
- node.platform_version("8.5")
+ node[:platform] = "mac_os_x"
+ node[:platform_version] = "8.5"
Chef::Platform.find_provider_for_node(node, kitty).should eql(Chef::Provider::Cat)
end
it "returns a provider object given a Chef::Resource object which has a valid run context" do
node = Chef::Node.new
- node.platform("mac_os_x")
- node.platform_version("9.2.2")
+ node[:platform] = "mac_os_x"
+ node[:platform_version] = "9.2.2"
run_context = Chef::RunContext.new(node, {}, @events)
file = Chef::Resource::File.new("whateva", run_context)
provider = Chef::Platform.provider_for_resource(file, :foo)
diff --git a/chef/spec/unit/provider/ohai_spec.rb b/chef/spec/unit/provider/ohai_spec.rb
index 1ba10d6c32..7bdc648c72 100644
--- a/chef/spec/unit/provider/ohai_spec.rb
+++ b/chef/spec/unit/provider/ohai_spec.rb
@@ -57,7 +57,7 @@ describe Chef::Provider::Ohai do
@new_resource = Chef::Resource::Ohai.new("ohai_reload")
ohai = Ohai::System.new
ohai.all_plugins
- @node.process_external_attrs(ohai.data,{})
+ @node.consume_external_attrs(ohai.data,{})
@provider = Chef::Provider::Ohai.new(@new_resource, @run_context)
end
diff --git a/chef/spec/unit/recipe_spec.rb b/chef/spec/unit/recipe_spec.rb
index ed0aa28a17..5f94e8fd14 100644
--- a/chef/spec/unit/recipe_spec.rb
+++ b/chef/spec/unit/recipe_spec.rb
@@ -110,8 +110,8 @@ describe Chef::Recipe do
it "locate resource for particular platform" do
Object.const_set('ShaunTheSheep', Class.new(Chef::Resource){ provides :laughter, :on_platforms => ["television"] })
- @node.platform("television")
- @node.platform_version("123")
+ @node.automatic[:platform] = "television"
+ @node.automatic[:platform_version] = "123"
res = @recipe.laughter "timmy"
res.name.should eql("timmy")
res.kind_of?(ShaunTheSheep)
diff --git a/chef/spec/unit/resource_spec.rb b/chef/spec/unit/resource_spec.rb
index a3bed5fce2..671a9fa147 100644
--- a/chef/spec/unit/resource_spec.rb
+++ b/chef/spec/unit/resource_spec.rb
@@ -522,8 +522,8 @@ describe Chef::Resource do
before(:each) do
@node = Chef::Node.new
@node.name("bumblebee")
- @node.platform("autobots")
- @node.platform_version("6.1")
+ @node.automatic[:platform] = "autobots"
+ @node.automatic[:platform_version] = "6.1"
Object.const_set('Soundwave', Class.new(Chef::Resource))
Object.const_set('Grimlock', Class.new(Chef::Resource){ provides :dinobot, :on_platforms => ['autobots'] })
end
diff --git a/chef/spec/unit/runner_spec.rb b/chef/spec/unit/runner_spec.rb
index d2a77e5579..388596e350 100644
--- a/chef/spec/unit/runner_spec.rb
+++ b/chef/spec/unit/runner_spec.rb
@@ -84,8 +84,8 @@ describe Chef::Runner do
before(:each) do
@node = Chef::Node.new
@node.name "latte"
- @node.platform "mac_os_x"
- @node.platform_version "10.5.1"
+ @node.automatic[:platform] = "mac_os_x"
+ @node.automatic[:platform_version] = "10.5.1"
@events = Chef::EventDispatch::Dispatcher.new
@run_context = Chef::RunContext.new(@node, Chef::CookbookCollection.new({}), @events)
@first_resource = Chef::Resource::Cat.new("loulou1", @run_context)