From eb5eed7126b6a6efbaf803e8a594d610cf661e97 Mon Sep 17 00:00:00 2001 From: John Dewey Date: Tue, 6 Aug 2013 17:49:24 -0700 Subject: [PATCH] Corrected `search_for` recipe and role queries Each query needed surrounding by parens, otherwise returned an empty result. Bug: 1209037 Change-Id: I1a7de0aba30c757e244375abf4e307a36a1bff71 --- CHANGELOG.md | 3 +++ libraries/search.rb | 4 ++-- metadata.rb | 2 +- spec/search_spec.rb | 6 +++--- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 861338ad..ee9e5994 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ This file is used to list changes made in each version of cookbook-openstack-common. +## 0.4.3: +* Corrected `#search_for` role and recipe queries. + ## 0.4.2: * Remove hardcoded localhost for mysql host specification. diff --git a/libraries/search.rb b/libraries/search.rb index f3ac5e02..8e97c6e2 100644 --- a/libraries/search.rb +++ b/libraries/search.rb @@ -23,8 +23,8 @@ module ::Openstack # @param [String] The role or recipe to be found. # @return [Array] The matching result or an empty list. def search_for r, &block - role_query = "chef_environment:#{node.chef_environment} AND roles:#{r}" - recipe_query = "chef_environment:#{node.chef_environment} AND recipes:#{r}".sub("::","\\:\\:") + role_query = "(chef_environment:#{node.chef_environment} AND roles:#{r})" + recipe_query = "(chef_environment:#{node.chef_environment} AND recipes:#{r})".sub("::","\\:\\:") query = "#{role_query} OR #{recipe_query}" resp = search(:node, query, &block) diff --git a/metadata.rb b/metadata.rb index 2843916c..e0264866 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.4.2" +version "0.4.3" recipe "openstack-common", "Installs/Configures common recipes" recipe "openstack-common::logging", "Installs/Configures common logging" diff --git a/spec/search_spec.rb b/spec/search_spec.rb index f3853b09..c52da1e7 100644 --- a/spec/search_spec.rb +++ b/spec/search_spec.rb @@ -17,7 +17,7 @@ describe ::Openstack do it "returns results" do @subject.stub(:node).and_return @chef_run.node @subject.stub(:search). - with(:node, "chef_environment:_default AND roles:role OR chef_environment:_default AND recipes:role"). + with(:node, "(chef_environment:_default AND roles:role) OR (chef_environment:_default AND recipes:role)"). and_return [@chef_run.node] resp = @subject.search_for("role") @@ -27,7 +27,7 @@ describe ::Openstack do it "returns empty results" do @subject.stub(:node).and_return @chef_run.node @subject.stub(:search). - with(:node, "chef_environment:_default AND roles:empty-role OR chef_environment:_default AND recipes:empty-role"). + with(:node, "(chef_environment:_default AND roles:empty-role) OR (chef_environment:_default AND recipes:empty-role)"). and_return [] resp = @subject.search_for("empty-role") @@ -37,7 +37,7 @@ describe ::Openstack do it "always returns empty results" do @subject.stub(:node).and_return @chef_run.node @subject.stub(:search). - with(:node, "chef_environment:_default AND roles:empty-role OR chef_environment:_default AND recipes:empty-role"). + with(:node, "(chef_environment:_default AND roles:empty-role) OR (chef_environment:_default AND recipes:empty-role)"). and_return nil resp = @subject.search_for("empty-role")