diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2015-08-24 12:17:57 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2015-09-08 15:31:32 -0700 |
commit | b0164e0db6a6981d6be21c0ba78b706ab62d38c8 (patch) | |
tree | 43eb53f8b6252ab628b181b4279130b8087f7b67 | |
parent | 24c26efdf71ca5a79e2b5142a86a996f6c9de37e (diff) | |
download | chef-b0164e0db6a6981d6be21c0ba78b706ab62d38c8.tar.gz |
checkpoint testing decorating ohai data
-rw-r--r-- | lib/chef/node.rb | 2 | ||||
-rw-r--r-- | lib/chef/node/attribute.rb | 5 | ||||
-rw-r--r-- | lib/chef/node/attribute_cell.rb | 28 | ||||
-rw-r--r-- | lib/chef/platform/provider_mapping.rb | 2 | ||||
-rw-r--r-- | spec/support/shared/context/client.rb | 10 | ||||
-rw-r--r-- | spec/unit/node_spec.rb | 4 |
6 files changed, 42 insertions, 9 deletions
diff --git a/lib/chef/node.rb b/lib/chef/node.rb index 1a7fb23840..051cfb4345 100644 --- a/lib/chef/node.rb +++ b/lib/chef/node.rb @@ -208,7 +208,7 @@ class Chef Chef::Log.debug("Extracting run list from JSON attributes provided on command line") consume_attributes(json_cli_attrs) - self.automatic_attrs = ohai_data + wrap_automatic_attrs(ohai_data) platform, version = Chef::Platform.find_platform_and_version(self) Chef::Log.debug("Platform is #{platform} version #{version}") diff --git a/lib/chef/node/attribute.rb b/lib/chef/node/attribute.rb index c5be969893..41dc4ae38f 100644 --- a/lib/chef/node/attribute.rb +++ b/lib/chef/node/attribute.rb @@ -45,6 +45,11 @@ class Chef end end + def wrap_automatic_attrs(value) + __deep_merge_cache.clear + wrapped_object.wrap_automatic_attrs(value) + end + def combined_default wrapped_object.combined_default end diff --git a/lib/chef/node/attribute_cell.rb b/lib/chef/node/attribute_cell.rb index 5e13ba8357..8552b55406 100644 --- a/lib/chef/node/attribute_cell.rb +++ b/lib/chef/node/attribute_cell.rb @@ -66,6 +66,16 @@ class Chef end end + def wrap_automatic_attrs(value) + @automatic = Chef::Node::VividMash.new( + wrapped_object: value, + precedence: :automatic, + node: __node, + deep_merge_cache: __deep_merge_cache, + convert_value: false + ) + end + # for performance we delegate Enumerable methods rather than implementing it Enumerable.instance_methods.each do |method| define_method method do |*args, &block| @@ -123,6 +133,15 @@ class Chef as_simple_object.to_s end + # perf + def key?(key) + if self.is_a?(Hash) + merged_hash_has_key?(key) + else + as_simple_object.key?(key) + end + end + def method_missing(method, *args, &block) as_simple_object.public_send(method, *args, &block) end @@ -253,6 +272,15 @@ class Chef end end + def merged_hash_has_key?(key) + COMPONENTS_AS_SYMBOLS.reverse.each do |component| + hash = instance_variable_get(:"@#{component}") + next unless hash.is_a?(Hash) + return true if hash.key?(key) + end + return false + end + def merged_hash_key(key) # this is much faster than merged_hash[key] highest_value_found = false diff --git a/lib/chef/platform/provider_mapping.rb b/lib/chef/platform/provider_mapping.rb index 38dd0e38af..a6c0efa359 100644 --- a/lib/chef/platform/provider_mapping.rb +++ b/lib/chef/platform/provider_mapping.rb @@ -1,6 +1,6 @@ # # Author:: Adam Jacob (<adam@opscode.com>) -# Copyright:: Copyright (c) 2008 Opscode, Inc. +# Copyright:: Copyright (c) 2008-2015 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/spec/support/shared/context/client.rb b/spec/support/shared/context/client.rb index eb537e9889..5f9c8f46e8 100644 --- a/spec/support/shared/context/client.rb +++ b/spec/support/shared/context/client.rb @@ -11,11 +11,11 @@ shared_context "client" do let(:ohai_data) do { - :fqdn => fqdn, - :hostname => hostname, - :machinename => machinename, - :platform => platform, - :platform_version => platform_version + 'fqdn' => fqdn, + 'hostname' => hostname, + 'machinename' => machinename, + 'platform' => platform, + 'platform_version' => platform_version } end diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb index 03b3ed0adb..c9ebc8fbe9 100644 --- a/spec/unit/node_spec.rb +++ b/spec/unit/node_spec.rb @@ -700,7 +700,7 @@ describe Chef::Node do describe "consuming json" do before do - @ohai_data = {:platform => 'foo', :platform_version => 'bar'} + @ohai_data = {'platform' => 'foo', 'platform_version' => 'bar'} end it "consumes the run list portion of a collection of attributes and returns the remainder" do @@ -767,7 +767,7 @@ describe Chef::Node do describe "preparing for a chef client run" do before do - @ohai_data = {:platform => 'foobuntu', :platform_version => '23.42'} + @ohai_data = {'platform' => 'foobuntu', 'platform_version' => '23.42'} end it "sets its platform according to platform detection" do |