diff --git a/.rubocop.yml b/.rubocop.yml index a79ebcf..ec42bff 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -80,3 +80,17 @@ Style/HashTransformKeys: # Added in 0.80, don't really care about the change Style/HashTransformValues: Enabled: false + +# These short variable names make sense as exceptions to the rule, but generally I think short variable names do hurt readability +Naming/MethodParameterName: + AllowedNames: + - vm + - dc + - s + - x + - f + +# Standard comparisons seem more readable +Style/NumericPredicate: + Enabled: true + EnforcedStyle: comparison \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index cd54d84..d438f26 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,9 +16,6 @@ matrix: - rvm: jruby-9.2.9.0 env: "CHECK=test" - # Remove the allow_failures section once - # Rubocop is required for Travis to pass a build - allow_failures: - rvm: 2.4.9 env: "CHECK=rubocop" diff --git a/lib/vmpooler.rb b/lib/vmpooler.rb index 7281c36..5ae00f1 100644 --- a/lib/vmpooler.rb +++ b/lib/vmpooler.rb @@ -198,7 +198,7 @@ module Vmpooler obj.to_s.downcase == 'true' end - def self.set_linked_clone(parsed_config) + def self.set_linked_clone(parsed_config) # rubocop:disable Naming/AccessorMethodName parsed_config[:config]['create_linked_clones'] = parsed_config[:config]['create_linked_clones'] || true parsed_config[:config]['create_linked_clones'] = ENV['CREATE_LINKED_CLONES'] if ENV['CREATE_LINKED_CLONES'] =~ /true|false/ parsed_config[:config]['create_linked_clones'] = true?(parsed_config[:config]['create_linked_clones']) if parsed_config[:config]['create_linked_clones'] diff --git a/lib/vmpooler/api/dashboard.rb b/lib/vmpooler/api/dashboard.rb index 84bae1d..4c56798 100644 --- a/lib/vmpooler/api/dashboard.rb +++ b/lib/vmpooler/api/dashboard.rb @@ -83,7 +83,7 @@ module Vmpooler history ||= {} begin - buffer = open(graph_link('.ready.*&from=-1hour&format=json')).read + buffer = URI.parse(graph_link('.ready.*&from=-1hour&format=json')).read history = JSON.parse(buffer) history.each do |pool| @@ -136,7 +136,7 @@ module Vmpooler if params[:history] if graph_url begin - buffer = open(graph_link('.running.*&from=-1hour&format=json')).read + buffer = URI.parse(graph_link('.running.*&from=-1hour&format=json')).read JSON.parse(buffer).each do |pool| if pool['target'] =~ /.*\.(.*)$/ pool['name'] = Regexp.last_match[1] diff --git a/lib/vmpooler/api/helpers.rb b/lib/vmpooler/api/helpers.rb index aeed4ce..0b98143 100644 --- a/lib/vmpooler/api/helpers.rb +++ b/lib/vmpooler/api/helpers.rb @@ -79,38 +79,38 @@ module Vmpooler def authenticate(auth, username_str, password_str) case auth['provider'] - when 'dummy' - return (username_str != password_str) - when 'ldap' - ldap_base = auth[:ldap]['base'] - ldap_port = auth[:ldap]['port'] || 389 + when 'dummy' + return (username_str != password_str) + when 'ldap' + ldap_base = auth[:ldap]['base'] + ldap_port = auth[:ldap]['port'] || 389 - if ldap_base.is_a? Array - ldap_base.each do |search_base| - result = authenticate_ldap( - ldap_port, - auth[:ldap]['host'], - auth[:ldap]['user_object'], - search_base, - username_str, - password_str - ) - return true if result == true - end - else + if ldap_base.is_a? Array + ldap_base.each do |search_base| result = authenticate_ldap( ldap_port, auth[:ldap]['host'], auth[:ldap]['user_object'], - ldap_base, + search_base, username_str, password_str ) - return result + return true if result == true end - - return false + else + result = authenticate_ldap( + ldap_port, + auth[:ldap]['host'], + auth[:ldap]['user_object'], + ldap_base, + username_str, + password_str + ) + return result end + + return false + end end def export_tags(backend, hostname, tags) @@ -216,7 +216,7 @@ module Vmpooler capacity[:current] = get_total_across_pools_redis_scard(pools, 'vmpooler__ready__', backend) if capacity[:total] > 0 - capacity[:percent] = ((capacity[:current].to_f / capacity[:total].to_f) * 100.0).round(1) + capacity[:percent] = (capacity[:current].fdiv(capacity[:total]) * 100.0).round(1) end capacity diff --git a/lib/vmpooler/api/v1.rb b/lib/vmpooler/api/v1.rb index 05957f3..469d68a 100644 --- a/lib/vmpooler/api/v1.rb +++ b/lib/vmpooler/api/v1.rb @@ -225,7 +225,7 @@ module Vmpooler payload.each do |poolname, clone_target| unless pools[pool_index[poolname]]['clone_target'] == clone_target - pools[pool_index[poolname]]['clone_target'] == clone_target + pools[pool_index[poolname]]['clone_target'] = clone_target backend.hset('vmpooler__config__clone_target', poolname, clone_target) pools_updated += 1 status 201 @@ -267,7 +267,7 @@ module Vmpooler if pool_index.include? poolname unless pools[pool_index[poolname]]['clone_target'] == clone_target pools[pool_index[poolname]]['clone_target'] == clone_target - end + end end end end diff --git a/lib/vmpooler/logger.rb b/lib/vmpooler/logger.rb index f8a9644..218ec4c 100644 --- a/lib/vmpooler/logger.rb +++ b/lib/vmpooler/logger.rb @@ -16,7 +16,7 @@ module Vmpooler puts "[#{stamp}] #{string}" if ENV['VMPOOLER_DEBUG'] - open(@file, 'a') do |f| + File.open(@file, 'a') do |f| f.puts "[#{stamp}] #{string}" end end diff --git a/lib/vmpooler/pool_manager.rb b/lib/vmpooler/pool_manager.rb index 22d7764..4c887d3 100644 --- a/lib/vmpooler/pool_manager.rb +++ b/lib/vmpooler/pool_manager.rb @@ -121,7 +121,7 @@ module Vmpooler def move_pending_vm_to_ready(vm, pool) clone_time = $redis.hget('vmpooler__vm__' + vm, 'clone') - finish = format('%.2f', Time.now - Time.parse(clone_time)) if clone_time + finish = format('%