Ori.livneh has submitted this change and it was merged.

Change subject: Catch a couple of corner cases in check_puppetrun
......................................................................


Catch a couple of corner cases in check_puppetrun

time_ago that was introduced in 5a3fe15 did not catch a couple of corner
cases. Notably if s was 0 or 1 the entire sorted reversed struct would be
returned and periods like 60 seconds would not be converted to 1 minute
and so on. Fix this by testing for s == 0, change > to >= and provide a
default return value in case of other failures

Change-Id: Iecaafb4ea696fab68a3ad3e7c857626ef2371cff
---
M modules/base/files/monitoring/check_puppetrun
1 file changed, 6 insertions(+), 2 deletions(-)

Approvals:
  Ori.livneh: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/base/files/monitoring/check_puppetrun 
b/modules/base/files/monitoring/check_puppetrun
index b8fd053..c486a44 100755
--- a/modules/base/files/monitoring/check_puppetrun
+++ b/modules/base/files/monitoring/check_puppetrun
@@ -96,9 +96,13 @@
 
 def time_ago(s)
   units = {86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second'}
-  units.sort.reverse.each do |len, unit|
-    return "#{s / len} #{unit}#{'s' if s / len > 1}" if s > len
+  if s == 0
+    return "0 seconds"
   end
+  units.sort.reverse.each do |len, unit|
+    return "#{s / len} #{unit}#{'s' if s / len > 1}" if s >= len
+  end
+  "Indeterminate amount of time (see time_ago)"
 end
 
 time_since_last_run = Time.now.to_i - lastrun

-- 
To view, visit https://gerrit.wikimedia.org/r/170310
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iecaafb4ea696fab68a3ad3e7c857626ef2371cff
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Alexandros Kosiaris <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to