From 8311869e5b99fecefd567ce3f1ad1cbdf8d5c5c6 Mon Sep 17 00:00:00 2001 From: Jay Pipes Date: Fri, 5 Jul 2013 19:02:26 -0400 Subject: [PATCH] Correct faulty Chef search query The search returns a Hash, not a list, so we need to remove the reference to [0] in the memcached_servers library routine call otherwise you get: undefined method `[]' for nil:NilClass in chef-client runs. Change-Id: I479aca833a2eb80fa2baf3e54809b2edaa713b89 --- CHANGELOG.md | 4 ++++ libraries/roles.rb | 2 +- metadata.rb | 2 +- spec/roles_spec.rb | 12 ++++-------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28ae7137..93badbb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ This file is used to list changes made in each version of cookbook-openstack-common. +## 0.3.1: +* Corrected a faulty Chef search query with `#config_by_role`. The search returns a + Hash, not an array. + ## 0.3.0: * Added `#rabbit_servers` method, which returns a comma-delimited string of rabbit servers in the format of host:port. diff --git a/libraries/roles.rb b/libraries/roles.rb index 4f1207bf..3d77a59b 100644 --- a/libraries/roles.rb +++ b/libraries/roles.rb @@ -39,7 +39,7 @@ module ::Openstack log("Searched for role #{role} by found no nodes with that role in run list.") { level :debug } nil else - section.nil? ? result[0] : result[0][section] + section.nil? ? result : result[section] end end end diff --git a/metadata.rb b/metadata.rb index 1891c8b6..ba4f01bf 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ maintainer_email "cookbooks@lists.tfoundry.com" license "Apache 2.0" description "Common OpenStack attributes, libraries and recipes." long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "0.3.0" +version "0.3.1" recipe "openstack-common", "Installs/Configures common recipes" recipe "openstack-common::logging", "Installs/Configures common logging" diff --git a/spec/roles_spec.rb b/spec/roles_spec.rb index 6e9da4c7..6f5334a4 100644 --- a/spec/roles_spec.rb +++ b/spec/roles_spec.rb @@ -39,24 +39,20 @@ describe ::Openstack do end it "returns section when section in first search result" do - nodes = [ - { "foo" => "bar" } - ] + node = { "foo" => "bar" } @subject.stub(:search_for). with("role1"). - and_return nodes + and_return node @subject.stub(:node).and_return @chef_run.node expect(@subject.config_by_role("role1", "foo")).to eq "bar" end it "returns full node hash when search match but no section supplied" do - nodes = [ - { "foo" => "bar" } - ] + node = { "foo" => "bar" } @subject.stub(:search_for). with("role1"). - and_return nodes + and_return node @subject.stub(:node).and_return @chef_run.node expect(@subject.config_by_role("role1")).to eq("foo" => "bar")