knife-depsolver 2.0.1 → 2.0.2
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/CHANGELOG.md +5 -0
- data/README.md +24 -4
- data/lib/chef/knife/depsolver.rb +72 -3
- data/lib/knife-depsolver/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 4dd5a344b9fcfc7c4e08e5199122981852f396f1
         | 
| 4 | 
            +
              data.tar.gz: 7973c0cd7d13687bc3fe81575e6f6b9bff430f04
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 733d5a061fc6bbaa400af405f8fd1419fef2f0fe2b313360dc91d5adf4e99b2b55c4293d2fea475a452f8260f12ef37e144dc098cbc58432db171121fc9f3a35
         | 
| 7 | 
            +
              data.tar.gz: dca4c199d6ba80069efd8ca2db97d2c94af28580fd8f7ecbcac146d865345d920e12b422739e9153584ffe5608fbb63465ec24dd7726cf1c8c2dcedea7a99838
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -65,9 +65,15 @@ knife depsolver -E production 'role[base],cookbook-B,cookbook-A::foo@3.1.4,cookb | |
| 65 65 |  | 
| 66 66 | 
             
            ### Using knife-depsolver with Chef DK's embedded depsolver
         | 
| 67 67 |  | 
| 68 | 
            -
             | 
| 68 | 
            +
            Mikael Lagerkvist is one of the authors of gecode, the constraint solver used by Chef's depsolver, and he says in the following mail list posts that "Debugging failures in constraint programs is unfortunately a very hard problem."
         | 
| 69 69 |  | 
| 70 | 
            -
             | 
| 70 | 
            +
            http://www.mail-archive.com/users@gecode.org/msg00110.html
         | 
| 71 | 
            +
             | 
| 72 | 
            +
            https://www.mail-archive.com/users@gecode.org/msg00076.html
         | 
| 73 | 
            +
             | 
| 74 | 
            +
            In the first post he goes on to talk about the importance of troubleshooting the whole problem set. With regards to the cookbook depsolver this translates to the importance of troubleshooting the whole run list. When troubleshooting a depsolver issue it is best to keep the run list the same and make changes to the environment cookbook version constraints or possibly to the cookbook universe.
         | 
| 75 | 
            +
             | 
| 76 | 
            +
            knife-depsolver can provide many troubleshooting options by using the depsolver embedded in your workstation's Chef DK to make an identical calculation as the Chef Server.
         | 
| 71 77 |  | 
| 72 78 | 
             
            First, you need to make sure that your version of Chef DK is using the same version of the dep_selector gem as your version of Chef Server. If your Chef DK is using a different version of the dep_selector gem then knife-depsolver's calculations will not be identical to the Chef Server's calculations which will confuse troubleshooting efforts.
         | 
| 73 79 |  | 
| @@ -100,7 +106,9 @@ For example: | |
| 100 106 | 
             
            knife depsolver --env-constraints rehearsal-environment-2017-05-01-18.52.40-5f5843d819ecb0b174f308d76d4336bb7bbfacbf.txt --universe automate-universe-2017-05-01-18.52.40-1c8e59e23530b1e1a8e0b3b3cc5236a29c84e469.txt --expanded-run-list expanded-run-list-2017-05-01-18.52.40-387d90499514747792a805213c30be13d830d31f.txt
         | 
| 101 107 | 
             
            ```
         | 
| 102 108 |  | 
| 103 | 
            -
            Now it is easy to modify  | 
| 109 | 
            +
            Now it is easy to modify the environment cookbook version constraints or the cookbook universe input files to see the impact on the depsolver.
         | 
| 110 | 
            +
             | 
| 111 | 
            +
            #### --timeout
         | 
| 104 112 |  | 
| 105 113 | 
             
            Sometimes it can help to give the depsolver more than the default five seconds to perform its calculations. This can be done by using the "--timeout <seconds>" option to change the depsolver timeout.
         | 
| 106 114 |  | 
| @@ -108,7 +116,19 @@ Sometimes it can help to give the depsolver more than the default five seconds t | |
| 108 116 | 
             
            knife depsolver --env-constraints production-environment-2017-05-01-18.52.40-5f5843d819ecb0b174f308d76d4336bb7bbfacbf.txt --universe my-org-universe-2017-05-01-18.52.40-1c8e59e23530b1e1a8e0b3b3cc5236a29c84e469.txt --expanded-run-list expanded-run-list-2017-05-01-18.52.40-387d90499514747792a805213c30be13d830d31f.txt --timeout 120
         | 
| 109 117 | 
             
            ```
         | 
| 110 118 |  | 
| 111 | 
            -
             | 
| 119 | 
            +
            #### --print-constrained-cookbook-set
         | 
| 120 | 
            +
             | 
| 121 | 
            +
            Sometimes you want to only see the list of cookbooks, and their cookbook dependency version constraints, that ultimately would be sent to the depsolver without actually triggering the depsolver calculation. This is especially helpful when the depsolver isn't returning any results because it can't calculate a solution in a reasonable amount of time. This can be done by using the `--print-constrained-cookbook-set` option.
         | 
| 122 | 
            +
             | 
| 123 | 
            +
            ```
         | 
| 124 | 
            +
            knife depsolver --env-constraints rehearsal-environment-2017-05-01-18.52.40-5f5843d819ecb0b174f308d76d4336bb7bbfacbf.txt --universe automate-universe-2017-05-01-18.52.40-1c8e59e23530b1e1a8e0b3b3cc5236a29c84e469.txt --expanded-run-list expanded-run-list-2017-05-01-18.52.40-387d90499514747792a805213c30be13d830d31f.txt --print-constrained-cookbook-set
         | 
| 125 | 
            +
            ```
         | 
| 126 | 
            +
             | 
| 127 | 
            +
            Now you can review the output to see if you can find anything that could be causing problems for the depsolver. You can make changes to the input files to see the impact on the list of cookbooks that would be sent to the depsolver.
         | 
| 128 | 
            +
             | 
| 129 | 
            +
            If necessary you could also use the list of cookbooks as a starting point for setting version constraints in the environment input file. Then you can modify that set of version constraints and run the depsolver in an effort to get a solution in a reasonable amount of time or to isolate the problem.
         | 
| 130 | 
            +
             | 
| 131 | 
            +
            ### Chef Server < 12.4.0
         | 
| 112 132 |  | 
| 113 133 | 
             
            knife-depsolver requires cookbook universe data in order to use Chef DK's embedded depsolver. The "/universe" API endpoint was added in the Chef Server 12.4.0 release.
         | 
| 114 134 |  | 
    
        data/lib/chef/knife/depsolver.rb
    CHANGED
    
    | @@ -31,9 +31,9 @@ class Chef | |
| 31 31 | 
             
                         long: '--universe FILENAME',
         | 
| 32 32 | 
             
                         description: 'Use the cookbook universe from FILENAME. REQUIRED when using the local depsolver.'
         | 
| 33 33 |  | 
| 34 | 
            -
             | 
| 35 | 
            -
             | 
| 36 | 
            -
             | 
| 34 | 
            +
                  option :expanded_run_list,
         | 
| 35 | 
            +
                         long: '--expanded-run-list FILENAME',
         | 
| 36 | 
            +
                         description: 'Use the expanded run list from FILENAME. REQUIRED when using the local depsolver.'
         | 
| 37 37 |  | 
| 38 38 | 
             
                  option :csv_universe_to_json,
         | 
| 39 39 | 
             
                         long: '--csv-universe-to-json FILENAME',
         | 
| @@ -43,8 +43,13 @@ class Chef | |
| 43 43 | 
             
                       long: '--env-constraints-filter-universe',
         | 
| 44 44 | 
             
                       description: 'Filter the cookbook universe using the environment cookbook version constraints.'
         | 
| 45 45 |  | 
| 46 | 
            +
                  option :print_constrained_cookbook_set,
         | 
| 47 | 
            +
                       long: '--print-constrained-cookbook-set',
         | 
| 48 | 
            +
                       description: 'Only print the constrained cookbook set that would be sent to the depsolver.'
         | 
| 49 | 
            +
             | 
| 46 50 | 
             
                  def run
         | 
| 47 51 | 
             
                    begin
         | 
| 52 | 
            +
                      DepSelector::Debug.log.level = Logger::INFO
         | 
| 48 53 | 
             
                      use_local_depsolver = false
         | 
| 49 54 | 
             
                      if config[:env_constraints_filter_universe]
         | 
| 50 55 | 
             
                        if config[:node] || config[:environment] || config[:timeout] || config[:capture] || config[:expanded_run_list] || config[:csv_universe_to_json]
         | 
| @@ -84,6 +89,10 @@ class Chef | |
| 84 89 | 
             
                        msg("ERROR: The --timeout option requires the --env-constraints, --universe and --expanded-run-list options to be set")
         | 
| 85 90 | 
             
                        exit!
         | 
| 86 91 | 
             
                      end
         | 
| 92 | 
            +
                      if config[:print_constrained_cookbook_set] && !use_local_depsolver
         | 
| 93 | 
            +
                        msg("ERROR: The --print-constrained-cookbook-set option requires the --env-constraints, --universe and --expanded-run-list options to be set")
         | 
| 94 | 
            +
                        exit!
         | 
| 95 | 
            +
                      end
         | 
| 87 96 |  | 
| 88 97 | 
             
                      timeout = (config[:timeout].to_f * 1000).to_i if config[:timeout]
         | 
| 89 98 | 
             
                      timeout ||= 5 * 1000
         | 
| @@ -240,6 +249,11 @@ class Chef | |
| 240 249 |  | 
| 241 250 | 
             
                        data = {environment_constraints: env_ckbk_constraints, all_versions: all_versions, run_list: expanded_run_list_with_split_versions, timeout_ms: timeout}
         | 
| 242 251 |  | 
| 252 | 
            +
                        if config[:print_constrained_cookbook_set]
         | 
| 253 | 
            +
                          print_constrained_cookbook_set(data)
         | 
| 254 | 
            +
                          exit!
         | 
| 255 | 
            +
                        end
         | 
| 256 | 
            +
             | 
| 243 257 | 
             
                        depsolver_start_time = Time.now
         | 
| 244 258 |  | 
| 245 259 | 
             
                        solution = solve(data)
         | 
| @@ -317,6 +331,61 @@ class Chef | |
| 317 331 | 
             
                      end
         | 
| 318 332 | 
             
                    end
         | 
| 319 333 | 
             
                  end
         | 
| 334 | 
            +
             | 
| 335 | 
            +
                  def print_constrained_cookbook_set(data)
         | 
| 336 | 
            +
                    begin
         | 
| 337 | 
            +
                      # create dependency graph from cookbooks
         | 
| 338 | 
            +
                      graph = DepSelector::DependencyGraph.new
         | 
| 339 | 
            +
             | 
| 340 | 
            +
                      env_constraints = data[:environment_constraints].inject({}) do |acc, env_constraint|
         | 
| 341 | 
            +
                        name, version, constraint = env_constraint
         | 
| 342 | 
            +
                        acc[name] = DepSelector::VersionConstraint.new(constraint_to_str(constraint, version))
         | 
| 343 | 
            +
                        acc
         | 
| 344 | 
            +
                      end
         | 
| 345 | 
            +
             | 
| 346 | 
            +
                      all_versions = []
         | 
| 347 | 
            +
             | 
| 348 | 
            +
                      data[:all_versions].each do | vsn|
         | 
| 349 | 
            +
                        name, version_constraints = vsn
         | 
| 350 | 
            +
                        version_constraints.each do |version_constraint| # todo: constraints become an array in ruby
         | 
| 351 | 
            +
                          # due to the erlectricity conversion from
         | 
| 352 | 
            +
                          # tuples
         | 
| 353 | 
            +
                          version, constraints = version_constraint
         | 
| 354 | 
            +
             | 
| 355 | 
            +
                          # filter versions based on environment constraints
         | 
| 356 | 
            +
                          env_constraint = env_constraints[name]
         | 
| 357 | 
            +
                          if (!env_constraint || env_constraint.include?(DepSelector::Version.new(version)))
         | 
| 358 | 
            +
                            package_version = graph.package(name).add_version(DepSelector::Version.new(version))
         | 
| 359 | 
            +
                            constraints.each do |package_constraint|
         | 
| 360 | 
            +
                              constraint_name, constraint_version, constraint = package_constraint
         | 
| 361 | 
            +
                              version_constraint = DepSelector::VersionConstraint.new(constraint_to_str(constraint, constraint_version))
         | 
| 362 | 
            +
                              dependency = DepSelector::Dependency.new(graph.package(constraint_name), version_constraint)
         | 
| 363 | 
            +
                              package_version.dependencies << dependency
         | 
| 364 | 
            +
                            end
         | 
| 365 | 
            +
                          end
         | 
| 366 | 
            +
                        end
         | 
| 367 | 
            +
             | 
| 368 | 
            +
                        # regardless of filter, add package reference to all_packages
         | 
| 369 | 
            +
                        all_versions << graph.package(name)
         | 
| 370 | 
            +
                      end
         | 
| 371 | 
            +
             | 
| 372 | 
            +
                      run_list = data[:run_list].map do |run_list_item|
         | 
| 373 | 
            +
                        item_name, item_constraint_version, item_constraint = run_list_item
         | 
| 374 | 
            +
                        version_constraint = DepSelector::VersionConstraint.new(constraint_to_str(item_constraint,
         | 
| 375 | 
            +
                        item_constraint_version))
         | 
| 376 | 
            +
                        DepSelector::SolutionConstraint.new(graph.package(item_name), version_constraint)
         | 
| 377 | 
            +
                      end
         | 
| 378 | 
            +
             | 
| 379 | 
            +
                      timeout_ms = data[:timeout_ms]
         | 
| 380 | 
            +
                      selector = DepSelector::Selector.new(graph, (timeout_ms / 1000.0))
         | 
| 381 | 
            +
             | 
| 382 | 
            +
                      constrained_cookbook_set = selector.send(:trim_unreachable_packages, selector.dep_graph, run_list)
         | 
| 383 | 
            +
                      constrained_cookbook_set.sort {|x,y| x.name <=> y.name}.each {|c| puts c.to_s.gsub(/Package/, 'Cookbook')}
         | 
| 384 | 
            +
             | 
| 385 | 
            +
                    rescue => e
         | 
| 386 | 
            +
                      puts = [:error, :exception, e.message, [e.backtrace]]
         | 
| 387 | 
            +
                    end
         | 
| 388 | 
            +
                  end
         | 
| 320 389 | 
             
                end
         | 
| 321 390 | 
             
              end
         | 
| 322 391 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: knife-depsolver
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 2.0. | 
| 4 | 
            +
              version: 2.0.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jeremiah Snapp
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2017-05- | 
| 11 | 
            +
            date: 2017-05-11 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies: []
         | 
| 13 13 | 
             
            description: Knife plugin that uses Chef Server to calculate cookbook dependencies
         | 
| 14 14 | 
             
              for a given run_list.
         |