From 05848db90525dad9420fbec78d6b1d49be70c03a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Czern=C3=BD?= Date: Mon, 31 May 2021 12:59:51 +0200 Subject: [PATCH] M #-: Linting monitor probes (#1259) (cherry picked from commit a47ef89286ee3ee1c09ae1e291f648cc57607bc5) --- .../host/system/machines_models.rb | 44 +++++++++---------- src/im_mad/remotes/lib/numa_common.rb | 2 +- src/im_mad/remotes/node-probes.d/pci.rb | 29 ++++++------ 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/im_mad/remotes/kvm-probes.d/host/system/machines_models.rb b/src/im_mad/remotes/kvm-probes.d/host/system/machines_models.rb index ddedc0593e..e999cc4498 100755 --- a/src/im_mad/remotes/kvm-probes.d/host/system/machines_models.rb +++ b/src/im_mad/remotes/kvm-probes.d/host/system/machines_models.rb @@ -21,11 +21,9 @@ require 'open3' ENV['LANG'] = 'C' ENV['LC_ALL'] = 'C' -GUEST_ARCHS = %w(i686 x86_64) +GUEST_ARCHS = %w[i686 x86_64] begin - - capabilities = "" machines = [] models = [] @@ -36,9 +34,9 @@ begin cap_xml = REXML::Document.new(capabilities) cap_xml = cap_xml.root - GUEST_ARCHS.each { |a| + GUEST_ARCHS.each do |a| a_elem = cap_xml.elements["guest/arch[@name='#{a}']"] - next if !a_elem + next unless a_elem # Evaluate the domain specific machines with higher priority # over the machines listed just inside the architecture. @@ -57,7 +55,9 @@ begin # # /usr/libexec/qemu-kvm # pc-i440fx-rhel7.4.0 - # pc + # + # pc + # # ... # rhel6.2.0 # pc-i440fx-rhel7.3.0 @@ -68,36 +68,35 @@ begin a_machines = [] - ['kvm', 'kqemu', 'qemu', ''].each { |type| + ['kvm', 'kqemu', 'qemu', ''].each do |type| if type.empty? d_elem = a_elem else d_elem = a_elem.elements["domain[@type='#{type}']"] end - if d_elem - d_elem.elements.each('machine') { |m| - a_machines << m.text - } + next unless d_elem - # take only first found domain type - unless a_machines.empty? - machines.concat(a_machines) - break - end + d_elem.elements.each('machine') {|m| a_machines << m.text } + + # take only first found domain type + unless a_machines.empty? + machines.concat(a_machines) + break end - } + end cmd = "virsh -r -c qemu:///system cpu-models #{a}" cpu_models, e, s = Open3.capture3(cmd) break unless s.success? - cpu_models.each_line { |l| + cpu_models.each_line do |l| l.chomp! - next if l.empty? or l =~ /all CPU models are accepted/i; + next if l.empty? || l =~ /all CPU models are accepted/i + models << l - } - } + end + end machines.uniq! models.uniq! @@ -105,6 +104,5 @@ begin puts "KVM_MACHINES=\"#{machines.join(' ')}\"" puts "KVM_CPU_MODELS=\"#{models.join(' ')}\"" puts "KVM_CPU_MODEL=\"#{cap_xml.elements['host/cpu/model'].text}\"" - -rescue +rescue StandardError end diff --git a/src/im_mad/remotes/lib/numa_common.rb b/src/im_mad/remotes/lib/numa_common.rb index 8de898c834..99fa556afd 100644 --- a/src/im_mad/remotes/lib/numa_common.rb +++ b/src/im_mad/remotes/lib/numa_common.rb @@ -134,7 +134,7 @@ module NUMA distance_h = {} distance_a.each_with_index {|d, i| distance_h[d.to_i] = i } - distance_h = Hash[distance_h.sort] + distance_h = distance_h.sort.to_h closer = '' distance_h.each {|_, v| closer << v.to_s << ' ' } diff --git a/src/im_mad/remotes/node-probes.d/pci.rb b/src/im_mad/remotes/node-probes.d/pci.rb index dad17f0ade..983759578a 100755 --- a/src/im_mad/remotes/node-probes.d/pci.rb +++ b/src/im_mad/remotes/node-probes.d/pci.rb @@ -38,14 +38,14 @@ def get_pci(filter = nil) command = 'lspci -mmnn' command << " -d #{filter}" if filter - text = %x(#{command}) + text = `#{command}` text.split("\n").map {|l| Shellwords.split(l) } end def get_name_and_id(text) m = text.match(/^(.*) \[(....)\]$/) - return m[1], m[2] + [m[1], m[2]] end def parse_pci(pci) @@ -57,8 +57,9 @@ def parse_pci(pci) card[:address] = "0000:#{card[:short_address].gsub(/[:.]/, ':')}" begin - numa_node = File.read("/sys/bus/pci/devices/0000:#{pci[0]}/numa_node").chomp - rescue + numa_node = + File.read("/sys/bus/pci/devices/0000:#{pci[0]}/numa_node").chomp + rescue StandardError numa_node = '-' end @@ -77,9 +78,9 @@ def parse_pci(pci) card end -def get_devices(filter=nil) +def get_devices(filter = nil) if filter - filter = [filter].flatten.map { |f| f.split(',') }.flatten + filter = [filter].flatten.map {|f| f.split(',') }.flatten else filter = [nil] end @@ -94,21 +95,22 @@ filter = CONF[:filter] devices = get_devices(filter) def pval(name, value) - %Q( #{name} = "#{value}") + %( #{name} = "#{value}" ) end devices.each do |dev| - next if !CONF[:short_address].empty? && !CONF[:short_address].include?(dev[:short_address]) + next if !CONF[:short_address].empty? && + !CONF[:short_address].include?(dev[:short_address]) if !CONF[:device_name].empty? - matched = CONF[:device_name].each { |pattern| - break true if !(dev[:device_name] =~ /#{pattern}/i).nil? - } + matched = CONF[:device_name].each do |pattern| + break true unless (dev[:device_name] =~ /#{pattern}/i).nil? + end next if matched != true end - puts "PCI = [" + puts 'PCI = [' values = [ pval('TYPE', dev[:type]), pval('VENDOR', dev[:vendor]), @@ -127,6 +129,5 @@ devices.each do |dev| ] puts values.join(",\n") - puts "]" + puts ']' end -