Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 4 commits
  • 5 files changed
  • 0 commit comments
  • 4 contributors
Commits on Jul 19, 2011
@seth seth Ignore already existing data bags for search test 5d8e2c9
Commits on Jul 20, 2011
@ches ches [CHEF-2105] Fix knife cookbook branch regression
Ability to specify a non-master branch with

    knife cookbook site install foobar --branch develop

was broken after 3f8b3bb
4b53525
@danielsdeleo danielsdeleo Merge branch 'CHEF-2105' 24782b3
Nuo Yan fix CHEF-2325 check dependencies when uploading cookbooks a1e69ab
View
2 chef/lib/chef/knife/cookbook_site_install.rb
@@ -44,7 +44,7 @@ class CookbookSiteInstall < Knife
:description => "A colon-separated path to look for cookbooks in",
:proc => lambda { |o| o.split(":") }
- option :branch_default,
+ option :default_branch,
:short => "-B BRANCH",
:long => "--branch BRANCH",
:description => "Default branch to work with",
View
47 chef/lib/chef/knife/cookbook_upload.rb
@@ -1,6 +1,7 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
# Author:: Christopher Walters (<cw@opscode.com>)
+# Author:: Nuo Yan (<yan.nuo@gmail.com>)
# Copyright:: Copyright (c) 2009, 2010 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -18,6 +19,7 @@
#
require 'chef/knife'
+require 'chef/cookbook_version_selector'
class Chef
class Knife
@@ -60,7 +62,7 @@ class CookbookUpload < Knife
:long => '--environment ENVIRONMENT',
:description => "Set ENVIRONMENT's version dependency match the version you're uploading.",
:default => nil
-
+
option :depends,
:short => "-d",
:long => "--include-dependencies",
@@ -72,6 +74,9 @@ def run
assert_environment_valid!
warn_about_cookbook_shadowing
version_constraints_to_update = {}
+ # Get a list of cookbooks and their versions from the server
+ # for checking existence of dependending cookbooks.
+ @server_side_cookbooks = Chef::CookbookVersion.list
if config[:all]
justify_width = cookbook_repo.cookbook_names.map {|name| name.size}.max.to_i + 2
@@ -162,6 +167,7 @@ def upload(cookbook, justify_width)
ui.info("Uploading #{cookbook.name.to_s.ljust(justify_width + 10)} [#{cookbook.version}]")
check_for_broken_links(cookbook)
+ check_dependencies(cookbook)
Chef::CookbookUploader.new(cookbook, config[:cookbook_path], :force => config[:force]).upload_cookbook
rescue Net::HTTPServerException => e
case e.response.code
@@ -191,6 +197,45 @@ def check_for_broken_links(cookbook)
end
end
+ def check_dependencies(cookbook)
+ # for each dependency, check if the version is on the server, or
+ # the version is in the cookbooks being uploaded. If not, exit and warn the user.
+ cookbook.metadata.dependencies.each do |cookbook_name, version|
+ unless check_server_side_cookbooks(cookbook_name, version) || check_uploading_cookbooks(cookbook_name, version)
+ # warn the user and exit
+ ui.error "Cookbook #{cookbook.name} depends on cookbook #{cookbook_name} version #{version},"
+ ui.error "which is not currently being uploaded and cannot be found on the server."
+ exit 1
+ end
+ end
+ end
+
+ def check_server_side_cookbooks(cookbook_name, version)
+ if @server_side_cookbooks[cookbook_name].nil?
+ false
+ else
+ @server_side_cookbooks[cookbook_name]["versions"].each do |versions_hash|
+ return true if Chef::VersionConstraint.new(version).include?(versions_hash["version"])
+ end
+ false
+ end
+ end
+
+ def check_uploading_cookbooks(cookbook_name, version)
+ if config[:all]
+ # check from all local cookbooks in the path
+ unless cookbook_repo[cookbook_name].nil?
+ return Chef::VersionConstraint.new(version).include?(cookbook_repo[cookbook_name].version)
+ end
+ else
+ # check from only those in the command argument
+ if @name_args.include?(cookbook_name)
+ return Chef::VersionConstraint.new(version).include?(cookbook_repo[cookbook_name].version)
+ end
+ end
+ false
+ end
+
end
end
end
View
3 chef/lib/chef/knife/core/cookbook_scm_repo.rb
@@ -34,6 +34,7 @@ def initialize(repo_path, ui, opts={})
@repo_path = repo_path
@ui = ui
@default_branch = 'master'
+ apply_opts(opts)
end
def sanity_check
@@ -133,8 +134,6 @@ def apply_opts(opts)
case option.to_s
when 'default_branch'
@default_branch = value
- else
- raise ArgumentError, "invalid option `#{option}' passed to CookbookRepo.new()"
end
end
end
View
11 chef/spec/unit/knife/core/cookbook_scm_repo_spec.rb
@@ -173,4 +173,15 @@
@cookbook_repo.finalize_updates_to("apache2", "1.2.3").should be_true
end
end
+
+ describe "when a custom default branch is specified" do
+ before do
+ @cookbook_repo = Chef::Knife::CookbookSCMRepo.new(@repo_path, @ui, :default_branch => 'develop')
+ end
+
+ it "resets to default state by checking out the default branch" do
+ @cookbook_repo.should_receive(:shell_out!).with('git checkout develop', :cwd => @repo_path)
+ @cookbook_repo.reset_to_default_state
+ end
+ end
end
View
4 features/data/search-tests/search-test-nodes.rb
@@ -73,7 +73,7 @@
items = []
bag = Chef::DataBag.new
bag.name "toys"
- bag.save
+ bag.save rescue nil
item = Chef::DataBagItem.new
item_data = {
"id" => "marbles",
@@ -102,7 +102,7 @@
items = []
bag = Chef::DataBag.new
bag.name "fruit"
- bag.save
+ bag.save rescue nil
item = Chef::DataBagItem.new
item_data = {
"id" => "citrus",

No commit comments for this range

Something went wrong with that request. Please try again.