Rubocop cleanups
authorTom Hughes <tom@compton.nu>
Thu, 5 Feb 2015 22:52:55 +0000 (22:52 +0000)
committerTom Hughes <tom@compton.nu>
Fri, 6 Feb 2015 08:28:14 +0000 (08:28 +0000)
18 files changed:
.rubocop_todo.yml
cookbooks/chef/recipes/default.rb
cookbooks/chef/recipes/server.rb
cookbooks/dev/recipes/default.rb
cookbooks/git/recipes/server.rb
cookbooks/hardware/recipes/default.rb
cookbooks/mysql/libraries/mysql.rb
cookbooks/mysql/providers/database.rb
cookbooks/mysql/providers/user.rb
cookbooks/networking/libraries/interfaces.rb
cookbooks/networking/recipes/default.rb
cookbooks/nfs/recipes/server.rb
cookbooks/ntp/recipes/default.rb
cookbooks/osmosis/recipes/default.rb
cookbooks/postgresql/providers/table.rb
cookbooks/postgresql/recipes/default.rb
cookbooks/rsyncd/recipes/default.rb
cookbooks/tile/files/default/ruby/expire.rb

index 4d8a942928a5aec78ad9bd33c2a109744688900d..155b7d1356752efabf9c104fb59dfc60be0e3de4 100644 (file)
@@ -68,11 +68,6 @@ Style/IfUnlessModifier:
 Style/MultilineOperationIndentation:
   Enabled: false
 
-# Offense count: 19
-# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
-Style/Next:
-  Enabled: false
-
 # Offense count: 29
 # Cop supports --auto-correct.
 Style/NumericLiterals:
index a9fa67b58fd1884987b710a8f2cf84829409b7e3..b8e81a3ed35dacf8ca1c9696524042d9fd56e784 100644 (file)
@@ -34,11 +34,11 @@ directory "/var/cache/chef" do
 end
 
 Dir.glob("/var/cache/chef/chef_*.deb").each do |deb|
-  if deb != "/var/cache/chef/#{chef_package}"
-    file deb do
-      action :delete
-      backup false
-    end
+  next if deb == "/var/cache/chef/#{chef_package}"
+
+  file deb do
+    action :delete
+    backup false
   end
 end
 
index f314515c406d695cb16f692e1e0f49dc5b93f504..37c84e78f299c19973031e65614e1f6a4abb282f 100644 (file)
@@ -34,11 +34,11 @@ directory "/var/cache/chef" do
 end
 
 Dir.glob("/var/cache/chef/chef-server_*.deb").each do |deb|
-  if deb != "/var/cache/chef/#{chef_package}"
-    file deb do
-      action :delete
-      backup false
-    end
+  next if deb == "/var/cache/chef/#{chef_package}"
+
+  file deb do
+    action :delete
+    backup false
   end
 end
 
index 75dcefc8bac20530ba49b5eea401b5550132a2b1..039f5b204b164bc5d59a92ad4716e01e83bf362a 100644 (file)
@@ -103,27 +103,28 @@ end
 search(:accounts, "*:*").each do |account|
   name = account["id"]
   details = node[:accounts][:users][name] || {}
-  port = 7000 + account["uid"].to_i
 
-  if %w(user administrator).include?(details[:status])
-    user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
+  next unless %w(user administrator).include?(details[:status])
 
-    if File.directory?("#{user_home}/public_html")
-      template "/etc/php5/fpm/pool.d/#{name}.conf" do
-        source "fpm.conf.erb"
-        owner "root"
-        group "root"
-        mode 0644
-        variables :user => name, :port => port
-        notifies :reload, "service[php5-fpm]"
-      end
+  user_home = details[:home] || account["home"] || "#{node[:accounts][:home]}/#{name}"
 
-      apache_site "#{name}.dev.openstreetmap.org" do
-        template "apache.user.erb"
-        directory "#{user_home}/public_html"
-        variables :user => name, :port => port
-      end
-    end
+  next unless File.directory?("#{user_home}/public_html")
+
+  port = 7000 + account["uid"].to_i
+
+  template "/etc/php5/fpm/pool.d/#{name}.conf" do
+    source "fpm.conf.erb"
+    owner "root"
+    group "root"
+    mode 0644
+    variables :user => name, :port => port
+    notifies :reload, "service[php5-fpm]"
+  end
+
+  apache_site "#{name}.dev.openstreetmap.org" do
+    template "apache.user.erb"
+    directory "#{user_home}/public_html"
+    variables :user => name, :port => port
   end
 end
 
index 7361624c4d4a75ca374b0f1a952c8e64de18da47..52d6304b090d8e8b4f80f99828d2a6ac1b5227ff 100644 (file)
@@ -61,14 +61,14 @@ Dir.new(git_directory).select { |name| name =~ /\.git$/ }.each do |repository|
     mode 0755
   end
 
-  if node[:recipes].include?("trace") && repository != "dns.git"
-    template "#{git_directory}/#{repository}/hooks/post-receive" do
-      source "post-receive.erb"
-      owner "root"
-      group node[:git][:group]
-      mode 0755
-      variables :repository => "#{git_directory}/#{repository}"
-    end
+  next unless node[:recipes].include?("trac") && repository != "dns.git"
+
+  template "#{git_directory}/#{repository}/hooks/post-receive" do
+    source "post-receive.erb"
+    owner "root"
+    group node[:git][:group]
+    mode 0755
+    variables :repository => "#{git_directory}/#{repository}"
   end
 end
 
index a0ee58485bc0406d6c1f79d73d991af3852784e5..dd2d8015727afc1ccc716fb234eace7cbae45065 100644 (file)
@@ -204,13 +204,13 @@ node[:kernel][:modules].each_key do |modname|
 end
 
 node[:block_device].each do |name, attributes|
-  if attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
-    if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
-      status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
-    else
-      Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
-        status_packages["cciss-vol-status"] |= [File.basename(sg)]
-      end
+  next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
+
+  if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
+    status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
+  else
+    Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
+      status_packages["cciss-vol-status"] |= [File.basename(sg)]
     end
   end
 end
index 2b2bca67d35767b71349058e547cf9799b1bf44a..769df807e0eda0c37c6c71c60ad90cbd595df34b 100644 (file)
@@ -104,12 +104,12 @@ class Chef
       end
 
       query("SELECT * FROM db").each do |record|
-        if database = @databases[record[:db]]
-          user = "'#{record[:user]}'@'#{record[:host]}'"
+        next unless database = @databases[record[:db]]
 
-          database[:permissions][user] = DATABASE_PRIVILEGES.each_with_object([]) do |privilege, privileges|
-            privileges << privilege if record["#{privilege}_priv".to_sym] == "Y"
-          end
+        user = "'#{record[:user]}'@'#{record[:host]}'"
+
+        database[:permissions][user] = DATABASE_PRIVILEGES.each_with_object([]) do |privilege, privileges|
+          privileges << privilege if record["#{privilege}_priv".to_sym] == "Y"
         end
       end
 
index ab735cd7ee1cb9846a78ce11497ce66cc739e17c..647925f263be839ff3b1c47fa359d5e9816cd63e 100644 (file)
@@ -41,11 +41,11 @@ action :create do
   end]
 
   @current_resource.permissions.each_key do |user|
-    unless new_permissions[user]
-      converge_by("revoke all for #{user} on #{new_resource}") do
-        Chef::Log.info("Revoking all for #{user} on #{new_resource}")
-        @mysql.execute(:command => "REVOKE ALL ON `#{new_resource.database}`.* FROM #{user}")
-      end
+    next if new_permissions[user]
+
+    converge_by("revoke all for #{user} on #{new_resource}") do
+      Chef::Log.info("Revoking all for #{user} on #{new_resource}")
+      @mysql.execute(:command => "REVOKE ALL ON `#{new_resource.database}`.* FROM #{user}")
     end
   end
 
index e027b4f5c27d1b427f5fa1a6a3d56b25831230ed..05fd01eb85caf8cad5ec4973826a463814a8faf1 100644 (file)
@@ -42,17 +42,17 @@ action :create do
   end
 
   Chef::MySQL::USER_PRIVILEGES.each do |privilege|
-    if new_resource.send(privilege) != @current_resource.send(privilege)
-      if new_resource.send(privilege)
-        converge_by("grant #{privilege} for #{new_resource}") do
-          Chef::Log.info("Granting #{privilege} for #{new_resource}")
-          @mysql.execute(:command => "GRANT #{@mysql.privilege_name(privilege)} ON *.* TO #{user}")
-        end
-      else
-        converge_by("revoke #{privilege} for #{new_resource}") do
-          Chef::Log.info("Revoking #{privilege} for #{new_resource}")
-          @mysql.execute(:command => "REVOKE #{@mysql.privilege_name(privilege)} ON *.* FROM #{user}")
-        end
+    next if new_resource.send(privilege) == @current_resource.send(privilege)
+
+    if new_resource.send(privilege)
+      converge_by("grant #{privilege} for #{new_resource}") do
+        Chef::Log.info("Granting #{privilege} for #{new_resource}")
+        @mysql.execute(:command => "GRANT #{@mysql.privilege_name(privilege)} ON *.* TO #{user}")
+      end
+    else
+      converge_by("revoke #{privilege} for #{new_resource}") do
+        Chef::Log.info("Revoking #{privilege} for #{new_resource}")
+        @mysql.execute(:command => "REVOKE #{@mysql.privilege_name(privilege)} ON *.* FROM #{user}")
       end
     end
   end
index fa0a93c7d7347ed63f53b1adb08bf5aa849134ee..cd9116dfa8be051956ef6550332e4dc1dbdb10f1 100644 (file)
@@ -7,14 +7,13 @@ class Chef
       networking_interfaces = networking[:interfaces] || []
 
       networking_interfaces.each_value  do |interface|
-        if options[:role].nil? || interface[:role].to_s == options[:role].to_s
-          if options[:family].nil? || interface[:family].to_s == options[:family].to_s
-            if block.nil?
-              interfaces << interface
-            else
-              block.call(interface)
-            end
-          end
+        next unless options[:role].nil? || interface[:role].to_s == options[:role].to_s
+        next unless options[:family].nil? || interface[:family].to_s == options[:family].to_s
+
+        if block.nil?
+          interfaces << interface
+        else
+          block.call(interface)
         end
       end
 
index dc5c69227ba320dc925341ae29602189e2803524..9eebca8c724b70fc89600cd8af305738d7df4234 100644 (file)
@@ -83,24 +83,24 @@ end
 node.interfaces(:role => :internal) do |interface|
   if interface[:gateway] && interface[:gateway] != interface[:address]
     search(:node, "networking_interfaces*address:#{interface[:gateway]}") do |gateway|
-      if gateway[:openvpn]
-        gateway[:openvpn][:tunnels].each_value do |tunnel|
-          if tunnel[:peer][:address]
-            route tunnel[:peer][:address] do
-              netmask "255.255.255.255"
-              gateway interface[:gateway]
-              device interface[:interface]
-            end
+      next unless gateway[:openvpn]
+
+      gateway[:openvpn][:tunnels].each_value do |tunnel|
+        if tunnel[:peer][:address]
+          route tunnel[:peer][:address] do
+            netmask "255.255.255.255"
+            gateway interface[:gateway]
+            device interface[:interface]
           end
+        end
+
+        next unless tunnel[:peer][:networks]
 
-          if tunnel[:peer][:networks]
-            tunnel[:peer][:networks].each do |network|
-              route network[:address] do
-                netmask network[:netmask]
-                gateway interface[:gateway]
-                device interface[:interface]
-              end
-            end
+        tunnel[:peer][:networks].each do |network|
+          route network[:address] do
+            netmask network[:netmask]
+            gateway interface[:gateway]
+            device interface[:interface]
           end
         end
       end
@@ -111,14 +111,14 @@ end
 zones = {}
 
 search(:node, "networking:interfaces").collect do |n|
-  if n[:fqdn] != node[:fqdn]
-    n.interfaces.each do |interface|
-      if interface[:role] == "external" && interface[:zone]
-        zones[interface[:zone]] ||= Hash.new
-        zones[interface[:zone]][interface[:family]] ||= Array.new
-        zones[interface[:zone]][interface[:family]] << interface[:address]
-      end
-    end
+  next if n[:fqdn] == node[:fqdn]
+
+  n.interfaces.each do |interface|
+    next unless interface[:role] == "external" && interface[:zone]
+
+    zones[interface[:zone]] ||= Hash.new
+    zones[interface[:zone]][interface[:family]] ||= Array.new
+    zones[interface[:zone]][interface[:family]] << interface[:address]
   end
 end
 
index 1142adb3fd2e3961cb9930489e2e8a8e806ce445..f75e44e889880f920f4db5986f4fbd332ef4d3fa 100644 (file)
@@ -33,18 +33,18 @@ end
 exports = {}
 
 search(:node, "*:*") do |client|
-  if client[:nfs]
-    client[:nfs].each_value do |mount|
-      if mount[:host] == node[:hostname]
-        client.ipaddresses do |address|
-          exports[mount[:path]] ||= {}
+  next unless client[:nfs]
 
-          if mount[:readonly]
-            exports[mount[:path]][address] = "ro"
-          else
-            exports[mount[:path]][address] = "rw"
-          end
-        end
+  client[:nfs].each_value do |mount|
+    next unless mount[:host] == node[:hostname]
+
+    client.ipaddresses do |address|
+      exports[mount[:path]] ||= {}
+
+      if mount[:readonly]
+        exports[mount[:path]][address] = "ro"
+      else
+        exports[mount[:path]][address] = "rw"
       end
     end
   end
index c2aba251d1b84f7126125962e421650fe6b5a1b2..96e6c2cafcec3238085435d816a46a154a32d5ab 100644 (file)
@@ -60,10 +60,10 @@ munin_plugin "ntp_offset"
 
 if File.directory?("/etc/munin/plugins")
   Dir.new("/etc/munin/plugins").each do |plugin|
-    if plugin.match(/^ntp_/) && !munin_plugins.include?(plugin)
-      munin_plugin plugin do
-        action :delete
-      end
+    next unless plugin.match(/^ntp_/) && !munin_plugins.include?(plugin)
+
+    munin_plugin plugin do
+      action :delete
     end
   end
 end
index 7532cd7acde2c80487e473db6106548df329245e..2c55a64aa18914561f5550eb3482dac391a4932e 100644 (file)
@@ -26,11 +26,11 @@ osmosis_package = "osmosis-#{node[:osmosis][:version]}.zip"
 osmosis_directory = "/opt/osmosis-#{node[:osmosis][:version]}"
 
 Dir.glob("/var/cache/chef/osmosis-*.zip").each do |zip|
-  if zip != "/var/cache/chef/#{osmosis_package}"
-    file zip do
-      action :delete
-      backup false
-    end
+  next if zip == "/var/cache/chef/#{osmosis_package}"
+
+  file zip do
+    action :delete
+    backup false
   end
 end
 
index 7bc8cfb020fd16af0d31f74914e45d3698a8a9fc..b1dc85f7b43d760f2d509bb1a365527fab481003 100644 (file)
@@ -43,11 +43,11 @@ action :create do
     end
 
     @current_resource.permissions.each_key do |user|
-      unless new_resource.permissions[user]
-        converge_by("revoke all for #{user} on #{new_resource}") do
-          Chef::Log.info("Revoking all for #{user} on #{new_resource}")
-          @pg.execute(:command => "REVOKE ALL ON #{@name} FROM \"#{user}\"", :database => new_resource.database)
-        end
+      next if new_resource.permissions[user]
+
+      converge_by("revoke all for #{user} on #{new_resource}") do
+        Chef::Log.info("Revoking all for #{user} on #{new_resource}")
+        @pg.execute(:command => "REVOKE ALL ON #{@name} FROM \"#{user}\"", :database => new_resource.database)
       end
     end
 
index 9fe64344a36049b7f1a5c281b1e22e3dae205009..ea043096cc86a11719db974bd9c02370bc112aa3 100644 (file)
@@ -131,11 +131,11 @@ clusters.each do |name, details|
     conf_variables :port => details[:port]
   end
 
-  if File.exist?("/var/lib/postgresql/#{details[:version]}/main/recovery.conf")
-    munin_plugin "postgres_replication_#{suffix}" do
-      target "postgres_replication"
-      conf "munin.erb"
-      conf_variables :port => details[:port]
-    end
+  next unless File.exist?("/var/lib/postgresql/#{details[:version]}/main/recovery.conf")
+
+  munin_plugin "postgres_replication_#{suffix}" do
+    target "postgres_replication"
+    conf "munin.erb"
+    conf_variables :port => details[:port]
   end
 end
index 6d4d6b7635bb14b46114ab0b6e825eff5c55c701..18eb23082249484f380d5f7e367aa5d71b15d293 100644 (file)
@@ -25,19 +25,15 @@ hosts_deny = {}
 node[:rsyncd][:modules].each do |name, details|
   hosts_allow[name] = details[:hosts_allow] || []
 
-  if details[:nodes_allow]
-    hosts_allow[name] |= search(:node, details[:nodes_allow]).collect do |n|
-      n.ipaddresses(:role => :external)
-    end.flatten
-  end
+  hosts_allow[name] |= search(:node, details[:nodes_allow]).collect do |n|
+    n.ipaddresses(:role => :external)
+  end.flatten if details[:nodes_allow]
 
   hosts_deny[name] = details[:hosts_deny] || []
 
-  if details[:nodes_deny]
-    hosts_deny[name] |= search(:node, details[:nodes_deny]).collect do |n|
-      n.ipaddresses(:role => :external)
-    end.flatten
-  end
+  hosts_deny[name] |= search(:node, details[:nodes_deny]).collect do |n|
+    n.ipaddresses(:role => :external)
+  end.flatten if details[:nodes_deny]
 end
 
 package "rsync"
index c6916943ade718c8c0840be36a0549aeb88e348b..7757386c5902272475f387fc1149d1a16279e72c 100755 (executable)
@@ -126,13 +126,14 @@ module Expire
     node_cache = NodeCache.new(NODE_CACHE_FILE)
     doc.find('//way/nd').each do |node|
       node_id = node['ref'].to_i
-      unless nodes.include? node_id
-        # this is a node referenced but not added, modified or deleted, so it should
-        # still be in the node cache.
-        if entry = node_cache[node_id]
-          point = Proj4::Point.new(entry.lon, entry.lat)
-          nodes[node_id] = tile_from_merc(point, max_zoom)
-        end
+
+      next if nodes.include? node_id
+
+      # this is a node referenced but not added, modified or deleted, so it should
+      # still be in the node cache.
+      if entry = node_cache[node_id]
+        point = Proj4::Point.new(entry.lon, entry.lat)
+        nodes[node_id] = tile_from_merc(point, max_zoom)
       end
     end