Browse Source

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
Krzysztof Szukiełojć 3 years ago
parent
commit
28dc110ea5
1 changed files with 10 additions and 10 deletions
  1. 10
    10
      agent

+ 10
- 10
agent View File

@@ -902,21 +902,21 @@ class NodeAgent
902 902
   end
903 903
 
904 904
   def _get_pci_dev_list
905
-    lshw_path = `which lshw`.chomp
906
-    exitstatus = $?
907
-    if exitstatus == 0
908
-      data = `#{lshw_path} -json`
909
-      exitstatus = $?
910
-      if exitstatus == 0
911
-        return JSON.parse(data)
905
+    lshw_timeout = @settings['lshw_timeout'] || 60
906
+    Timeout::timeout(lshw_timeout) do
907
+      lshw_path = `which lshw`.chomp
908
+      if $?.success?
909
+        data = `#{lshw_path} -json`
910
+        return JSON.parse(data) if $?.success?
911
+        @logger.warn("Can't get data from lshw. Reason: lshw exited with status #{$?.exitstatus}")
912 912
       else
913
-        @logger.warn("Can't get data from lshw. Reason: lshw exited with status #{exitstatus}")
913
+        @logger.warn("Can't find lshw. Reason: 'which lshw' returned exit status #{$?.exitstatus}")
914 914
       end
915
-    else
916
-      @logger.warn("Can't find lshw. Reason: 'which lshw' returned exit status #{exitstatus}")
917 915
     end
916
+    {}
918 917
   rescue => e
919 918
     @logger.warn("Can't get data from lshw. Reason: #{e.message}")
919
+    {}
920 920
   end
921 921
 
922 922
   def get_numa_topology

Loading…
Cancel
Save