diff options
author | Daniel DeLeo <dan@opscode.com> | 2011-03-25 10:42:32 -0700 |
---|---|---|
committer | Daniel DeLeo <dan@opscode.com> | 2011-03-25 10:42:32 -0700 |
commit | 71c71bd76df051f1f619ff5de0218d947b30b536 (patch) | |
tree | 34e4c0d481d8282aaae002b5555f2a504522909a | |
parent | 82e0a8a0cd13e0480a96c6d9c881838bcc92ced4 (diff) | |
download | chef-71c71bd76df051f1f619ff5de0218d947b30b536.tar.gz |
[CHEF-2076] Add integration tests for frozen cookbooks
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | chef/lib/chef/cookbook_uploader.rb | 8 | ||||
-rw-r--r-- | features/api/cookbooks/upload_cookbooks.feature | 14 | ||||
-rw-r--r-- | features/steps/cookbook_steps.rb | 24 | ||||
-rw-r--r-- | features/support/env.rb | 3 |
5 files changed, 48 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore index ee6370db10..774cd65899 100644 --- a/.gitignore +++ b/.gitignore @@ -34,5 +34,6 @@ chef-expander/conf/chef-expander.rb chef-expander/spec/fixtures/expander.log features/data/cookbooks/transfer_remote_files/metadata.json features/data/cookbooks/synchronize_deps/metadata.json +features/data/cookbooks_not_uploaded_at_feature_start/*/metadata.json */tags *~ diff --git a/chef/lib/chef/cookbook_uploader.rb b/chef/lib/chef/cookbook_uploader.rb index 72f45c5ad1..877f320022 100644 --- a/chef/lib/chef/cookbook_uploader.rb +++ b/chef/lib/chef/cookbook_uploader.rb @@ -1,5 +1,6 @@ require 'rest_client' require 'chef/exceptions' +require 'chef/knife/cookbook_metadata' require 'chef/checksum_cache' require 'chef/sandbox' require 'chef/cookbook_version' @@ -12,6 +13,7 @@ class Chef attr_reader :cookbook attr_reader :path attr_reader :opts + attr_reader :rest # Creates a new CookbookUploader. # ===Arguments: @@ -24,15 +26,17 @@ class Chef # uploading the cookbook. This allows frozen CookbookVersion # documents on the server to be overwritten (otherwise a 409 is # returned by the server) + # * :rest A Chef::REST object that you have configured the way you like it. + # If you don't provide this, one will be created using the values + # in Chef::Config. def initialize(cookbook, path, opts={}) @cookbook, @path, @opts = cookbook, path, opts + @rest = opts[:rest] || Chef::REST.new(Chef::Config[:chef_server_url]) end def upload_cookbook Chef::Log.info("Saving #{cookbook.name}") - rest = Chef::REST.new(Chef::Config[:chef_server_url]) - # Syntax Check validate_cookbook # Generate metadata.json from metadata.rb diff --git a/features/api/cookbooks/upload_cookbooks.feature b/features/api/cookbooks/upload_cookbooks.feature index a3ce81a2fc..a8562d1e4b 100644 --- a/features/api/cookbooks/upload_cookbooks.feature +++ b/features/api/cookbooks/upload_cookbooks.feature @@ -141,3 +141,17 @@ Feature: CRUD cookbooks Then I should not get an exception When I create a cookbook named 'testcookbook_invalid_empty_except_metadata' with only the metadata file Then I should get a '400 "Bad Request"' exception + + @freeze_cookbook_version + Scenario: Create a frozen Cookbook Version + Given I am an administrator + And I have uploaded a frozen cookbook named 'testcookbook_valid' at version '0.1.0' + When I 'GET' the path '/cookbooks/testcookbook_valid/0.1.0' + Then the cookbook version document should be frozen + + @freeze_cookbook_version @overwrite_frozen_version + Scenario: Cannot overwrite a frozen Cookbook Version + Given I am an administrator + And I have uploaded a frozen cookbook named 'testcookbook_valid' at version '0.1.0' + When I upload a cookbook named 'testcookbook_valid' at version '0.1.0' + Then I should get a '409 "Conflict"' exception diff --git a/features/steps/cookbook_steps.rb b/features/steps/cookbook_steps.rb index cae8f07b6c..3e4e78f9c0 100644 --- a/features/steps/cookbook_steps.rb +++ b/features/steps/cookbook_steps.rb @@ -19,6 +19,7 @@ # require 'chef/cookbook/file_system_file_vendor' +require 'chef/cookbook_uploader' def compare_manifests(manifest1, manifest2) Chef::CookbookVersion::COOKBOOK_SEGMENTS.each do |segment| @@ -67,6 +68,10 @@ Given "I upload the cookbook" do shell_out!("#{KNIFE_CMD} cookbook upload -c #{KNIFE_CONFIG} -a -o #{INTEGRATION_COOKBOOKS}") end +Given "I have uploaded a frozen cookbook named '$cookbook_name' at version '$cookbook_version'" do |name, version| + shell_out!("#{KNIFE_CMD} cookbook upload #{name} -c #{KNIFE_CONFIG} -o #{EXTRA_COOKBOOKS} --freeze --force") +end + Given /^I delete the cookbook's on disk checksum files$/ do #pp :checksums => @last_uploaded_cookbook.checksums.keys #pending # express the regexp above with the code you wish you had @@ -103,6 +108,21 @@ end # Cookbook upload/download-specific steps ##### +When "I upload a cookbook named '$name' at version '$version'" do |name, version| + + # This is total crap :( + Chef::Config[:client_key] = rest.auth_credentials.key_file + Chef::Config[:node_name] = rest.auth_credentials.client_name + + cookbook = @cookbook_loader_not_uploaded_at_feature_start[name] + uploader = Chef::CookbookUploader.new(cookbook, [EXTRA_COOKBOOKS], :rest => rest) + begin + uploader.upload_cookbook + rescue Exception => e + @exception = e + end +end + When /^I create a versioned cookbook(?: named '(.*?)')?(?: versioned '(.*?)')? with '(.*?)'$/ do |request_name, request_version, cookbook_name| cookbook = @cookbook_loader_not_uploaded_at_feature_start[cookbook_name] raise ArgumentError, "no such cookbook in cookbooks_not_uploaded_at_feature_start: #{cookbook_name}" unless cookbook @@ -329,6 +349,10 @@ Then /^the metadata should include a dependency on '(.+)'$/ do |key| inflated_response.metadata.dependencies.should have_key(key) end +Then "the cookbook version document should be frozen" do + inflated_response.should be_frozen_version +end + RSpec::Matchers.define :have_been_deleted do match do |file_name| ! File.exist?(file_name) diff --git a/features/support/env.rb b/features/support/env.rb index b38a1d7e52..d29d60776f 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -24,6 +24,7 @@ KNIFE_CONFIG = CHEF_PROJECT_ROOT + '/features/data/config/knife.rb' KNIFE_CMD = File.expand_path(File.join(CHEF_PROJECT_ROOT, "chef", "bin", "knife")) FEATURES_DATA = File.join(CHEF_PROJECT_ROOT, "features", "data") INTEGRATION_COOKBOOKS = File.join(FEATURES_DATA, "cookbooks") +EXTRA_COOKBOOKS = File.join(FEATURES_DATA, "cookbooks_not_uploaded_at_feature_start") $:.unshift(CHEF_PROJECT_ROOT) $:.unshift(CHEF_PROJECT_ROOT + '/chef/lib') @@ -42,6 +43,8 @@ require 'chef/checksum' require 'chef/sandbox' require 'chef/solr_query' require 'chef/certificate' +require 'chef/cookbook_version' +require 'chef/cookbook_loader' require 'chef/mixin/shell_out' require 'tmpdir' require 'chef/streaming_cookbook_uploader' |