[chef]


Chronological Thread 
  • From: Joseph Hammerman < >
  • To: " " < >
  • Subject: [chef]
  • Date: Mon, 10 Nov 2014 12:19:42 -0800

Hi chef-users email list,

I am resending this as Charles Johnson indicated that my rpevious communication was formatted as a winmail.dat attachment by our Exchange Server (Thank you Charles).

I am trying to implement unit testing for a cookbook wrapper to HAProxy that I put together. I’m trying to define an environment and stubbed node within that environment, in order to test the search and template rendering functionality of my cookbook.

If I include chefspec/server in my spec_helper file, and attempt to create the node and set the running nodes environment to ‘staging’, a la:

  context 'with env, role and one node' do
    let(:node_env) { 'staging' }
    let(:chef_run) do
      ChefSpec::Runner.new(platform: platform, version: platform_version) do |node|
        # Create a new environment (you could also use a different :let block or :before block)
        env = Chef::Environment.new
        env.name node_env

        # Stub the node to return this environment
        node.stub(:chef_environment).and_return(env.name)

        # Stub any calls to Environment.load to return this environment
        Chef::Environment.stub(:load).and_return(env)
      end.converge(described_recipe)
    end

    before do
      ChefSpec::Server.create_environment(node_env, { description: 'Staging env' })
      ChefSpec::Server.create_role('smp', { default_attributes: {} })
      ChefSpec::Server.create_node('smp1.stg.prv', {
        run_list: ['role[smp]'],
        chef_environment: node_env,
        normal: { fqdn: '127.0.0.1', hostname: 'smp1.stg.prv', ipaddress: '127.0.0.1' }
      })
    end

    it 'Renders a template in staging with staging values' do
      expect(chef_run).to render_file('/etc/haproxy/haproxy.cfg').with_content(/smp1.stg.prv/)
    end
  end

All of my test report:

Net::HTTPServerException:
       404 "Not Found “

From what I can tell via Google, the Chef gem version, Chef Zero gem version and chef spec gem version are all somewhat temperamental. Do the Chef-DK Chef Zero and Chef-DK ChefSpec not play nice? Should I create a Bundler file with “proper” Gem version and bundle install it? Does the old chef_solo syntax work, and if so, can anyone point me to a web resource that uses only chef_solo syntax?

Really, any help anyone can provide would be greatly appreciated on my part.

Thanks all.
Joseph Hammerman



  • [chef], indra, 11/05/2014
    • <Possible follow-up(s)>
    • [chef], Joseph Hammerman, 11/10/2014

Archive powered by MHonArc 2.6.16.

§