berkshelf_ext 1.0.12 → 1.0.14

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## v1.0.14
2
+ * Use chef configurations from berks config if unset by knife
3
+ * Fix exception namespacing
4
+ * Provide path information when Berksfile processing fails
5
+ * Allow limiting depth of nested berksfiles `--nested-depth n`
6
+ * Attempt to properly identify cookbook causing solution failure
7
+ * Provide better output for solution failures
8
+
1
9
  ## v1.0.12
2
10
  * Add proper support for metadata with missing name
3
11
 
@@ -44,20 +44,30 @@ class RidleyMocker
44
44
  cv.manifest['name'] = "#{cv.metadata.name}-#{cv.version}"
45
45
  cv.name = cv.manifest['cookbook_name'] = cv.metadata.name
46
46
  cv.freeze_version if upload_options.delete(:freeze)
47
+ puts " -> Knife upload to: #{Chef::Config[:chef_server_url]}"
47
48
  Chef::CookbookUploader.new([cv], cookbook.path, upload_options).upload_cookbooks
48
49
  @ckbk = cv
49
50
  end
50
51
 
51
52
  def chef_config!
52
53
  cwd = Dir.pwd.split('/')
53
- until(cwd.empty?)
54
+ found = false
55
+ until(found || cwd.empty?)
54
56
  knife_conf = File.join(cwd.join('/'), '.chef/knife.rb')
55
- if(File.exists?(knife_conf))
56
- Chef::Config.from_file(knife_conf)
57
- return
57
+ if(found = File.exists?(knife_conf))
58
+ begin
59
+ Chef::Config.from_file(knife_conf)
60
+ rescue
61
+ end
62
+ end
63
+ cwd.pop
64
+ end
65
+ %w(chef_server_url validation_client_name validation_key client_key node_name).each do |k|
66
+ key = k.to_sym
67
+ if(value = Berkshelf::Config.instance[:chef][key])
68
+ Chef::Config[key] = value
58
69
  end
59
70
  end
60
- raise 'Failed to locate knife.rb file to configure chef!'
61
71
  end
62
72
 
63
73
  end
@@ -22,7 +22,7 @@ module BerkshelfExt
22
22
  Dir.chdir(File.dirname(path))
23
23
  instance_eval(content, File.expand_path(path), 1)
24
24
  rescue => e
25
- raise BerksfileReadError.new(e), "An error occurred while reading the Berksfile: #{e.to_s}"
25
+ raise ::Berkshelf::BerksfileReadError.new(e), "An error occurred while reading the Berksfile (#{path}): #{e.to_s}"
26
26
  ensure
27
27
  Dir.chdir(initial_path)
28
28
  end
@@ -84,13 +84,23 @@ module BerkshelfExt
84
84
  # solution and not the dependency that caused the failure, run
85
85
  # each dependency through the graph individually so we can
86
86
  # provide a useful error string
87
- demands.each do |demand|
87
+ demands.reverse.each do |demand|
88
88
  begin
89
89
  solution = Solve.it!(graph, [demand])
90
90
  rescue Solve::Errors::NoSolutionError
91
- raise Berkshelf::NoSolution.new(
92
- "Failed to resolve dependencies for:\n#{demand.join(': ')}\nDependencies: " <<
93
- @sources[demand.first].cached_cookbook.dependencies.map{|n,v| " #{n}: #{v}"}.join("\n")
91
+ deps = @sources[demand.first].cached_cookbook.dependencies.map{|n,v| "#{n.strip}-#{v.sub(%r{^[^0-9]+}, '').strip}"}
92
+ cur = @sources.values.map(&:cached_cookbook).map{|c| "#{c.metadata.name}-#{c.metadata.version}"}
93
+ failed_on = Array(deps - cur)
94
+ # TODO: if failed on is empty, resort and solve to attempt
95
+ # to locate root cause
96
+ raise Berkshelf::NoSolution.new(
97
+ "\n\nFailed to resolve dependencies for:\n#{demand.join(': ')}\n" <<
98
+ "Probable failure on: #{failed_on.empty? ? 'UNKNOWN!?' : failed_on.join(', ')}\n" <<
99
+ "Dependencies:\n" <<
100
+ @sources[demand.first].cached_cookbook.dependencies.map{|n,v| " #{n}: #{v}"}.sort.join("\n") <<
101
+ "\nCurrently loaded:\n" <<
102
+ @sources.values.map(&:cached_cookbook).map{|c| " #{c.name}: #{c.metadata.name} - #{c.metadata.version}"}.sort.join("\n") <<
103
+ "\n"
94
104
  )
95
105
  end
96
106
  end
@@ -3,9 +3,15 @@ module BerkshelfExt
3
3
  module Cli
4
4
  class << self
5
5
  def included(klass)
6
- klass.tasks['upload'].options[:nested_berksfiles] = Thor::Option.new(
7
- 'nested_berksfiles', :type => :boolean, :default => false,
8
- :desc => 'Use Berksfiles found within cookbooks specifed in Berksfile'
6
+ klass.tasks['upload'].options.update(
7
+ :nested_berksfiles => Thor::Option.new(
8
+ 'nested_berksfiles', :type => :boolean, :default => false,
9
+ :desc => 'Use Berksfiles found within cookbooks specifed in Berksfile'
10
+ ),
11
+ :nested_depth => Thor::Option.new(
12
+ 'nested_depth', :type => :numeric, :default => 0,
13
+ :desc => 'Restrict nesting to this depth. Defaults to "0" (no restriction)'
14
+ )
9
15
  )
10
16
  end
11
17
  end
@@ -26,7 +32,8 @@ module BerkshelfExt
26
32
  self.downloader,
27
33
  sources: sources(options),
28
34
  skip_dependencies: options[:skip_dependencies],
29
- nested_berksfiles: options[:nested_berksfiles]
35
+ nested_berksfiles: options[:nested_berksfiles],
36
+ nested_depth: options[:nested_depth]
30
37
  )
31
38
  end
32
39
  end
@@ -43,6 +50,7 @@ module BerkshelfExt
43
50
  end
44
51
 
45
52
  def nested_berksfiles_initialize(downloader, options={})
53
+ @nested_depth_limit = options[:nested_depth].to_i
46
54
  skip_deps = options[:skip_dependencies]
47
55
  options[:skip_dependencies] = true
48
56
  non_nested_berksfiles_initialize(downloader, options)
@@ -57,18 +65,24 @@ module BerkshelfExt
57
65
  end
58
66
  end
59
67
 
60
- def process_nested_berksfiles(srcs)
68
+ def process_nested_berksfiles(srcs, depth=0)
61
69
  srcs.map(&:name).each do |name|
70
+ next unless @sources[name].location.is_a?(Berkshelf::GitLocation) || @sources[name].location.is_a?(Berkshelf::PathLocation)
62
71
  berks_path = File.join(@sources[name].cached_cookbook.path, 'Berksfile')
63
72
  if(File.exists?(berks_path))
64
73
  berksfile = Berkshelf::Berksfile.from_file(berks_path)
74
+ puts "processing berksfile: #{berks_path}"
65
75
  new_sources = berksfile.sources.delete_if do |new_src|
66
- @sources.has_key?(new_src.name)
76
+ @sources.has_key?(new_src.name) || new_src.location.class != Berkshelf::GitLocation
67
77
  end
68
78
  new_sources.each do |source|
69
79
  add_source(source, false)
70
80
  end
71
- process_nested_berksfiles(new_sources)
81
+ if((depth + 1) >= @nested_depth_limit)
82
+ puts "Nested depth threshold reached. Halting nesting on this branch path is halted! (leaf file: #{berks_path})"
83
+ else
84
+ process_nested_berksfiles(new_sources, depth + 1)
85
+ end
72
86
  end
73
87
  end
74
88
  end
@@ -2,6 +2,6 @@ module BerkshelfExt
2
2
  class Version < Gem::Version
3
3
  end
4
4
 
5
- VERSION = Version.new('1.0.12')
5
+ VERSION = Version.new('1.0.14')
6
6
  BERKSHELF_CONSTRAINT = '~> 1.3.1'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berkshelf_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12
4
+ version: 1.0.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-17 00:00:00.000000000 Z
12
+ date: 2013-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: berkshelf