summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2015-03-16 11:09:52 +0000
committerThom May <thom@may.lt>2015-03-16 11:09:52 +0000
commita0872d16eda17b7fb144513425a2a4af2bc8c369 (patch)
tree968b87c94a7d648b605203bb2dc5adfcb41bd07f
parent0d7f6a64abef06e94273dbcefd8adc53ab071f11 (diff)
downloadchef-a0872d16eda17b7fb144513425a2a4af2bc8c369.tar.gz
Ensure valid lucene queries
-rw-r--r--lib/chef/knife/status.rb6
-rw-r--r--spec/unit/knife/status_spec.rb6
2 files changed, 7 insertions, 5 deletions
diff --git a/lib/chef/knife/status.rb b/lib/chef/knife/status.rb
index 93e596a7db..be48b87368 100644
--- a/lib/chef/knife/status.rb
+++ b/lib/chef/knife/status.rb
@@ -52,13 +52,15 @@ class Chef
def run
ui.use_presenter Knife::Core::StatusPresenter
- @query = ""
+ @query ||= ""
append_to_query(@name_args[0]) if @name_args[0]
append_to_query("chef_environment:#{config[:environment]}") if config[:environment]
if config[:hide_healthy]
time = Time.now.to_i
- append_to_query("NOT ohai_time:[#{(time - 60*60).to_s} TO #{time.to_s}]")
+ # AND NOT is not valid lucene syntax, so don't use append_to_query
+ @query << " " unless @query.empty?
+ @query << "NOT ohai_time:[#{(time - 60*60).to_s} TO #{time.to_s}]"
end
@query = @query.empty? ? "*:*" : @query
diff --git a/spec/unit/knife/status_spec.rb b/spec/unit/knife/status_spec.rb
index 0a638530d7..45c7c9334e 100644
--- a/spec/unit/knife/status_spec.rb
+++ b/spec/unit/knife/status_spec.rb
@@ -54,7 +54,7 @@ describe Chef::Knife::Status do
it "should filter by environment and health" do
@knife.config[:environment] = "production"
@knife.config[:hide_healthy] = true
- expect(@query).to receive(:search).with(:node, "chef_environment:production AND NOT ohai_time:[119856 TO 123456]")
+ expect(@query).to receive(:search).with(:node, "chef_environment:production NOT ohai_time:[119856 TO 123456]")
@knife.run
end
@@ -70,7 +70,7 @@ describe Chef::Knife::Status do
it "should filter healthy nodes" do
@knife.config[:hide_healthy] = true
- expect(@query).to receive(:search).with(:node, "name:my_custom_name AND NOT ohai_time:[119856 TO 123456]")
+ expect(@query).to receive(:search).with(:node, "name:my_custom_name NOT ohai_time:[119856 TO 123456]")
@knife.run
end
@@ -83,7 +83,7 @@ describe Chef::Knife::Status do
it "should filter by environment and health" do
@knife.config[:environment] = "production"
@knife.config[:hide_healthy] = true
- expect(@query).to receive(:search).with(:node, "name:my_custom_name AND chef_environment:production AND NOT ohai_time:[119856 TO 123456]")
+ expect(@query).to receive(:search).with(:node, "name:my_custom_name AND chef_environment:production NOT ohai_time:[119856 TO 123456]")
@knife.run
end
end