1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-23 22:50:09 +03:00

L #-: Linting changes in ruby files

rubocop 0.88.0

(cherry picked from commit cc4d80884b89834e77d1c838e9553a6b73150cfb)
This commit is contained in:
Tino Vazquez 2020-07-17 13:38:09 +02:00
parent 0278094ad6
commit 4afaf937bc
No known key found for this signature in database
GPG Key ID: 2FE9C32E94AEABBE
22 changed files with 88 additions and 69 deletions

View File

@ -528,6 +528,8 @@ AllCops:
- src/flow/lib/grammar.rb
- src/flow/lib/validator.rb
########
# LAYOUT
########
@ -684,6 +686,38 @@ Style/ExponentialNotation:
Style/SlicingWithRange:
Enabled: true
Style/AccessorGrouping:
Enabled: False
Style/ArrayCoercion:
Enabled: True
Style/BisectedAttrAccessor:
Enabled: True
Style/CaseLikeIf:
Enabled: True
Style/HashAsLastArrayItem:
Enabled: True
Style/HashLikeCase:
Enabled: True
Style/RedundantAssignment:
Enabled: True
Style/RedundantFetchBlock:
Enabled: True
Style/RedundantFileExtensionInRequire:
Enabled: True
Style/RedundantRegexpCharacterClass:
Enabled: True
Style/RedundantRegexpEscape:
Enabled: False
######
# LINT
@ -737,6 +771,12 @@ Lint/Debugger:
Lint/ScriptPermission:
Enabled: false
Lint/DuplicateElsifCondition:
Enabled: True
Lint/MixedRegexpCaptureTypes:
Enabled: True
#########
# METRICS
########

View File

@ -325,9 +325,10 @@ module CLIHelper
column[:size] = 5
conf.each do |c|
if c.is_a? Symbol
case c.is_a?
when Symbol
column[c] = true
elsif c.is_a? Hash
when Hash
c.each do |key, value|
column[key] = value
end

View File

@ -115,7 +115,7 @@ class OneAclHelper < OpenNebulaHelper::OneHelper
def format_pool(_options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
CLIHelper::ShowTable.new(config_file, self) do
column :ID,
'Rule Identifier',
:size => 5 do |d|
@ -157,8 +157,6 @@ class OneAclHelper < OpenNebulaHelper::OneHelper
default :ID, :USER, :RES_VHNIUTGDCOZSvRMAPt, :RID, :OPE_UMAC, :ZONE
end
table
end
# rubocop:enable Lint/IneffectiveAccessModifier

View File

@ -94,7 +94,7 @@ class OneHookHelper < OpenNebulaHelper::OneHelper
def format_pool(_options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
CLIHelper::ShowTable.new(config_file, self) do
column :ID, 'ONE identifier for the Hook', :size => 5 do |d|
d['ID']
end
@ -109,8 +109,6 @@ class OneHookHelper < OpenNebulaHelper::OneHelper
default :ID, :NAME, :TYPE
end
table
end
# Function to print Execution Log records as sent by oned using:

View File

@ -103,7 +103,7 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
CLIHelper::ShowTable.new(config_file, self) do
column :ID, 'ONE identifier for Host', :size => 4 do |d|
d['ID']
end
@ -233,8 +233,6 @@ class OneHostHelper < OpenNebulaHelper::OneHelper
default :ID, :NAME, :CLUSTER, :TVM,
:ALLOCATED_CPU, :ALLOCATED_MEM, :STAT
end
table
end
def set_hybrid(type, path)

View File

@ -192,7 +192,7 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
CLIHelper::ShowTable.new(config_file, self) do
column :ID, 'ONE identifier for the Image', :size=>4 do |d|
d['ID']
end
@ -246,8 +246,6 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
default :ID, :USER, :GROUP, :NAME, :DATASTORE, :SIZE, :TYPE,
:PERSISTENT, :STAT, :RVMS
end
table
end
def check_orphans

View File

@ -49,7 +49,7 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper
def format_pool
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
CLIHelper::ShowTable.new(config_file, self) do
column :ID, 'Identifier for the Provision', :size => 36 do |p|
p['ID']
end
@ -80,8 +80,6 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper
default :ID, :NAME, :CLUSTERS, :HOSTS, :NETWORKS, :DATASTORES, :STAT
end
table
end
#######################################################################
@ -228,11 +226,9 @@ class OneProvisionHelper < OpenNebulaHelper::OneHelper
end
def names_to_ids(objects, type)
objects = [objects].flatten.map do |obj|
[objects].flatten.map do |obj|
OpenNebulaHelper.rname_to_id(obj.to_s, type)[1]
end
objects
end
def get_list(provision_list)

View File

@ -176,7 +176,7 @@ files_to_upload.each_with_index do |f, index|
if last_file_to_upload?(index, files_to_upload)
puts stdout_str
end
next if status.success?
STDERR.puts "Cannot upload file #{f}"

View File

@ -768,7 +768,7 @@ class ServiceLCM
action = :wait_deploy
end
rc = roles.each do |name, role|
roles.each do |name, role|
rc = role.deploy
if !rc[0]
@ -788,8 +788,6 @@ class ServiceLCM
rc[0],
report)
end
rc
end
def undeploy_roles(client, roles, success_state, error_state, scale)
@ -799,7 +797,7 @@ class ServiceLCM
action = :wait_undeploy
end
rc = roles.each do |name, role|
roles.each do |name, role|
rc = role.shutdown(false)
if !rc[0]
@ -820,8 +818,6 @@ class ServiceLCM
role.name,
rc[0])
end
rc
end
def set_cardinality(role, cardinality, force)

View File

@ -25,8 +25,8 @@ require 'opennebula/document_pool_json'
require 'validator'
require 'models/role.rb'
require 'models/service_pool.rb'
require 'models/service.rb'
require 'models/service_template_pool.rb'
require 'models/service_template.rb'
require 'models/role'
require 'models/service_pool'
require 'models/service'
require 'models/service_template_pool'
require 'models/service_template'

View File

@ -156,7 +156,7 @@ module LXD
cpu = cpu.chomp('%').to_f / 100
mem = parse_memory(mem)
template = <<-EOT
<<-EOT
NAME = "#{@deploy_id}"
CPU = #{cpu}
VCPU = #{vcpu}
@ -166,8 +166,6 @@ module LXD
DEPLOY_ID = "#{@deploy_id}"
OS = [ ARCH="#{arch}" ]
EOT
template
end
private

View File

@ -96,10 +96,8 @@ class MonitorClient
data = edata
end
zdata = Zlib::Deflate.deflate(data, Zlib::BEST_COMPRESSION)
data64 = Base64.strict_encode64(zdata)
data64
zdata = Zlib::Deflate.deflate(data, Zlib::BEST_COMPRESSION)
Base64.strict_encode64(zdata)
end
end

View File

@ -69,15 +69,16 @@ module OneProvision
end
end
if choice == :retry
case choice
when :retry
sleep(seconds) if seconds
retry
elsif choice == :quit
when :quit
exit(-1)
elsif choice == :skip
when :skip
return :skip
elsif choice == :cleanup
when :cleanup
raise OneProvisionCleanupException if cleanup
Utils.fail('Cleanup unsupported for this operation')

View File

@ -290,9 +290,10 @@ module OneProvision
timeout = meta['wait_timeout']
end
if wait == false
case wait
when false
[wait, nil]
elsif wait == true
when true
if timeout
[wait, timeout]
else

View File

@ -306,13 +306,14 @@ module OneProvision
def evaluate_erb(provision, root)
if root.is_a? Hash
root.each_pair do |key, value|
if value.is_a? Array
case value.is_a?
when Array
root[key] = value.map do |x|
evaluate_erb(provision, x)
end
elsif value.is_a? Hash
when Hash
root[key] = evaluate_erb(provision, value)
elsif value.is_a? String
when String
if value =~ /<%= /
root[key] = get_erb_value(provision, value)
end
@ -439,7 +440,7 @@ module OneProvision
ind_tab = ' '
end
str = attributes.collect do |key, value|
attributes.collect do |key, value|
next unless value
str_line = ''
@ -483,8 +484,6 @@ module OneProvision
end
str_line
end.compact.join("\n")
str
end
end

View File

@ -57,10 +57,11 @@ post '/nsx/auth' do
nsxuser,
nsxpassword,
nsx_type)
if nsx_type == 'NSX-T'
case nsx_type
when 'NSX-T'
url = NSXDriver::NSXConstants::NSXT_AUTH
response = nsx_client.get_token(url)
elsif nsx_type == 'NSX-V'
when 'NSX-V'
url = NSXDriver::NSXConstants::NSXV_AUTH
response = nsx_client.get_token(url)
else

View File

@ -144,9 +144,10 @@ get '/support/request' do
end
zrequests.each do |zrequest|
if zrequest.status == 'pending'
case zrequest.status
when 'pending'
pending_requests += 1
elsif zrequest.status == 'open'
when 'open'
open_requests += 1
end

View File

@ -155,7 +155,7 @@ module NSXDriver
break
end
nic_data = {
{
:id => nic_id,
:name => nic_name,
:network_name => network_name,
@ -163,8 +163,6 @@ module NSXDriver
:network_vcref => network_vcref,
:lp => nic_lp
}
nic_data
end
# Create OpenNebula fw rules for an instance (given a template)

View File

@ -119,11 +119,10 @@ module NSXDriver
err_msg = rc.message
raise CreateNetworkError, err_msg
end
vnet_data = {
{
:nsxid => one_vnet['TEMPLATE/NSX_ID'],
:name => one_vnet['NAME']
}
vnet_data
end
def extract_rule_data(xml_rule)
@ -161,7 +160,7 @@ module NSXDriver
end
end
# Create hash with data
rule_data = {
{
:id => sg_id,
:name => sg_name,
:direction => sg_direction,
@ -173,8 +172,6 @@ module NSXDriver
:subnets => sg_subnets,
:ports => sg_ports.split(',')
}
rule_data
end
def rule_spec(rule, vm_data, nic_data, nsx_client)

View File

@ -91,8 +91,7 @@ module NSXDriver
return if result.nil?
xp = NSXConstants::NSXV_DFW_SECTION_XPATH
section = result.xpath(xp)
section
result.xpath(xp)
end
# Create new section

View File

@ -97,7 +97,8 @@ module VirtualMachineDevice
config = {}
if action == :delete
case action
when :delete
if managed?
key = "opennebula.mdisk.#{@id}"
else
@ -106,14 +107,14 @@ module VirtualMachineDevice
config[:key] = key
config[:value] = ''
elsif action == :resize
when :resize
if new_size
d = device
d.capacityInKB = new_size
config[:device] = d
config[:operation] = :edit
end
elsif action == :attach
when :attach
puts 'not supported'
end

View File

@ -82,7 +82,7 @@ require 'resolv'
# vCenter Library #
# ---------------------------------------------------------------------------- #
require 'vcenter_importer.rb'
require 'vcenter_importer:'
require 'memoize'
require 'vi_client'
begin