summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/knife/core/status_presenter.rb22
-rw-r--r--lib/chef/knife/status.rb13
-rw-r--r--spec/unit/knife/status_spec.rb27
3 files changed, 42 insertions, 20 deletions
diff --git a/lib/chef/knife/core/status_presenter.rb b/lib/chef/knife/core/status_presenter.rb
index 3298d5e4ac..a6cb7448db 100644
--- a/lib/chef/knife/core/status_presenter.rb
+++ b/lib/chef/knife/core/status_presenter.rb
@@ -66,16 +66,16 @@ class Chef
list.each do |node|
result = {}
- result["name"] = node.name
- result["chef_environment"] = node.chef_environment
- ip = (node[:ec2] && node[:ec2][:public_ipv4]) || node[:ipaddress]
- fqdn = (node[:ec2] && node[:ec2][:public_hostname]) || node[:fqdn]
+ result["name"] = node["name"]
+ result["chef_environment"] = node["chef_environment"]
+ ip = (node["ec2"] && node["ec2"]["public_ipv4"]) || node["ipaddress"]
+ fqdn = (node["ec2"] && node["ec2"]["public_hostname"]) || node["fqdn"]
result["ip"] = ip if ip
result["fqdn"] = fqdn if fqdn
- result["run_list"] = node.run_list if config[:run_list]
- result["ohai_time"] = node[:ohai_time]
- result["platform"] = node[:platform] if node[:platform]
- result["platform_version"] = node[:platform_version] if node[:platform_version]
+ result["run_list"] = node.run_list if config["run_list"]
+ result["ohai_time"] = node["ohai_time"]
+ result["platform"] = node["platform"] if node["platform"]
+ result["platform_version"] = node["platform_version"] if node["platform_version"]
if config[:long_output]
result["default"] = node.default_attrs
@@ -100,10 +100,10 @@ class Chef
ip = (node[:ec2] && node[:ec2][:public_ipv4]) || node[:ipaddress]
fqdn = (node[:ec2] && node[:ec2][:public_hostname]) || node[:fqdn]
- hours, minutes, seconds = time_difference_in_hms(node["ohai_time"])
+ hours, minutes, _ = time_difference_in_hms(node["ohai_time"])
hours_text = "#{hours} hour#{hours == 1 ? ' ' : 's'}"
minutes_text = "#{minutes} minute#{minutes == 1 ? ' ' : 's'}"
- run_list = "#{node.run_list}" if config[:run_list]
+ run_list = "#{node['run_list']}" if config[:run_list]
if hours > 24
color = :red
text = hours_text
@@ -116,7 +116,7 @@ class Chef
end
line_parts = Array.new
- line_parts << @ui.color(text, color) + ' ago' << node.name
+ line_parts << @ui.color(text, color) + ' ago' << node['name']
line_parts << fqdn if fqdn
line_parts << ip if ip
line_parts << run_list if run_list
diff --git a/lib/chef/knife/status.rb b/lib/chef/knife/status.rb
index be48b87368..35868b376f 100644
--- a/lib/chef/knife/status.rb
+++ b/lib/chef/knife/status.rb
@@ -22,6 +22,7 @@ require 'chef/knife/core/status_presenter'
class Chef
class Knife
class Status < Knife
+ include Knife::Core::NodeFormattingOptions
deps do
require 'chef/search/query'
@@ -52,6 +53,15 @@ class Chef
def run
ui.use_presenter Knife::Core::StatusPresenter
+ if config[:long_output]
+ opts = {}
+ else
+ opts = {filter_result:
+ { name: ["name"], ipaddress: ["ipaddress"], ohai_time: ["ohai_time"],
+ ec2: ["ec2"], run_list: ["run_list"], platform: ["platform"],
+ platform_version: ["platform_version"], chef_environment: ["chef_environment"]}}
+ end
+
@query ||= ""
append_to_query(@name_args[0]) if @name_args[0]
append_to_query("chef_environment:#{config[:environment]}") if config[:environment]
@@ -67,7 +77,8 @@ class Chef
all_nodes = []
q = Chef::Search::Query.new
- q.search(:node, @query) do |node|
+ Chef::Log.info("Sending query: #{@query}")
+ q.search(:node, @query, opts) do |node|
all_nodes << node
end
diff --git a/spec/unit/knife/status_spec.rb b/spec/unit/knife/status_spec.rb
index 45c7c9334e..f4731bbc2a 100644
--- a/spec/unit/knife/status_spec.rb
+++ b/spec/unit/knife/status_spec.rb
@@ -34,27 +34,38 @@ describe Chef::Knife::Status do
end
describe "run" do
+ let(:opts) {{filter_result:
+ { name: ["name"], ipaddress: ["ipaddress"], ohai_time: ["ohai_time"],
+ ec2: ["ec2"], run_list: ["run_list"], platform: ["platform"],
+ platform_version: ["platform_version"], chef_environment: ["chef_environment"]}}}
+
it "should default to searching for everything" do
- expect(@query).to receive(:search).with(:node, "*:*")
+ expect(@query).to receive(:search).with(:node, "*:*", opts)
@knife.run
end
it "should filter healthy nodes" do
@knife.config[:hide_healthy] = true
- expect(@query).to receive(:search).with(:node, "NOT ohai_time:[119856 TO 123456]")
+ expect(@query).to receive(:search).with(:node, "NOT ohai_time:[119856 TO 123456]", opts)
@knife.run
end
it "should filter by environment" do
@knife.config[:environment] = "production"
- expect(@query).to receive(:search).with(:node, "chef_environment:production")
+ expect(@query).to receive(:search).with(:node, "chef_environment:production", opts)
@knife.run
end
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 NOT ohai_time:[119856 TO 123456]")
+ expect(@query).to receive(:search).with(:node, "chef_environment:production NOT ohai_time:[119856 TO 123456]", opts)
+ @knife.run
+ end
+
+ it "should not use partial search with long output" do
+ @knife.config[:long_output] = true
+ expect(@query).to receive(:search).with(:node, "*:*", {})
@knife.run
end
@@ -64,26 +75,26 @@ describe Chef::Knife::Status do
end
it "should allow a custom query to be specified" do
- expect(@query).to receive(:search).with(:node, "name:my_custom_name")
+ expect(@query).to receive(:search).with(:node, "name:my_custom_name", opts)
@knife.run
end
it "should filter healthy nodes" do
@knife.config[:hide_healthy] = true
- expect(@query).to receive(:search).with(:node, "name:my_custom_name NOT ohai_time:[119856 TO 123456]")
+ expect(@query).to receive(:search).with(:node, "name:my_custom_name NOT ohai_time:[119856 TO 123456]", opts)
@knife.run
end
it "should filter by environment" do
@knife.config[:environment] = "production"
- expect(@query).to receive(:search).with(:node, "name:my_custom_name AND chef_environment:production")
+ expect(@query).to receive(:search).with(:node, "name:my_custom_name AND chef_environment:production", opts)
@knife.run
end
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 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]", opts)
@knife.run
end
end