Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Don't attempt an upload when all cookbooks exist on the server
Browse files Browse the repository at this point in the history
Chef Server treats an API request to upload zero files as an error, so
skip the upload when all required cookbooks are present on the server.
  • Loading branch information
danielsdeleo committed Oct 31, 2014
1 parent 9e47215 commit fbdb61b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/chef-dk/policyfile/uploader.rb
Expand Up @@ -119,7 +119,7 @@ def cookbook_versions_for_policy
def upload_cookbooks
ui.msg("WARN: Uploading cookbooks using semver compat mode")

uploader.upload_cookbooks
uploader.upload_cookbooks unless cookbook_versions_to_upload.empty?

reused_cbs, uploaded_cbs = cookbook_versions_for_policy.partition do |cb_with_lock|
remote_already_has_cookbook?(cb_with_lock.cookbook)
Expand Down
31 changes: 31 additions & 0 deletions spec/unit/policyfile/uploader_spec.rb
Expand Up @@ -283,6 +283,37 @@ def lock_double(name, dotted_decimal_id)

end

context "with a set of cookbooks that all exist on the server" do

before do
# Have this one:
lock_double("build-essential", "67369247788170534.26353953100055918.55660493423796")
end

let(:expected_cookbooks_for_upload) do
[]
end

it "lists no cookbooks as needing to be uploaded" do
expect(policyfile_lock).to receive(:validate_cookbooks!)
expect(http_client).to receive(:get).with('cookbooks?num_versions=all').and_return(existing_cookbook_on_remote)

expect(uploader.cookbook_versions_to_upload).to eq(expected_cookbooks_for_upload)
end

it "skips cookbooks uploads, then uploads the policy" do
expect(policyfile_lock).to receive(:validate_cookbooks!)
expect(http_client).to receive(:get).with('cookbooks?num_versions=all').and_return(existing_cookbook_on_remote)

expect(uploader.uploader).to_not receive(:upload_cookbooks)

# behavior for these tested above
expect(uploader).to receive(:data_bag_create)
expect(uploader).to receive(:data_bag_item_create)

uploader.upload
end
end
end

end
Expand Down

0 comments on commit fbdb61b

Please sign in to comment.