aws / opsworks-cookbooks

Chef Cookbooks for the AWS OpsWorks Service
Other
1.06k stars 1.23k forks source link

rubygems monkey patch breaks chef_gem when not run with bundler #267

Open bbergstrom opened 9 years ago

bbergstrom commented 9 years ago

Test kitchen executes Chef without bundler. Your cookbooks should be compatible with the popular testing framework and support bunder and non-bundler execution.

 * chef_gem[httparty] action install       [2015-01-05T19:46:29+00:00] INFO: Processing chef_gem[httparty] action install (newrelic_policy_manager::httparty line 1)

================================================================================       
Error executing action `install` on resource 'chef_gem[httparty]'       
       ================================================================================

NameError       
---------       
       uninitialized constant Chef::Provider::Package::Rubygems::OpsWorksInternalGems::Bundler

       Cookbook Trace:
       ---------------
       /tmp/kitchen/cookbooks/opsworks_commons/libraries/monkey_patch_rubygems_provider.rb:151:in `internal_gem_home'
       /tmp/kitchen/cookbooks/opsworks_commons/libraries/monkey_patch_rubygems_provider.rb:165:in `internal_gem_installed?'
       /tmp/kitchen/cookbooks/opsworks_commons/libraries/monkey_patch_rubygems_provider.rb:113:in `install_internal_gem'
       /tmp/kitchen/cookbooks/opsworks_commons/libraries/monkey_patch_rubygems_provider.rb:81:in `install'
       ...

       Resource Declaration:
       ---------------------
       # In /tmp/kitchen/cookbooks/newrelic_policy_manager/recipes/httparty.rb

         1: chef_gem 'httparty' do
         2:   version '0.11.0'
         3:   action :install
         4: end
         5: require 'httparty'

       Compiled Resource:
       ------------------
       # Declared in /tmp/kitchen/cookbooks/newrelic_policy_manager/recipes/httparty.rb:1:in `from_file'

       chef_gem("httparty") do
         provider Chef::Provider::Package::Rubygems
         action [:install]
         retries 0
         retry_delay 2
         options {:opts=>"--no-ri --no-rdoc", :sources=>nil}
         package_name "httparty"
         version "0.11.0"
         cookbook_name :newrelic_policy_manager
         recipe_name "httparty"
       end
jcderose commented 9 years ago

I'm having the same problem.

https://github.com/opscode-cookbooks/aws/issues/166

I'm writing a recipe that includes the aws default recipe, and then uses the aws_ebs_volume resource. At runtime, I get the following error:

uninitialized constant Chef::Provider::Package::Rubygems::CurrentGemEnvironment::Bundler https://gist.github.com/jcderose/0f589b36aad50c05d737

Here's my recipe:

include_recipe "opsworks_initial_setup"
include_recipe 'aws'

instance_az = node[:opsworks][:instance][:availability_zone]
device_id = "/dev/xvdx"

directory '/srv-enc' do
  mode '0755'
end

  aws_ebs_volume 'EncryptedVolume' do
    size 8
    device device_id
    availability_zone instance_az
    volume_type "gp2"
    encrypted true
    action [:create, :attach]
  end

Here's my metadata.rb:

name             'setup-ebs-encryption'
maintainer       'XXXX'
maintainer_email 'XXXX'
license          'All rights reserved'
description      'Installs/Configures setup-ebs-encryption'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version          '0.1.0'

depends 'opsworks_initial_setup'
depends 'aws'

Here's my Berksfile: https://gist.github.com/jcderose/1f054f7714571c25d7b1

jcderose commented 9 years ago

FYI @bbergstrom, I reached out to AWS support regarding this issue and received this response:

"Thanks for reaching out. Generally speaking, the OpsWorks team has informed me that OpsWorks doesn't officially support Test Kitchen for our built-in cookbooks, since there's some setup that happens before Chef is run. Because of this, I don't believe you will be able to get past the error without actually manually editing the opsworks_commons cookbook, the way that the cookbook is composed and how OpsWorks does initial setup prior to the built-in cookbooks running."