chef / cookbook-omnifetch

Fetch Chef Cookbooks from Various Sources to a Local Cache
Apache License 2.0
6 stars 9 forks source link

Chef install fails to create Policy Lock File #30

Closed ashxjain closed 4 years ago

ashxjain commented 4 years ago

Version:

❯ chef --version Chef Workstation version: 20.7.81 Chef Infra Client version: 16.2.73 Chef InSpec version: 4.21.1 Chef CLI version: 3.0.11 Test Kitchen version: 2.5.2 Cookstyle version: 6.9.0

Environment:

Tried on my Mac

Scenario:

Chef install fails. After patching this commit: https://github.com/chef/chef/pull/10140.

❯ chef install testpolicy.rb -c knife_local.rb -D
Building policy testpolicy
Expanded run list: recipe[runstatus_handler]
Caching Cookbooks...
Installing runstatus_handler 1.0.0
Error: Failed to generate Policyfile.lock
Reason: (Errno::ENOENT) No such file or directory @ rb_file_s_rename - (/Users/ashishjain/.chef-workstation/cache/.cache_tmp/metadata-installer/_cookbooks_runstatus_handler_1_0_0_493020545, /Users/ashishjain/.chef-workstation/cache/cookbooks/runstatus_handler-1.0.0)
/opt/chef-workstation/embedded/lib/ruby/2.7.0/fileutils.rb:548:in `rename'
/opt/chef-workstation/embedded/lib/ruby/2.7.0/fileutils.rb:548:in `block in mv'
/opt/chef-workstation/embedded/lib/ruby/2.7.0/fileutils.rb:1588:in `block in fu_each_src_dest'
/opt/chef-workstation/embedded/lib/ruby/2.7.0/fileutils.rb:1604:in `fu_each_src_dest0'
/opt/chef-workstation/embedded/lib/ruby/2.7.0/fileutils.rb:1586:in `fu_each_src_dest'
/opt/chef-workstation/embedded/lib/ruby/2.7.0/fileutils.rb:539:in `mv'
/opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/cookbook-omnifetch-0.9.1/lib/cookbook-omnifetch/metadata_based_installer.rb:68:in `install'
/opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/cookbook-omnifetch-0.9.1/lib/cookbook-omnifetch/chef_server.rb:30:in `install'
/opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/chef-cli-3.0.11/lib/chef-cli/policyfile/cookbook_location_specification.rb:81:in `ensure_cached'
/opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/chef-cli-3.0.11/lib/chef-cli/policyfile_compiler.rb:183:in `block in install'
/opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/chef-cli-3.0.11/lib/chef-cli/policyfile_compiler.rb:178:in `each'
/opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/chef-cli-3.0.11/lib/chef-cli/policyfile_compiler.rb:178:in `install'
/opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/chef-cli-3.0.11/lib/chef-cli/policyfile_services/install.rb:102:in `generate_lock_and_install'
/opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/chef-cli-3.0.11/lib/chef-cli/policyfile_services/install.rb:63:in `run'
/opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/chef-cli-3.0.11/lib/chef-cli/command/install.rb:80:in `run'
/opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/chef-cli-3.0.11/lib/chef-cli/command/base.rb:63:in `run_with_default_options'
/opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/chef-cli-3.0.11/lib/chef-cli/cli.rb:74:in `run'
/opt/chef-workstation/embedded/lib/ruby/gems/2.7.0/gems/chef-cli-3.0.11/bin/chef-cli:25:in `<top (required)>'
/usr/local/bin/chef-cli:360:in `load'
/usr/local/bin/chef-cli:360:in `<main>'

Steps to Reproduce:

  1. Started chef-zero:

    ❯ chef-zero --port 8889 --multi-org

    >> Starting Chef Zero (v15.0.0)...
    >> WEBrick (v1.6.0) on Rack (v2.2.3) is listening at http://127.0.0.1:8889
    >> Press CTRL+C to stop
  2. Used following knife config:

    ❯ cat knife_local.rb
    current_dir = File.dirname(__FILE__)
    chef_server_url   "http://127.0.0.1:8889/organizations/testorg"
    client_key        "#{current_dir}/dummy_key.pem"
    cookbook_path     [ "#{current_dir}/../../chef/cookbooks" ]
  3. Created org: ❯ knife opc org create testorg Test Org -c /tmp/knife_local.rb

  4. Uploaded cookbook: ❯ knife cookbook upload runstatus_handler -c /tmp/knife_local.rb

  5. Used following policyFile: ❯ cat testpolicy.rb

    # A name that describes what the system you're building with Chef does.
    name 'testpolicy'
    # Where to find external cookbooks:
    default_source :chef_server, "http://127.0.0.1:8889/organizations/testorg"
    # run_list: chef-client will run these recipes in the order specified.
    run_list 'recipe[runstatus_handler]'
    # Specify a custom source for a single cookbook:
    cookbook 'runstatus_handler', '= 1.0.1'
  6. Run ❯ chef install testpolicy.rb -c knife_local.rb

    Expected Result:

Possible Fix: