batali-wedge 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/batali-wedge/sync.rb +76 -80
 - data/lib/batali-wedge/version.rb +1 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 64024acd8e0fb94d33b225a9cc7f94d72370aae6
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 2f1d3e2e0769fd0e417b6e67928d1c52dd5498e3
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 5653e53bda177ade9995fc2348eb85d6a8f9d1ece305d30d29077b5381d24e42ea42215c72499152f6f4766b92d333c24f7f73dd9e05d5db6faa1fcc8a98f6c1
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: ad7a959f9a0aa95598d0d273ed6981eddaaba5e0bdae9479b3fae92dc0a42c294f9e37c5332032beaa639165330bfe55b6c6562081aba4a7382a95c409935ebe
         
     | 
    
        data/lib/batali-wedge/sync.rb
    CHANGED
    
    | 
         @@ -1,97 +1,93 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'batali-wedge'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
              module Sync
         
     | 
| 
      
 3 
     | 
    
         
            +
            class Chef::PolicyBuilder::ExpandNodeObject
         
     | 
| 
       5 
4 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
      
 5 
     | 
    
         
            +
              # Provide override to force Batali resolution
         
     | 
| 
      
 6 
     | 
    
         
            +
              def sync_cookbooks
         
     | 
| 
      
 7 
     | 
    
         
            +
                Chef::Log.debug("Synchronizing cookbooks")
         
     | 
| 
       9 
8 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
      
 9 
     | 
    
         
            +
                begin
         
     | 
| 
      
 10 
     | 
    
         
            +
                  events.cookbook_resolution_start(@expanded_run_list_with_versions)
         
     | 
| 
      
 11 
     | 
    
         
            +
                  cookbook_hash = batali_cookbook_hash
         
     | 
| 
       13 
12 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
      
 13 
     | 
    
         
            +
                rescue Exception => e
         
     | 
| 
      
 14 
     | 
    
         
            +
                  # TODO: wrap/munge exception to provide helpful error output
         
     | 
| 
      
 15 
     | 
    
         
            +
                  events.cookbook_resolution_failed(@expanded_run_list_with_versions, e)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  raise
         
     | 
| 
      
 17 
     | 
    
         
            +
                else
         
     | 
| 
      
 18 
     | 
    
         
            +
                  events.cookbook_resolution_complete(cookbook_hash)
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
       21 
20 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
      
 21 
     | 
    
         
            +
                synchronizer = Chef::CookbookSynchronizer.new(cookbook_hash, events)
         
     | 
| 
      
 22 
     | 
    
         
            +
                if temporary_policy?
         
     | 
| 
      
 23 
     | 
    
         
            +
                  synchronizer.remove_obsoleted_files = false
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
                synchronizer.sync_cookbooks
         
     | 
| 
       27 
26 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
      
 27 
     | 
    
         
            +
                # register the file cache path in the cookbook path so that CookbookLoader actually picks up the synced cookbooks
         
     | 
| 
      
 28 
     | 
    
         
            +
                Chef::Config[:cookbook_path] = File.join(Chef::Config[:file_cache_path], "cookbooks")
         
     | 
| 
       30 
29 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
      
 30 
     | 
    
         
            +
                cookbook_hash
         
     | 
| 
       32 
31 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
      
 32 
     | 
    
         
            +
              end
         
     | 
| 
       34 
33 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                    end
         
     | 
| 
      
 34 
     | 
    
         
            +
              # Generate expected cookbook version hash
         
     | 
| 
      
 35 
     | 
    
         
            +
              #
         
     | 
| 
      
 36 
     | 
    
         
            +
              # @return [Hash]
         
     | 
| 
      
 37 
     | 
    
         
            +
              def batali_cookbook_hash
         
     | 
| 
      
 38 
     | 
    
         
            +
                Chef::Log.warn 'Resolving cookbooks via Batali!'
         
     | 
| 
      
 39 
     | 
    
         
            +
                system = batali_build_system
         
     | 
| 
      
 40 
     | 
    
         
            +
                constraints = Smash[
         
     | 
| 
      
 41 
     | 
    
         
            +
                  api_service.get_rest("environments/#{node.chef_environment}").cookbook_versions.to_a
         
     | 
| 
      
 42 
     | 
    
         
            +
                ]
         
     | 
| 
      
 43 
     | 
    
         
            +
                @expanded_run_list_with_versions.each do |item|
         
     | 
| 
      
 44 
     | 
    
         
            +
                  c_name, c_version = item.split('@')
         
     | 
| 
      
 45 
     | 
    
         
            +
                  c_name = c_name.split('::').first
         
     | 
| 
      
 46 
     | 
    
         
            +
                  if(c_version)
         
     | 
| 
      
 47 
     | 
    
         
            +
                    constraints[c_name] = c_version
         
     | 
| 
      
 48 
     | 
    
         
            +
                  elsif(constraints[c_name].nil?)
         
     | 
| 
      
 49 
     | 
    
         
            +
                    constraints[c_name] = '> 0'
         
     | 
| 
       52 
50 
     | 
    
         
             
                  end
         
     | 
| 
       53 
     | 
    
         
            -
                  requirements = Grimoire::RequirementList.new(
         
     | 
| 
       54 
     | 
    
         
            -
                    :name => :batali_resolv,
         
     | 
| 
       55 
     | 
    
         
            -
                    :requirements => constraints.to_a
         
     | 
| 
       56 
     | 
    
         
            -
                  )
         
     | 
| 
       57 
     | 
    
         
            -
                  solver = Grimoire::Solver.new(
         
     | 
| 
       58 
     | 
    
         
            -
                    :requirements => requirements,
         
     | 
| 
       59 
     | 
    
         
            -
                    :system => system
         
     | 
| 
       60 
     | 
    
         
            -
                  )
         
     | 
| 
       61 
     | 
    
         
            -
                  results = solver.generate!
         
     | 
| 
       62 
     | 
    
         
            -
                  solution = results.pop
         
     | 
| 
       63 
     | 
    
         
            -
                  solution_output = solution.units.sort_by(&:name).map{|u| "#{u.name}<#{u.version}>"}.join(', ')
         
     | 
| 
       64 
     | 
    
         
            -
                  Chef::Log.warn "Batali cookbook resolution: #{solution_output}"
         
     | 
| 
       65 
     | 
    
         
            -
                  Hash[
         
     | 
| 
       66 
     | 
    
         
            -
                    solution.units.map do |unit|
         
     | 
| 
       67 
     | 
    
         
            -
                      [unit.name, api_service.get_rest("cookbooks/#{unit.name}/#{unit.version}")]
         
     | 
| 
       68 
     | 
    
         
            -
                    end
         
     | 
| 
       69 
     | 
    
         
            -
                  ]
         
     | 
| 
       70 
51 
     | 
    
         
             
                end
         
     | 
| 
      
 52 
     | 
    
         
            +
                requirements = Grimoire::RequirementList.new(
         
     | 
| 
      
 53 
     | 
    
         
            +
                  :name => :batali_resolv,
         
     | 
| 
      
 54 
     | 
    
         
            +
                  :requirements => constraints.to_a
         
     | 
| 
      
 55 
     | 
    
         
            +
                )
         
     | 
| 
      
 56 
     | 
    
         
            +
                solver = Grimoire::Solver.new(
         
     | 
| 
      
 57 
     | 
    
         
            +
                  :requirements => requirements,
         
     | 
| 
      
 58 
     | 
    
         
            +
                  :system => system
         
     | 
| 
      
 59 
     | 
    
         
            +
                )
         
     | 
| 
      
 60 
     | 
    
         
            +
                results = solver.generate!
         
     | 
| 
      
 61 
     | 
    
         
            +
                solution = results.pop
         
     | 
| 
      
 62 
     | 
    
         
            +
                solution_output = solution.units.sort_by(&:name).map{|u| "#{u.name}<#{u.version}>"}.join(', ')
         
     | 
| 
      
 63 
     | 
    
         
            +
                Chef::Log.warn "Batali cookbook resolution: #{solution_output}"
         
     | 
| 
      
 64 
     | 
    
         
            +
                Hash[
         
     | 
| 
      
 65 
     | 
    
         
            +
                  solution.units.map do |unit|
         
     | 
| 
      
 66 
     | 
    
         
            +
                    [unit.name, api_service.get_rest("cookbooks/#{unit.name}/#{unit.version}")]
         
     | 
| 
      
 67 
     | 
    
         
            +
                  end
         
     | 
| 
      
 68 
     | 
    
         
            +
                ]
         
     | 
| 
      
 69 
     | 
    
         
            +
              end
         
     | 
| 
       71 
70 
     | 
    
         | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
                    end
         
     | 
| 
       81 
     | 
    
         
            -
                  end.flatten.map do |ckbk|
         
     | 
| 
       82 
     | 
    
         
            -
                    Batali::Unit.new(
         
     | 
| 
       83 
     | 
    
         
            -
                      Smash.new(
         
     | 
| 
       84 
     | 
    
         
            -
                        :name => ckbk.split('/').first,
         
     | 
| 
       85 
     | 
    
         
            -
                        :version => ckbk.split('/').last,
         
     | 
| 
       86 
     | 
    
         
            -
                        :dependencies => api_service.get_rest("cookbooks/#{ckbk}").metadata.dependencies.to_a
         
     | 
| 
       87 
     | 
    
         
            -
                      )
         
     | 
| 
       88 
     | 
    
         
            -
                    )
         
     | 
| 
      
 71 
     | 
    
         
            +
              # Build the base system for generating solution
         
     | 
| 
      
 72 
     | 
    
         
            +
              #
         
     | 
| 
      
 73 
     | 
    
         
            +
              # @return [Grimoire::System]
         
     | 
| 
      
 74 
     | 
    
         
            +
              def batali_build_system
         
     | 
| 
      
 75 
     | 
    
         
            +
                system = Grimoire::System.new
         
     | 
| 
      
 76 
     | 
    
         
            +
                units = api_service.get_rest('cookbooks').map do |c_name, meta|
         
     | 
| 
      
 77 
     | 
    
         
            +
                  meta['versions'].map do |info|
         
     | 
| 
      
 78 
     | 
    
         
            +
                    "#{c_name}/#{info['version']}"
         
     | 
| 
       89 
79 
     | 
    
         
             
                  end
         
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
                   
     | 
| 
      
 80 
     | 
    
         
            +
                end.flatten.map do |ckbk|
         
     | 
| 
      
 81 
     | 
    
         
            +
                  Batali::Unit.new(
         
     | 
| 
      
 82 
     | 
    
         
            +
                    Smash.new(
         
     | 
| 
      
 83 
     | 
    
         
            +
                      :name => ckbk.split('/').first,
         
     | 
| 
      
 84 
     | 
    
         
            +
                      :version => ckbk.split('/').last,
         
     | 
| 
      
 85 
     | 
    
         
            +
                      :dependencies => api_service.get_rest("cookbooks/#{ckbk}").metadata.dependencies.to_a
         
     | 
| 
      
 86 
     | 
    
         
            +
                    )
         
     | 
| 
      
 87 
     | 
    
         
            +
                  )
         
     | 
| 
       92 
88 
     | 
    
         
             
                end
         
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
      
 89 
     | 
    
         
            +
                system.add_unit(*units)
         
     | 
| 
      
 90 
     | 
    
         
            +
                system
         
     | 
| 
       94 
91 
     | 
    
         
             
              end
         
     | 
| 
       95 
     | 
    
         
            -
            end
         
     | 
| 
       96 
92 
     | 
    
         | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
      
 93 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/batali-wedge/version.rb
    CHANGED