]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/hardware/recipes/default.rb
Fix issues reported by new rubocop
[chef.git] / cookbooks / hardware / recipes / default.rb
index 2f8a4398e8d2805910b0eda719741a259d691244..8342a9ac3f78921c59055d5ddd53e2f4a62425c7 100644 (file)
@@ -297,10 +297,18 @@ end
   end
 end
 
-disks = node[:hardware][:disk][:disks].map do |disk|
+disks = if node[:hardware][:disk]
+          node[:hardware][:disk][:disks]
+        else
+          []
+        end
+
+disks = disks.map do |disk|
+  next if disk[:state] == "spun_down"
+
   if disk[:smart_device]
     controller = node[:hardware][:disk][:controllers][disk[:controller]]
-    device = File.basename(controller[:device])
+    device = controller[:device].sub("/dev/", "")
     smart = disk[:smart_device]
 
     if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
@@ -311,11 +319,13 @@ disks = node[:hardware][:disk][:disks].map do |disk|
     elsif smart =~ %r{^.*,(\d+)/(\d+)$}
       munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
     end
-  else
-    device = File.basename(disk[:device])
+  elsif disk[:device]
+    device = disk[:device].sub("/dev/", "")
     munin = device
   end
 
+  next if device.nil?
+
   Hash[
     :device => device,
     :smart => smart,
@@ -324,6 +334,8 @@ disks = node[:hardware][:disk][:disks].map do |disk|
   ]
 end
 
+disks = disks.compact
+
 if disks.count > 0
   package "smartmontools"
 
@@ -431,7 +443,11 @@ if node[:lsb][:release].to_f <= 12.10
   end
 else
   service "kmod" do
-    provider Chef::Provider::Service::Upstart
+    if node[:lsb][:release].to_f >= 15.10
+      provider Chef::Provider::Service::Systemd
+    else
+      provider Chef::Provider::Service::Upstart
+    end
     action :nothing
     subscribes :start, "template[/etc/modules]"
   end
@@ -460,15 +476,15 @@ unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
     cpu = File.basename(coretemp).sub("coretemp.", "").to_i
     chip = format("coretemp-isa-%04d", cpu)
 
-    if File.exist?("#{coretemp}/name")
-      temps = Dir.glob("#{coretemp}/temp*_input").map do |temp|
-        File.basename(temp).sub("temp", "").sub("_input", "").to_i
-      end.sort
-    else
-      temps = Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
-        File.basename(temp).sub("temp", "").sub("_input", "").to_i
-      end.sort
-    end
+    temps = if File.exist?("#{coretemp}/name")
+              Dir.glob("#{coretemp}/temp*_input").map do |temp|
+                File.basename(temp).sub("temp", "").sub("_input", "").to_i
+              end.sort
+            else
+              Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
+                File.basename(temp).sub("temp", "").sub("_input", "").to_i
+              end.sort
+            end
 
     if temps.first == 1
       node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"