Browse Source

Fix volatile CPU 'size'

The 'size' parameter for CPU returned by lshw is current CPU clock
which changes constantly breaking nailgun optimization which expects
hw data to not change each time.
This also must reduce probability of deadlocks in #1624230.

Change-Id: I7d9b5282991b17424d458c2612dfa4eeeb52be48
Partial-Bug: #1624230
georgy 2 years ago
parent
commit
5e7127f9ec
1 changed files with 18 additions and 1 deletions
  1. 18
    1
      agent

+ 18
- 1
agent View File

@@ -1235,6 +1235,23 @@ class NodeAgent
1235 1235
     res
1236 1236
   end
1237 1237
 
1238
+  def traverse(item, &block)
1239
+    yield item
1240
+    if item.is_a?(Hash)
1241
+      item.each { |k,v| traverse(v, &block) }
1242
+    elsif item.is_a?(Array)
1243
+      item.each { |elem| traverse(elem, &block) }
1244
+    end
1245
+  end
1246
+ 
1247
+  #todo: move all quirks here
1248
+  def fixup(data)
1249
+    traverse(data) do |item|
1250
+      # size for CPU means current clock frequency which constantly changes
1251
+      item.delete(:size) if item.is_a?(Hash) and item.fetch(:class, nil) == 'processor'
1252
+    end
1253
+  end
1254
+
1238 1255
   def _get_pci_dev_list
1239 1256
     return {} if `cat /etc/nailgun_systemtype`.chomp != 'bootstrap'
1240 1257
     lshw_timeout = @settings['lshw_timeout'] || 60
@@ -1242,7 +1259,7 @@ class NodeAgent
1242 1259
       lshw_path = `which lshw`.chomp
1243 1260
       if $?.success?
1244 1261
         data = `#{lshw_path} -json -sanitize`
1245
-        return JSON.parse(data) if $?.success?
1262
+        return fixup(JSON.parse(data)) if $?.success?
1246 1263
         @logger.warn("Can't get data from lshw. Reason: lshw exited with status #{$?.exitstatus}")
1247 1264
       else
1248 1265
         @logger.warn("Can't find lshw. Reason: 'which lshw' returned exit status #{$?.exitstatus}")

Loading…
Cancel
Save