Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chefspec not working with policyfiles on chef server #934

Open
keefbaker opened this issue Oct 9, 2018 · 3 comments · Fixed by chef/chef-cli#208
Open

Chefspec not working with policyfiles on chef server #934

keefbaker opened this issue Oct 9, 2018 · 3 comments · Fixed by chef/chef-cli#208

Comments

@keefbaker
Copy link

This has been tested on three developer machines running:

  • Windows 10
  • Ubuntu 16.04

When having dependent cookbooks in the policyfile and importing the chefspec/policyfile gem the rspec tests fail with:

An error occurred in a before(:suite) hook.                                                                                                                                                    
Failure/Error: raise PolicyfileInstallError.new("Failed to install cookbooks from lockfile", error)                                                                                              
                                                                                                                                                                                                 
ChefDK::PolicyfileInstallError:                                                                                                                                                                  
  Failed to install cookbooks from lockfile                                                                                                                                                      
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-dk-3.3.23/lib/chef-dk/policyfile_services/install.rb:158:in `rescue in install_from_lock'                                             
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-dk-3.3.23/lib/chef-dk/policyfile_services/install.rb:153:in `install_from_lock'                                                       
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chef-dk-3.3.23/lib/chef-dk/policyfile_services/install.rb:61:in `run'                                                                      
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chefspec-7.3.2/lib/chefspec/policyfile.rb:32:in `setup!'                                                                                   
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/chefspec-7.3.2/lib/chefspec/policyfile.rb:60:in `block (2 levels) in <top (required)>'                                                     
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/example.rb:447:in `instance_exec'                                                                          
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/example.rb:447:in `instance_exec'                                                                          
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/hooks.rb:350:in `run'                                                                                      
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration.rb:1981:in `block in run_suite_hooks'                                                        
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration.rb:1979:in `each'                                                                            
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration.rb:1979:in `run_suite_hooks'                                                                 
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/configuration.rb:1925:in `with_suite_hooks'                                                                
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:113:in `block in run_specs'                                                                      
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/reporter.rb:79:in `report'                                                                                 
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:112:in `run_specs'                                                                               
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:87:in `run'                                                                                      
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:71:in `run'                                                                                      
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/rspec-core-3.7.1/lib/rspec/core/runner.rb:45:in `invoke'                                                                                   
# C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/rspec-core-3.7.1/exe/rspec:4:in `<top (required)>'                                                                                         
# C:/opscode/chefdk/embedded/bin/rspec:23:in `load'                                                                                                                                              
# C:/opscode/chefdk/embedded/bin/rspec:23:in `<main>'                                                                                                                                            
#                                                                                                                                                                                                
#   Showing full backtrace because every line was filtered out.                                                                                                                                  
#   See docs for RSpec::Configuration#backtrace_exclusion_patterns and                                                                                                                           
#   RSpec::Configuration#backtrace_inclusion_patterns for more information.                                                                                                                      
# ------------------                                                                                                                                                                             
# --- Caused by: ---                                                                                                                                                                             
# CookbookOmnifetch::MissingConfiguration:                                                                                                                                                       
#   `default_chef_server_http_client` is not configured                                                                                                                                          
#   C:/opscode/chefdk/embedded/lib/ruby/gems/2.5.0/gems/cookbook-omnifetch-0.8.0/lib/cookbook-omnifetch/integration.rb:24:in `block in configurable'                                             
                                                                                                                                                                                                 
                                                                                                                                                                                                 
Finished in 0.12373 seconds (files took 8.02 seconds to load)                                                                                                                                    
0 examples, 0 failures, 1 error occurred outside of examples

The following commands work no problem chef install, chef update and kitchen tests run with no problem.

I have tried numerous cookbooks, and even a different version of chefdk (it was 3.1.0 and I upgraded to 3.3.23) but the results are the same:

spec_helper.rb

# frozen_string_literal: true
require 'chefspec'
require 'chefspec/policyfile'

Policyfile (anonymized)

# Policyfile.rb - Describe how you want Chef to build your system.
#
# For more information on the Policyfile feature, visit
# https://docs.chef.io/policyfile.html

name 'basic_mongo'
default_source :chef_server, 'https://chef-server.something.net/organizations/myorg'

run_list 'basic_utilities::yumrepo', 'basic_utilities::default', 'basic_mongo::default'

cookbook 'basic_mongo', path: '.'
cookbook 'basic_utilities'

First reported in the chef community slack and was advised to raise a bug report.

@robbkidd
Copy link

🤔 I suspect chefspec/policyfile will need to have something to allow optionally injecting a chef_config to the ChefDK::PolicyfileServices::Install instance.

@klas-s
Copy link

klas-s commented Dec 3, 2018

I work around the issue with the following in my spec_helper.rb.

CookbookOmnifetch.configure do |config|
  chef_server_url = 'https://your-chef-server/organizations/your-org'
  config.default_chef_server_http_client = ChefDK::ChefServerAPIMulti.new(chef_server_url, {})
end

@tyler-ball
Copy link
Contributor

Update for Chef Workstation users: the workaround that @klas-s mentioned needs to be updated to:

CookbookOmnifetch.configure do |config|
  chef_server_url = 'https://your-chef-server/organizations/your-org'
  config.default_chef_server_http_client = ChefCLI::ChefServerAPIMulti.new(chef_server_url, {})
end

We moved the location of the ChefServerAPIMulti class in Chef Workstation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants