[chef] Re: Chefspec and accessing a node attribute within EncryptedDataBagItem.load


Chronological Thread 
  • From: Pete Cheslock < >
  • To:
  • Subject: [chef] Re: Chefspec and accessing a node attribute within EncryptedDataBagItem.load
  • Date: Fri, 7 Feb 2014 12:56:54 -0500

What I think you want to do is to stub out your databag in the before block so that chefspec can execute your tests on that data.

Here is an example of what I've done. 

More info:


On Fri, Feb 7, 2014 at 12:19 PM, Bryan Bishop < " target="_blank"> > wrote:
Hello great chefs!

I'm running into trouble using ChefSpec 3.2.0 and converging a
ChefSpec runner with an encrypted data bag.  The data bag I'm trying
to load is referenced by a node attribute, like this:


    mysql_passwords =
Chef::EncryptedDataBagItem.load(node['percona']['encrypted_data_bag'],
"mysql")


So in my ChefSpec runner, I've set that node attribute:

    let(:chef_run) do
      ChefSpec::Runner.new do |node|
        node.override["percona"]["encrypted_data_bag"] = 'something'
      end.converge(described_recipe)
    end

But converging the ChefSpec running seems to choke on this.  Are these
attributes not being assigned in the Runner object?  I've placed a
puts statement in my recipe code and the tests print out the correct
bogus attribute I defined, "something."

  4>> mysql_passwords =
Chef::EncryptedDataBagItem.load(node['percona']['encrypted_data_bag'],
"mysql")

Failures:

  1) prsn_epen2::_deploy_common does something
     Failure/Error: end.converge(described_recipe)
     TypeError:
       no implicit conversion of Array into String


I'm sure this is something obvious, can anyone help me please?  I
really appreciate the discussions on this list!



- Bryan




Archive powered by MHonArc 2.6.16.

§