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
- Gemfile
- attributes/**
- libraries/**
- providers/**
- recipes/**
- resources/**
- spec/**
Excludes:
- libraries/**
Encoding:
Exclude:

View File

@@ -1,3 +1,4 @@
# encoding: UTF-8
#
# Cookbook Name:: openstack-object-storage
# Library:: drive_utils
@@ -19,11 +20,14 @@
# 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
def locate_disks(enum_expression, filter_expressions)
candidate_disks = eval(enum_expression)
candidate_expression = "candidate_disks.select{|candidate,info| (" +
filter_expressions.map{|x| "(#{x})"}.join(" and ") + ")}"
candidate_expression = 'candidate_disks.select{|candidate,info| (' +
filter_expressions.map { |x| "(#{x})" }.join(' and ') + ')}'
# TODO(mancdaz): fix this properly so the above works in the first place
candidate_expression.gsub!(/\[\'removable\'\] = 0/, "['removable'].to_i == 0")
drives = Hash[eval(candidate_expression)]
@@ -31,4 +35,3 @@ module DriveUtils
drives.keys
end
end

View File

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