summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2016-07-21 16:40:27 +0100
committerThom May <thom@chef.io>2016-07-26 13:27:24 +0100
commit01d6650793e51ad1bdb5309fea49464c2335365d (patch)
treeed8009be851cd5a7abd4b278efa3aa66c16f7983
parentff9d72e533a5a5e5afa53d4cf9a8feef3078925f (diff)
downloadchef-01d6650793e51ad1bdb5309fea49464c2335365d.tar.gz
Cache ChefFS childrentm/cache_fs_children
Signed-off-by: Thom May <thom@chef.io>
-rw-r--r--Gemfile.lock6
-rw-r--r--chef.gemspec2
-rw-r--r--lib/chef/chef_fs/file_system/repository/directory.rb6
-rw-r--r--lib/chef/chef_fs/file_system_cache.rb62
-rw-r--r--spec/integration/knife/diff_spec.rb4
-rw-r--r--spec/integration/knife/download_spec.rb8
-rw-r--r--spec/integration/knife/raw_spec.rb2
-rw-r--r--spec/integration/knife/upload_spec.rb6
-rw-r--r--spec/spec_helper.rb4
-rw-r--r--spec/support/shared/integration/knife_support.rb4
10 files changed, 90 insertions, 14 deletions
diff --git a/Gemfile.lock b/Gemfile.lock
index 062aa32d22..7868bd29c9 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -20,7 +20,7 @@ PATH
chef (12.13.13)
bundler (>= 1.10)
chef-config (= 12.13.13)
- chef-zero (~> 4.5)
+ chef-zero (~> 4.8)
diff-lcs (~> 1.2, >= 1.2.4)
erubis (~> 2.7)
ffi-yajl (~> 2.2)
@@ -48,7 +48,7 @@ PATH
chef (12.13.13-universal-mingw32)
bundler (>= 1.10)
chef-config (= 12.13.13)
- chef-zero (~> 4.5)
+ chef-zero (~> 4.8)
diff-lcs (~> 1.2, >= 1.2.4)
erubis (~> 2.7)
ffi (~> 1.9)
@@ -133,7 +133,7 @@ GEM
ubuntu_ami (~> 0.4, >= 0.4.1)
chef-rewind (0.0.9)
chef-sugar (3.3.0)
- chef-zero (4.7.0)
+ chef-zero (4.8.0)
ffi-yajl (~> 2.2)
hashie (>= 2.0, < 4.0)
mixlib-log (~> 1.3)
diff --git a/chef.gemspec b/chef.gemspec
index 12c0aa5e3e..14b31ca23e 100644
--- a/chef.gemspec
+++ b/chef.gemspec
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
s.add_dependency "erubis", "~> 2.7"
s.add_dependency "diff-lcs", "~> 1.2", ">= 1.2.4"
- s.add_dependency "chef-zero", "~> 4.5"
+ s.add_dependency "chef-zero", "~> 4.8"
s.add_dependency "plist", "~> 3.2"
s.add_dependency "iniparse", "~> 1.4"
diff --git a/lib/chef/chef_fs/file_system/repository/directory.rb b/lib/chef/chef_fs/file_system/repository/directory.rb
index dae467993a..43f5719822 100644
--- a/lib/chef/chef_fs/file_system/repository/directory.rb
+++ b/lib/chef/chef_fs/file_system/repository/directory.rb
@@ -16,6 +16,8 @@
# limitations under the License.
#
+require "chef/chef_fs/file_system_cache"
+
class Chef
module ChefFS
module FileSystem
@@ -68,9 +70,11 @@ class Chef
end
def children
- dir_ls.sort.
+ return FileSystemCache.instance.children(file_path) if FileSystemCache.instance.exist?(file_path)
+ children = dir_ls.sort.
map { |child_name| make_child_entry(child_name) }.
select { |new_child| new_child.fs_entry_valid? && can_have_child?(new_child.name, new_child.dir?) }
+ FileSystemCache.instance.set_children(file_path, children)
rescue Errno::ENOENT => e
raise Chef::ChefFS::FileSystem::NotFoundError.new(self, e)
end
diff --git a/lib/chef/chef_fs/file_system_cache.rb b/lib/chef/chef_fs/file_system_cache.rb
new file mode 100644
index 0000000000..38b4fda7ad
--- /dev/null
+++ b/lib/chef/chef_fs/file_system_cache.rb
@@ -0,0 +1,62 @@
+#
+# Copyright:: Copyright 2016, Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# 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.
+#
+
+require "singleton"
+require "chef/client"
+
+class Chef
+ module ChefFS
+ class FileSystemCache
+ include Singleton
+
+ def initialize
+ @cache = {}
+
+ Chef::Client.when_run_starts do
+ FileSystemCache.instance.reset!
+ end
+ end
+
+ def reset!
+ @cache = {}
+ end
+
+ def exist?(path)
+ @cache.key?(path)
+ end
+
+ def children(path)
+ @cache[path]["children"]
+ end
+
+ def set_children(path, val)
+ @cache[path] ||= { "children" => [] }
+ @cache[path]["children"] = val
+ val
+ end
+
+ def fetch(path)
+ if @cache.key?(path)
+ @cache[path]
+ else
+ false
+ end
+ end
+
+ end
+ end
+end
diff --git a/spec/integration/knife/diff_spec.rb b/spec/integration/knife/diff_spec.rb
index b7d2f4d1c3..b3bd23f48e 100644
--- a/spec/integration/knife/diff_spec.rb
+++ b/spec/integration/knife/diff_spec.rb
@@ -72,7 +72,7 @@ EOM
file "data_bags/x/y.json", {}
file "environments/_default.json", { "description" => "The default Chef environment" }
file "environments/x.json", {}
- file "nodes/x.json", {}
+ file "nodes/x.json", { "normal" => { "tags" => [] } }
file "roles/x.json", {}
file "users/admin.json", { "admin" => true, "public_key" => ChefZero::PUBLIC_KEY }
file "users/x.json", { "public_key" => ChefZero::PUBLIC_KEY }
@@ -366,7 +366,7 @@ EOM
file "data_bags/x/y.json", {}
file "environments/_default.json", { "description" => "The default Chef environment" }
file "environments/x.json", {}
- file "nodes/x.json", {}
+ file "nodes/x.json", { "normal" => { "tags" => [] } }
file "roles/x.json", {}
file "users/admin.json", { "admin" => true, "public_key" => ChefZero::PUBLIC_KEY }
file "users/x.json", { "public_key" => ChefZero::PUBLIC_KEY }
diff --git a/spec/integration/knife/download_spec.rb b/spec/integration/knife/download_spec.rb
index a924226ea2..be0fc9d708 100644
--- a/spec/integration/knife/download_spec.rb
+++ b/spec/integration/knife/download_spec.rb
@@ -76,7 +76,7 @@ EOM
file "data_bags/x/y.json", {}
file "environments/_default.json", { "description" => "The default Chef environment" }
file "environments/x.json", {}
- file "nodes/x.json", {}
+ file "nodes/x.json", { "normal" => { "tags" => [] } }
file "roles/x.json", {}
file "users/admin.json", { "admin" => true, "public_key" => ChefZero::PUBLIC_KEY }
file "users/x.json", { "public_key" => ChefZero::PUBLIC_KEY }
@@ -645,7 +645,7 @@ EOM
file "data_bags/x/y.json", {}
file "environments/_default.json", { "description" => "The default Chef environment" }
file "environments/x.json", {}
- file "nodes/x.json", {}
+ file "nodes/x.json", { "normal" => { "tags" => [] } }
file "roles/x.json", {}
file "users/admin.json", { "admin" => true, "public_key" => ChefZero::PUBLIC_KEY }
file "users/x.json", { "public_key" => ChefZero::PUBLIC_KEY }
@@ -1271,7 +1271,7 @@ EOM
file "groups/x.json", {}
file "invitations.json", [ "foo" ]
file "members.json", [ "bar" ]
- file "nodes/x.json", {}
+ file "nodes/x.json", { "normal" => { "tags" => [] } }
file "org.json", { "full_name" => "Something" }
file "policies/x-1.0.0.json", {}
file "policies/blah-1.0.0.json", {}
@@ -1295,7 +1295,7 @@ EOM
file "environments/x.json", { "description" => "foo" }
file "groups/x.json", { "description" => "foo" }
file "groups/x.json", { "groups" => [ "admin" ] }
- file "nodes/x.json", { "run_list" => [ "blah" ] }
+ file "nodes/x.json", { "normal" => { "tags" => [] }, "run_list" => [ "blah" ] }
file "org.json", { "full_name" => "Something Else " }
file "policies/x-1.0.0.json", { "run_list" => [ "blah" ] }
file "policy_groups/x.json", {
diff --git a/spec/integration/knife/raw_spec.rb b/spec/integration/knife/raw_spec.rb
index 9078bf09a1..5e0d3a3d11 100644
--- a/spec/integration/knife/raw_spec.rb
+++ b/spec/integration/knife/raw_spec.rb
@@ -49,7 +49,9 @@ describe "knife raw", :workstation do
},
"normal": {
+ "tags": [
+ ]
},
"default": {
diff --git a/spec/integration/knife/upload_spec.rb b/spec/integration/knife/upload_spec.rb
index 55c95b59b7..1db0ea8726 100644
--- a/spec/integration/knife/upload_spec.rb
+++ b/spec/integration/knife/upload_spec.rb
@@ -96,7 +96,7 @@ EOM
file "data_bags/x/y.json", {}
file "environments/_default.json", { "description" => "The default Chef environment" }
file "environments/x.json", {}
- file "nodes/x.json", {}
+ file "nodes/x.json", { "normal" => { "tags" => [] } }
file "roles/x.json", {}
file "users/admin.json", { "admin" => true, "public_key" => ChefZero::PUBLIC_KEY }
file "users/x.json", { "public_key" => ChefZero::PUBLIC_KEY }
@@ -802,7 +802,7 @@ EOM
file "data_bags/x/y.json", {}
file "environments/_default.json", { "description" => "The default Chef environment" }
file "environments/x.json", {}
- file "nodes/x.json", {}
+ file "nodes/x.json", { "normal" => { "tags" => [] } }
file "roles/x.json", {}
file "users/admin.json", { "admin" => true, "public_key" => ChefZero::PUBLIC_KEY }
file "users/x.json", { "public_key" => ChefZero::PUBLIC_KEY }
@@ -1313,7 +1313,7 @@ EOM
file "invitations.json", [ "foo" ]
file "members.json", [ "bar" ]
file "org.json", { "full_name" => "wootles" }
- file "nodes/x.json", {}
+ file "nodes/x.json", { "normal" => { "tags" => [] } }
file "policies/x-1.0.0.json", {}
file "policies/blah-1.0.0.json", {}
file "policy_groups/x.json", { "policies" => { "x" => { "revision_id" => "1.0.0" }, "blah" => { "revision_id" => "1.0.0" } } }
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 44a599436c..dcbc34a157 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -66,6 +66,8 @@ require "chef/util/file_edit"
require "chef/config"
+require "chef/chef_fs/file_system_cache"
+
if ENV["CHEF_FIPS"] == "1"
Chef::Config.init_openssl
end
@@ -202,6 +204,8 @@ RSpec.configure do |config|
config.before(:each) do
Chef.reset!
+ Chef::ChefFS::FileSystemCache.instance.reset!
+
Chef::Config.reset
# By default, treat deprecation warnings as errors in tests.
diff --git a/spec/support/shared/integration/knife_support.rb b/spec/support/shared/integration/knife_support.rb
index 398d90dff0..01df9ab1a7 100644
--- a/spec/support/shared/integration/knife_support.rb
+++ b/spec/support/shared/integration/knife_support.rb
@@ -20,6 +20,7 @@ require "chef/knife"
require "chef/application/knife"
require "logger"
require "chef/log"
+require "chef/chef_fs/file_system_cache"
module KnifeSupport
DEBUG = ENV["DEBUG"]
@@ -70,6 +71,9 @@ module KnifeSupport
Chef::Config[:verbosity] = ( DEBUG ? 2 : 0 )
instance.config[:config_file] = File.join(CHEF_SPEC_DATA, "null_config.rb")
+ # Ensure the ChefFS cache is empty
+ Chef::ChefFS::FileSystemCache.instance.reset!
+
# Configure chef with a (mostly) blank knife.rb
# We set a global and then mutate it in our stub knife.rb so we can be
# extra sure that we're not loading someone's real knife.rb and then