Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Final fix for chef-492 - makes the context for the template provider …

…always be distinct from the data we feed it in the variables method, to make sure we don't inadvertantly leak the node object into other persistent data.
  • Loading branch information...
commit 3ead7a2b936cca291d3a91e1d42effce09969dc4 1 parent ca6dd91
@adamhjk adamhjk authored fujin committed
View
4 Rakefile
@@ -171,6 +171,10 @@ namespace :features do
end
namespace :provider do
+ Cucumber::Rake::Task.new(:template) do |t|
+ t.profile = "provider_template"
+ end
+
Cucumber::Rake::Task.new(:remote_file) do |t|
t.profile = "provider_remote_file"
end
View
8 chef/lib/chef/node/attribute.rb
@@ -398,6 +398,14 @@ def method_missing(symbol, *args)
end
end
+ def to_hash
+ result = determine_value(current_override, current_attribute, current_default)
+ if result.class == Hash
+ result
+ else
+ result.to_hash
+ end
+ end
end
end
View
7 chef/lib/chef/provider/template.rb
@@ -95,8 +95,9 @@ def action_create
Chef::Log.debug("Updating template for #{@new_resource} in the cache")
Chef::FileCache.move_to(raw_template_file.path, cache_file_name)
end
-
- context = @new_resource.variables
+
+ context = {}
+ context.merge!(@new_resource.variables)
context[:node] = @node
template_file = render_template(Chef::FileCache.load(cache_file_name), context)
@@ -137,4 +138,4 @@ def action_create_if_missing
end
end
-end
View
12 chef/spec/unit/node/attribute_spec.rb
@@ -404,6 +404,18 @@
end
end
+ describe "to_hash" do
+ it "should convert to a hash" do
+ @attributes.to_hash.class.should == Hash
+ end
+
+ it "should convert to a hash based on current state" do
+ hash = @attributes["hot"].to_hash
+ hash.class.should == Hash
+ hash["day"].should == "sunday"
+ end
+ end
+
describe "has_key?" do
it "should return true if an attribute exists" do
@attributes.has_key?("music").should == true
View
1  cucumber.yml
@@ -18,5 +18,6 @@ search: --tags search --format pretty -r features/steps -r features/support feat
language: --tags language --format pretty -r features/steps -r features/support features
recipe_inclusion: --tags recipe_inclusion --format pretty -r features/steps -r features/support features
provider_remote_file: --tags provider,remote_file --format pretty -r features/steps -r features/support features
+provider_template: --tags template --format pretty -r features/steps -r features/support features
provider_package_macports: --tags macports --format pretty -r features/steps -r features/support features
View
8 features/data/cookbooks/template/README.rdoc
@@ -0,0 +1,8 @@
+= DESCRIPTION:
+
+= REQUIREMENTS:
+
+= ATTRIBUTES:
+
+= USAGE:
+
View
6 features/data/cookbooks/template/metadata.rb
@@ -0,0 +1,6 @@
+maintainer "Opscode"
+maintainer_email "do_not_reply@opscode.com"
+license "Apache 2.0"
+description "Installs/Configures template"
+long_description IO.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
+version "0.1"
View
26 features/data/cookbooks/template/recipes/default.rb
@@ -0,0 +1,26 @@
+#
+# Cookbook Name:: template
+# Recipe:: default
+#
+# Copyright 2009, Opscode
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+node.set[:markov][:test] = { "value" => "sauce" }
+
+template "#{node[:tmpdir]}/template.txt" do
+ source "template.txt.erb"
+ variables node[:markov][:test]
+end
+
View
1  features/data/cookbooks/template/templates/default/template.txt.erb
@@ -0,0 +1 @@
+<%= @value %>
View
13 features/provider/template/template.feature
@@ -0,0 +1,13 @@
+@provider @template
+Feature: Templates
+ In order to easily manage many systems at once
+ As a Developer
+ I want to manage the contents of files programatically
+
+ Scenario: Render a template from a cookbook
+ Given a validated node
+ And it includes the recipe 'template'
+ When I run the chef-client
+ Then the run should exit '0'
+ And a file named 'template.txt' should contain 'sauce'
+
Please sign in to comment.
Something went wrong with that request. Please try again.