Update libraries to be rubocop compliant

- Update rubocop config to include libraries/**
- Update libraries to comply with rubocop

Change-Id: I143944f77803da3525aefae54fe2ae3f6406d337
Implements: blueprint rubocop-for-object-storage
This commit is contained in:
Christopher H. Laco
2014-02-04 12:20:51 -05:00
committed by Gerrit Code Review
parent 6b3218d125
commit 183c2f7b82
3 changed files with 19 additions and 16 deletions

View File

@@ -3,12 +3,11 @@ AllCops:
- metadata.rb - metadata.rb
- Gemfile - Gemfile
- attributes/** - attributes/**
- libraries/**
- providers/** - providers/**
- recipes/** - recipes/**
- resources/** - resources/**
- spec/** - spec/**
Excludes:
- libraries/**
Encoding: Encoding:
Exclude: Exclude:

View File

@@ -1,3 +1,4 @@
# encoding: UTF-8
# #
# Cookbook Name:: openstack-object-storage # Cookbook Name:: openstack-object-storage
# Library:: drive_utils # Library:: drive_utils
@@ -19,11 +20,14 @@
# Author: Ron Pedde <ron.pedde@rackspace.com> # Author: Ron Pedde <ron.pedde@rackspace.com>
# #
# Drive Inspection Related Utilities
# rubocop:disable Eval, UselessAssignment
# TODO(chrislaco) This is a tragedy, and needs refactored
module DriveUtils module DriveUtils
def locate_disks(enum_expression, filter_expressions) def locate_disks(enum_expression, filter_expressions)
candidate_disks = eval(enum_expression) candidate_disks = eval(enum_expression)
candidate_expression = "candidate_disks.select{|candidate,info| (" + candidate_expression = 'candidate_disks.select{|candidate,info| (' +
filter_expressions.map{|x| "(#{x})"}.join(" and ") + ")}" filter_expressions.map { |x| "(#{x})" }.join(' and ') + ')}'
# TODO(mancdaz): fix this properly so the above works in the first place # TODO(mancdaz): fix this properly so the above works in the first place
candidate_expression.gsub!(/\[\'removable\'\] = 0/, "['removable'].to_i == 0") candidate_expression.gsub!(/\[\'removable\'\] = 0/, "['removable'].to_i == 0")
drives = Hash[eval(candidate_expression)] drives = Hash[eval(candidate_expression)]
@@ -31,4 +35,3 @@ module DriveUtils
drives.keys drives.keys
end end
end end

View File

@@ -1,3 +1,4 @@
# encoding: UTF-8
# #
# Cookbook Name:: openstack-object-storage # Cookbook Name:: openstack-object-storage
# Library:: ip_utils # Library:: ip_utils
@@ -19,20 +20,20 @@
# Author: Alan Meadows <alan.meadows@gmail.com> # Author: Alan Meadows <alan.meadows@gmail.com>
# #
require "ipaddr" require 'ipaddr'
# IPAddress Related Utilities
module IPUtils module IPUtils
def locate_ip_in_cidr(network, node) # TODO(chrislaco) This needs yanked/refactored into common/libraries/network
def locate_ip_in_cidr(network, node) # rubocop:disable MethodLength
Chef::Log.debug("Searching for ip within #{network} on node #{node.name}") Chef::Log.debug("Searching for ip within #{network} on node #{node.name}")
net = IPAddr.new(network) net = IPAddr.new(network)
node["network"]["interfaces"].each do |interface| node['network']['interfaces'].each do |interface|
if interface[1].has_key?("addresses") then if interface[1].key?('addresses')
interface[1]["addresses"].each do |k,v| interface[1]['addresses'].each do |k, v|
if v["family"] == "inet6" or (v["family"] == "inet" and v["prefixlen"] != "32") then if v['family'] == 'inet6' || (v['family'] == 'inet' && v['prefixlen'] != '32')
addr=IPAddr.new(k) addr = IPAddr.new(k)
if net.include?(addr) then return k if net.include?(addr)
return k
end
end end
end end
end end
@@ -40,6 +41,6 @@ module IPUtils
error = "Can't find address within network #{network} for node #{node.name}" error = "Can't find address within network #{network} for node #{node.name}"
Chef::Log.error(error) Chef::Log.error(error)
raise error fail error
end end
end end