diff options
author | John Keiser <john@johnkeiser.com> | 2016-01-13 15:08:48 -0800 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2016-01-15 09:37:43 -0800 |
commit | 15eeec09c22da15370152a40311f085f0aced9e2 (patch) | |
tree | fb4aea0b7252b296294f493ddbaa8328a10c390e | |
parent | 7fd174277679739fb2c7aa628a26fade406655df (diff) | |
download | chef-15eeec09c22da15370152a40311f085f0aced9e2.tar.gz |
Make upload cookbook_artifacts work
4 files changed, 28 insertions, 4 deletions
diff --git a/lib/chef/chef_fs/file_system/chef_server/chef_server_root_dir.rb b/lib/chef/chef_fs/file_system/chef_server/chef_server_root_dir.rb index 969cea876e..9c9a0d1001 100644 --- a/lib/chef/chef_fs/file_system/chef_server/chef_server_root_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/chef_server_root_dir.rb @@ -82,6 +82,7 @@ class Chef @environment = chef_config[:environment] @repo_mode = chef_config[:repo_mode] @versioned_cookbooks = chef_config[:versioned_cookbooks] + @policy_document_native_api = chef_config[:policy_document_native_api] @root_name = root_name @cookbook_version = options[:cookbook_version] # Used in knife diff and download for server cookbook version end @@ -93,6 +94,7 @@ class Chef attr_reader :repo_mode attr_reader :cookbook_version attr_reader :versioned_cookbooks + attr_reader :policy_document_native_api def fs_description "Chef server at #{chef_server_url} (user #{chef_username}), repo_mode = #{repo_mode}" diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbook_artifact_dir.rb b/lib/chef/chef_fs/file_system/chef_server/cookbook_artifact_dir.rb index ad22b6a64c..ff3cde51a8 100644 --- a/lib/chef/chef_fs/file_system/chef_server/cookbook_artifact_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/cookbook_artifact_dir.rb @@ -27,6 +27,10 @@ class Chef super(name, parent) @cookbook_name, dash, @version = name.rpartition('-') end + + def copy_from(other, options = {}) + raise OperationNotAllowedError.new(:write, self, nil, "cannot be updated: cookbook artifacts are immutable once uploaded") + end end end end diff --git a/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb b/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb index adc7003013..b001c28dc4 100644 --- a/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb +++ b/lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb @@ -56,7 +56,7 @@ class Chef # to make this work. So instead, we make a temporary cookbook # symlinking back to real cookbook, and upload the proxy. def upload_cookbook(other, options) - cookbook_name = Chef::ChefFS::FileSystem::Repository::ChefRepositoryFileSystemCookbookDir.canonical_cookbook_name(other.name) + cookbook_name, dash, identifier = other.name.rpartition('-') Dir.mktmpdir do |temp_cookbooks_path| proxy_cookbook_path = "#{temp_cookbooks_path}/#{cookbook_name}" @@ -69,10 +69,11 @@ class Chef proxy_loader.load_cookbooks cookbook_to_upload = proxy_loader.cookbook_version + cookbook_to_upload.identifier = identifier cookbook_to_upload.freeze_version if options[:freeze] # Instantiate a new uploader based on the proxy loader - uploader = Chef::CookbookUploader.new(cookbook_to_upload, :force => options[:force], :rest => root.chef_rest) + uploader = Chef::CookbookUploader.new(cookbook_to_upload, force: options[:force], rest: root.chef_rest, policy_mode: true) with_actual_cookbooks_dir(temp_cookbooks_path) do uploader.upload_cookbooks diff --git a/spec/integration/knife/upload_spec.rb b/spec/integration/knife/upload_spec.rb index 79dae99acf..6ef40a1d98 100644 --- a/spec/integration/knife/upload_spec.rb +++ b/spec/integration/knife/upload_spec.rb @@ -1288,6 +1288,7 @@ EOM file "clients/x.json", { "public_key" => ChefZero::PUBLIC_KEY } file "containers/x.json", {} file "cookbooks/x/metadata.rb", cb_metadata("x", "1.0.0") + file "cookbook_artifacts/x-1x1/metadata.rb", cb_metadata("x", "1.0.0") file "data_bags/x/y.json", {} file "environments/x.json", {} file "groups/x.json", {} @@ -1306,6 +1307,7 @@ EOM Updated /acls/groups/blah.json Created /clients/x.json Created /containers/x.json +Created /cookbook_artifacts/x-1x1 Created /cookbooks/x Created /data_bags/x Created /data_bags/x/y.json @@ -1322,6 +1324,7 @@ Created /roles/x.json EOM expect(api.get("association_requests").map { |a| a["username"] }).to eq([ "foo" ]) expect(api.get("users").map { |a| a["user"]["username"] }).to eq([ "bar" ]) + knife("diff --name-status --diff-filter=AMT /").should_succeed "" end context "When the chef server has an identical copy of each thing" do @@ -1333,6 +1336,7 @@ EOM # acl_for %w(organizations foo groups blah) client "x", {} cookbook "x", "1.0.0" + cookbook_artifact "x", "1x1", "metadata.rb" => cb_metadata("x", "1.0.0") container "x", {} data_bag "x", { "y" => {} } environment "x", {} @@ -1345,7 +1349,7 @@ EOM policy_group "x", { "policies" => { "x" => { "revision_id" => "1.0.0" }, - "blah" => { "revision_id" => "1.0.0" }, + "blah" => { "revision_id" => "1.0.0" } } } role "x", {} @@ -1370,12 +1374,25 @@ EOM end end + context "When the chef server has a slightly different copy of the cookbook artifact" do + before do + cookbook_artifact "x", "1x1", { "recipes" => { "default.rb" => "" } } + end + + it "should fail because cookbook_artifacts cannot be updated" do + knife("upload /cookbook_artifacts/x-1x1").should_fail <<EOM +ERROR: /cookbook_artifacts/x-1x1 cannot be updated: cookbook artifacts are immutable once uploaded. +EOM + end + end + context "When the chef server has a slightly different copy of each thing (except policy revisions)" do before do # acl_for %w(organizations foo groups blah) client "x", { "validator" => true } container "x", {} cookbook "x", "1.0.0", { "recipes" => { "default.rb" => "" } } + cookbook_artifact "x", "1x1", { "metadata.rb" => cb_metadata("x", "1.0.0") } data_bag "x", { "y" => { "a" => "b" } } environment "x", { "description" => "foo" } group "x", { "groups" => [ "admin" ] } @@ -1386,7 +1403,7 @@ EOM policy_group "x", { "policies" => { "x" => { "revision_id" => "1.0.1" }, - "y" => { "revision_id" => "1.0.0" }, + "y" => { "revision_id" => "1.0.0" } } } role "x", { "run_list" => [ "blah" ] } |