summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChibuikem Amaechi <cramaechi@me.com>2018-01-15 23:16:24 -0600
committerChibuikem Amaechi <cramaechi@me.com>2018-01-23 02:39:10 -0600
commit4919b83e8dd397f159e33d11756138f2e044cd38 (patch)
treeb26df8071b9f9e504aca8bf22018817e0d77df19
parentbc98db2fd24d75443d048a83ae1844eec7499507 (diff)
downloadchef-4919b83e8dd397f159e33d11756138f2e044cd38.tar.gz
Update error handling for "knife status" #3287
If a node object's ohai_time value is "nil" then the calculated time-since-last-run value is incorrect because the "nil" gets converted to integer "0". "knife status" should signal an error when a node's ohai_time value is nil. Signed-off-by: Chibuikem Amaechi <cramaechi@me.com>
-rw-r--r--lib/chef/knife/core/status_presenter.rb5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/chef/knife/core/status_presenter.rb b/lib/chef/knife/core/status_presenter.rb
index bb6766c6ac..899da21003 100644
--- a/lib/chef/knife/core/status_presenter.rb
+++ b/lib/chef/knife/core/status_presenter.rb
@@ -101,6 +101,11 @@ class Chef
fqdn = (node[:ec2] && node[:ec2][:public_hostname]) || node[:fqdn]
name = node["name"] || node.name
+ if !node["ohai_time"]
+ ui.error("Ohai has not yet ran on node #{name}.")
+ exit(1)
+ end
+
hours, minutes, seconds = time_difference_in_hms(node["ohai_time"])
hours_text = "#{hours} hour#{hours == 1 ? ' ' : 's'}"
minutes_text = "#{minutes} minute#{minutes == 1 ? ' ' : 's'}"