summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-12-16 12:54:11 -0800
committerJohn Keiser <john@johnkeiser.com>2015-12-16 12:54:11 -0800
commit14086fef574219674816fe1cd7db71a934c4450c (patch)
tree475d3bb6ab5f1f4f1fb21b8d77e26a32b956f90e
parentb027f4b9cebda8314118a0839f93d812e1b6fcfa (diff)
downloadchef-jk/split-cookbooks.tar.gz
Separate versioned /cookbooks from unversionedjk/split-cookbooks
-rw-r--r--lib/chef/chef_fs/file_system/chef_server_root_dir.rb5
-rw-r--r--lib/chef/chef_fs/file_system/cookbook_dir.rb2
-rw-r--r--lib/chef/chef_fs/file_system/cookbooks_dir.rb45
-rw-r--r--lib/chef/chef_fs/file_system/cookbooks_dir_unversioned.rb54
4 files changed, 69 insertions, 37 deletions
diff --git a/lib/chef/chef_fs/file_system/chef_server_root_dir.rb b/lib/chef/chef_fs/file_system/chef_server_root_dir.rb
index 09181ac4b4..9d30b5055d 100644
--- a/lib/chef/chef_fs/file_system/chef_server_root_dir.rb
+++ b/lib/chef/chef_fs/file_system/chef_server_root_dir.rb
@@ -21,6 +21,7 @@ require 'chef/chef_fs/file_system/acls_dir'
require 'chef/chef_fs/file_system/base_fs_dir'
require 'chef/chef_fs/file_system/rest_list_dir'
require 'chef/chef_fs/file_system/cookbooks_dir'
+require 'chef/chef_fs/file_system/cookbooks_dir_unversioned'
require 'chef/chef_fs/file_system/data_bags_dir'
require 'chef/chef_fs/file_system/nodes_dir'
require 'chef/chef_fs/file_system/org_entry'
@@ -140,7 +141,9 @@ class Chef
@children ||= begin
result = [
# /cookbooks
- CookbooksDir.new("cookbooks", self),
+ versioned_cookbooks ?
+ CookbooksDir.new("cookbooks", self) :
+ CookbooksDirUnversioned.new("cookbooks", self),
# /data_bags
DataBagsDir.new("data_bags", self, "data"),
# /environments
diff --git a/lib/chef/chef_fs/file_system/cookbook_dir.rb b/lib/chef/chef_fs/file_system/cookbook_dir.rb
index 42408c0869..856386a144 100644
--- a/lib/chef/chef_fs/file_system/cookbook_dir.rb
+++ b/lib/chef/chef_fs/file_system/cookbook_dir.rb
@@ -165,7 +165,7 @@ class Chef
end
def copy_from(other, options = {})
- parent.upload_cookbook_from(other, options)
+ parent.create_child_from(other, options)
end
def rest
diff --git a/lib/chef/chef_fs/file_system/cookbooks_dir.rb b/lib/chef/chef_fs/file_system/cookbooks_dir.rb
index 8cbc06931b..4b53c621c1 100644
--- a/lib/chef/chef_fs/file_system/cookbooks_dir.rb
+++ b/lib/chef/chef_fs/file_system/cookbooks_dir.rb
@@ -28,6 +28,9 @@ require 'tmpdir'
class Chef
module ChefFS
module FileSystem
+ # Represents top-level /cookbooks.
+ # Children include name and version (i.e. apache2-1.0.0).
+ # This is used for the top-level /cookbooks when Chef::Config.versioned_cookbooks is true.
class CookbooksDir < RestListDir
include Chef::Mixin::FileClass
@@ -39,15 +42,11 @@ class Chef
def children
@children ||= begin
- if root.versioned_cookbooks
- result = []
- root.get_json("#{api_path}/?num_versions=all").each_pair do |cookbook_name, cookbooks|
- cookbooks['versions'].each do |cookbook_version|
- result << CookbookDir.new("#{cookbook_name}-#{cookbook_version['version']}", self, :exists => true)
- end
+ result = []
+ root.get_json("#{api_path}/?num_versions=all").each_pair do |cookbook_name, cookbooks|
+ cookbooks['versions'].each do |cookbook_version|
+ result << CookbookDir.new("#{cookbook_name}-#{cookbook_version['version']}", self, :exists => true)
end
- else
- result = root.get_json(api_path).keys.map { |cookbook_name| CookbookDir.new(cookbook_name, self, :exists => true) }
end
result.sort_by(&:name)
end
@@ -56,10 +55,6 @@ class Chef
def create_child_from(other, options = {})
@children = nil
upload_cookbook_from(other, options)
- end
-
- def upload_cookbook_from(other, options = {})
- root.versioned_cookbooks ? upload_versioned_cookbook(other, options) : upload_unversioned_cookbook(other, options)
rescue Timeout::Error => e
raise Chef::ChefFS::FileSystem::OperationFailedError.new(:write, self, e, "Timeout writing: #{e}")
rescue Net::HTTPServerException => e
@@ -77,7 +72,7 @@ class Chef
# Cookbook Version uploader also requires a lot of refactoring
# to make this work. So instead, we make a temporary cookbook
# symlinking back to real cookbook, and upload the proxy.
- def upload_versioned_cookbook(other, options)
+ def upload_cookbook_from(other, options = {})
cookbook_name = Chef::ChefFS::FileSystem::ChefRepositoryFileSystemCookbookDir.canonical_cookbook_name(other.name)
Dir.mktmpdir do |temp_cookbooks_path|
@@ -97,7 +92,7 @@ class Chef
uploader = Chef::CookbookUploader.new(cookbook_to_upload, :force => options[:force], :rest => root.chef_rest)
with_actual_cookbooks_dir(temp_cookbooks_path) do
- upload_cookbook!(uploader)
+ uploader.upload_cookbooks
end
#
@@ -113,16 +108,6 @@ class Chef
end
end
- def upload_unversioned_cookbook(other, options)
- cookbook_to_upload = other.chef_object
- cookbook_to_upload.freeze_version if options[:freeze]
- uploader = Chef::CookbookUploader.new(cookbook_to_upload, :force => options[:force], :rest => root.chef_rest)
-
- with_actual_cookbooks_dir(other.parent.file_path) do
- upload_cookbook!(uploader)
- end
- end
-
# Work around the fact that CookbookUploader doesn't understand chef_repo_path (yet)
def with_actual_cookbooks_dir(actual_cookbook_path)
old_cookbook_path = Chef::Config.cookbook_path
@@ -133,18 +118,8 @@ class Chef
Chef::Config.cookbook_path = old_cookbook_path
end
- def upload_cookbook!(uploader, options = {})
- if uploader.respond_to?(:upload_cookbook)
- uploader.upload_cookbook
- else
- uploader.upload_cookbooks
- end
- end
-
def can_have_child?(name, is_dir)
- return false if !is_dir
- return false if root.versioned_cookbooks && name !~ Chef::ChefFS::FileSystem::CookbookDir::VALID_VERSIONED_COOKBOOK_NAME
- return true
+ return false if is_dir && name =~ Chef::ChefFS::FileSystem::CookbookDir::VALID_VERSIONED_COOKBOOK_NAME
end
end
end
diff --git a/lib/chef/chef_fs/file_system/cookbooks_dir_unversioned.rb b/lib/chef/chef_fs/file_system/cookbooks_dir_unversioned.rb
new file mode 100644
index 0000000000..b530e49644
--- /dev/null
+++ b/lib/chef/chef_fs/file_system/cookbooks_dir_unversioned.rb
@@ -0,0 +1,54 @@
+#
+# Author:: John Keiser (<jkeiser@opscode.com>)
+# Copyright:: Copyright (c) 2012 Opscode, 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 'chef/chef_fs/file_system/cookbooks_dir'
+
+class Chef
+ module ChefFS
+ module FileSystem
+ # Represents top-level /cookbooks.
+ # Directories ending with `-<version>` are assumed to be versioned cookbooks.
+ # New cookbooks uploaded will use Chef::Config.versioned_cookbooks to
+ # decide how to create new cookbooks.
+ class CookbooksDirUnversioned < CookbooksDir
+
+ def children
+ @children ||= begin
+ result = root.get_json(api_path).keys.map { |cookbook_name| CookbookDir.new(cookbook_name, self, :exists => true) }
+ result.sort_by(&:name)
+ end
+ end
+
+ def upload_cookbook_from(other, options = {})
+ root.versioned_cookbooks ? upload_versioned_cookbook(other, options) : upload_unversioned_cookbook(other, options)
+ cookbook_to_upload = other.chef_object
+ cookbook_to_upload.freeze_version if options[:freeze]
+ uploader = Chef::CookbookUploader.new(cookbook_to_upload, :force => options[:force], :rest => root.chef_rest)
+
+ with_actual_cookbooks_dir(other.parent.file_path) do
+ uploader.upload_cookbooks
+ end
+ end
+
+ def can_have_child?(name, is_dir)
+ is_dir
+ end
+ end
+ end
+ end
+end