summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-09-09 10:24:42 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2016-09-21 10:37:59 -0700
commit723bac74427f6f605fd2c9ab855afe59ba84d08b (patch)
tree957ccc2475a557a8d96cff5b69c1dc8ebcfebcc3
parented0729ba1ef9a7494dbe374c9ee2ec0c776a76f6 (diff)
downloadchef-723bac74427f6f605fd2c9ab855afe59ba84d08b.tar.gz
ignore unknown metadata fields in metadata.rb
if we're just using chef-zero there's no metadata.json file so chef-client doesn't do json parsing (which ignores unknown metadata fields already) but parses metadata.json which explodes. i believe since TK goes through berks it renders the rb to json before copying to the virt so we don't see this in TK or in running chef-client from a real server. this only affects the chef-client -z or chef-zolo mode of operation (and probably legacy chef-solo) Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/cookbook/metadata.rb8
-rw-r--r--spec/unit/cookbook/metadata_spec.rb19
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb
index ab83da9e55..212c596272 100644
--- a/lib/chef/cookbook/metadata.rb
+++ b/lib/chef/cookbook/metadata.rb
@@ -722,6 +722,14 @@ class Chef
end
end
+ def method_missing(method, *args, &block)
+ if block_given?
+ super
+ else
+ Chef::Log.warn "ignoring method #{method} on cookbook with name #{name}, possible typo or future metdata?"
+ end
+ end
+
private
# Helper to match a gem style version (ohai_version/chef_version) against a set of
diff --git a/spec/unit/cookbook/metadata_spec.rb b/spec/unit/cookbook/metadata_spec.rb
index 27666eb338..a6c85bd397 100644
--- a/spec/unit/cookbook/metadata_spec.rb
+++ b/spec/unit/cookbook/metadata_spec.rb
@@ -948,5 +948,24 @@ describe Chef::Cookbook::Metadata do
end
end
+ describe "from_file" do
+ it "ignores unknown metadata fields in metadata.rb files" do
+ expect(Chef::Log).to receive(:warn).with(/ignoring method some_spiffy_new_metadata_field/)
+ Tempfile.open("metadata.rb") do |f|
+ f.write <<-EOF
+ some_spiffy_new_metadata_field "stuff its set to"
+ EOF
+ f.close
+ metadata.from_file(f.path)
+ end
+ end
+ end
+
+ describe "from_json" do
+ it "ignores unknown metadata fields in metdata.json files" do
+ json = %q{{ "some_spiffy_new_metadata_field": "stuff its set to" }}
+ metadata.from_json(json)
+ end
+ end
end
end