From 28dc110ea552c1bcbbd0160c29e1438962cd13f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Szukie=C5=82oj=C4=87?= Date: Mon, 21 Mar 2016 12:09:55 +0100 Subject: [PATCH] Setting timeout for calling lshw In some cases lshw may take too long like when we have lot of partitions > 600. We avoid this problem with setting timeout for lshw. Change-Id: I67748bc18023f3f6edce0cc20d4f0486877723b2 Closes-bug: #1559167 --- agent | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/agent b/agent index 5e04c95..21a9491 100755 --- a/agent +++ b/agent @@ -902,21 +902,21 @@ class NodeAgent end def _get_pci_dev_list - lshw_path = `which lshw`.chomp - exitstatus = $? - if exitstatus == 0 - data = `#{lshw_path} -json` - exitstatus = $? - if exitstatus == 0 - return JSON.parse(data) + lshw_timeout = @settings['lshw_timeout'] || 60 + Timeout::timeout(lshw_timeout) do + lshw_path = `which lshw`.chomp + if $?.success? + data = `#{lshw_path} -json` + return JSON.parse(data) if $?.success? + @logger.warn("Can't get data from lshw. Reason: lshw exited with status #{$?.exitstatus}") else - @logger.warn("Can't get data from lshw. Reason: lshw exited with status #{exitstatus}") + @logger.warn("Can't find lshw. Reason: 'which lshw' returned exit status #{$?.exitstatus}") end - else - @logger.warn("Can't find lshw. Reason: 'which lshw' returned exit status #{exitstatus}") end + {} rescue => e @logger.warn("Can't get data from lshw. Reason: #{e.message}") + {} end def get_numa_topology