Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some RuboCop rules #330

Merged
merged 5 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/helpers/proxmox_compute_resources_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def user_token_expiration_date(compute_resource)
def cluster_nodes(compute_resource)
nodes = compute_resource.nodes ? compute_resource.nodes.collect(&:node) : []
rescue ::Foreman::Exception => e
return [] if e.message == 'User token expired'
[] if e.message == 'User token expired'
rescue StandardError => e
logger.warn("failed to get cluster nodes: #{e}")
raise e
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/proxmox_form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def password_proxmox_f(f, attr, options = {})
addClass options, 'form-control'
pass = f.password_field(attr, options) +
tag(:span, '', class: 'glyphicon glyphicon-warning-sign input-addon', title: 'Caps lock ON',
style: 'display:none')
style: 'display:none')
if unset_button
button = link_to_function(icon_text('edit', '', :kind => 'pficon'), 'toggle_input_group(this)',
:id => 'disable-pass-btn', :class => 'btn btn-default', :title => _('Change the password'))
Expand All @@ -56,7 +56,7 @@ def new_child_fields_template_typed(form_builder, association, options = {})
options[:form_builder_attrs] ||= {}

content_tag(:div, :class => "#{options[:type]}_#{association}_fields_template form_template",
:style => 'display: none;') do
:style => 'display: none;') do
form_builder.fields_for(association, options[:object],
:child_index => "new_#{options[:type]}_#{association}") do |f|
render(:partial => options[:partial], :layout => options[:layout],
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/proxmox_vm_interfaces_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ def interface_compute_attributes_typed_keys(type)
end

def interface_common_typed_keys(type)
['id', type == 'qemu' ? 'macaddr' : 'hwaddr']
['id', (type == 'qemu') ? 'macaddr' : 'hwaddr']
end

def compute_dhcps(interface_attributes_h)
interface_attributes_h[:dhcp] = interface_attributes_h[:ip] == 'dhcp' ? '1' : '0'
interface_attributes_h[:dhcp] = (interface_attributes_h[:ip] == 'dhcp') ? '1' : '0'
interface_attributes_h[:ip] = '' if interface_attributes_h[:dhcp] == '1'
interface_attributes_h[:dhcp6] = interface_attributes_h[:ip6] == 'dhcp' ? '1' : '0'
interface_attributes_h[:dhcp6] = (interface_attributes_h[:ip6] == 'dhcp') ? '1' : '0'
interface_attributes_h[:ip6] = '' if interface_attributes_h[:dhcp6] == '1'
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/fog_extensions/proxmox/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def each(collection_filters = {}, &block)
# We need to explicitly use the base 'each' method here on the page,
# otherwise we get infinite recursion
base_each = Fog::Collection.instance_method(:each)
base_each.bind(page).call(&block)
base_each.bind_call(page, &block)
end
end
self
Expand Down
6 changes: 3 additions & 3 deletions app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def host_compute_attrs(host)
unless compute_os_types(host).include?(ostype)
raise ::Foreman::Exception,
format(_('Operating system family %<type>s is not consistent with %<ostype>s'), type: host.operatingsystem.type,
ostype: ostype)
ostype: ostype)
end
end
super
Expand All @@ -42,8 +42,8 @@ def not_config_key?(vm, key)

def interface_compute_attributes(interface_attributes)
vm_attrs = ForemanFogProxmox::HashCollection.new_hash_reject_keys(interface_attributes, [:identifier, :macaddr, :hwaddr])
vm_attrs[:dhcp] = interface_attributes[:ip] == 'dhcp' ? '1' : '0'
vm_attrs[:dhcp6] = interface_attributes[:ip6] == 'dhcp' ? '1' : '0'
vm_attrs[:dhcp] = (interface_attributes[:ip] == 'dhcp') ? '1' : '0'
vm_attrs[:dhcp6] = (interface_attributes[:ip6] == 'dhcp') ? '1' : '0'
vm_attrs
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/foreman_fog_proxmox/proxmox_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def version
v = identity_client.read_version if identity_client
v ? v['version'] : 'Unknown'
rescue ::Foreman::Exception => e
return 'Unkown' if e.message == 'User token expired'
'Unkown' if e.message == 'User token expired'
rescue StandardError => e
logger.warn("failed to get identity client version: #{e}")
raise e
Expand Down
2 changes: 1 addition & 1 deletion app/models/foreman_fog_proxmox/proxmox_vm_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def create_vm(args = {})
end

def assign_vmid(vmid, node)
vmid < 1 ? node.servers.next_id : vmid
(vmid < 1) ? node.servers.next_id : vmid
end

def compute_clone_attributes(args, container, type)
Expand Down
2 changes: 1 addition & 1 deletion app/models/foreman_fog_proxmox/proxmox_vm_new.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def new_typed_vm(new_attr, type)
new_attr_type ||= type
logger.debug("new_typed_vm(#{type}): new_attr_type=#{new_attr_type}")
logger.debug("new_typed_vm(#{type}): new_attr=#{new_attr}'")
options = !new_attr.key?('vmid') || ForemanFogProxmox::Value.empty?(new_attr['vmid']) ? vm_typed_instance_defaults(type).merge(new_attr).merge(type: type) : new_attr
options = (!new_attr.key?('vmid') || ForemanFogProxmox::Value.empty?(new_attr['vmid'])) ? vm_typed_instance_defaults(type).merge(new_attr).merge(type: type) : new_attr
logger.debug("new_typed_vm(#{type}): options=#{options}")
vm_h = parse_typed_vm(options, type).deep_symbolize_keys
logger.debug("new_typed_vm(#{type}): vm_h=#{vm_h}")
Expand Down
6 changes: 3 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
Rails.application.routes.draw do
namespace :foreman_fog_proxmox do
match 'isos/:compute_resource_id/:node_id/:storage', :to => 'compute_resources#isos_by_id_and_node_and_storage',
:via => 'get'
:via => 'get'
match 'ostemplates/:compute_resource_id/:node_id/:storage',
:to => 'compute_resources#ostemplates_by_id_and_node_and_storage', :via => 'get'
match 'isos/:compute_resource_id/:node_id', :to => 'compute_resources#isos_by_id_and_node', :via => 'get'
match 'ostemplates/:compute_resource_id/:node_id', :to => 'compute_resources#ostemplates_by_id_and_node',
:via => 'get'
:via => 'get'
match 'storages/:compute_resource_id/:node_id', :to => 'compute_resources#storages_by_id_and_node', :via => 'get'
match 'isostorages/:compute_resource_id/:node_id', :to => 'compute_resources#iso_storages_by_id_and_node',
:via => 'get'
:via => 'get'
match 'bridges/:compute_resource_id/:node_id', :to => 'compute_resources#bridges_by_id_and_node', :via => 'get'
end
end
14 changes: 7 additions & 7 deletions test/factories/proxmox_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
require 'fog/proxmox/compute/models/node'

FactoryBot.define do
factory :proxmox_resource, :class => ComputeResource do
factory :proxmox_resource, :class => 'ComputeResource' do
sequence(:name) { |n| "compute_resource#{n}" }
organizations { [Organization.find_by(name: 'Organization 1')] }
locations { [Location.find_by(name: 'Location 1')] }
Expand All @@ -32,18 +32,18 @@
url { 'https://192.168.56.101:8006/api2/json' }
end

factory :proxmox_cr, :class => ForemanFogProxmox::Proxmox, :traits => [:proxmox]
factory :proxmox_cr, :class => 'ForemanFogProxmox::Proxmox', :traits => [:proxmox]
end

factory :node, :class => Fog::Proxmox::Compute::Node do
factory :node, :class => 'Fog::Proxmox::Compute::Node' do
sequence(:identity) { |n| "node#{n}" }
trait :proxmox do
identity { 'proxmox' }
end
trait :service do
service { :proxmox_cr }
end
factory :proxmox_node, :class => Fog::Proxmox::Compute::Node, :traits => [:proxmox, :service]
factory :proxmox_node, :class => 'Fog::Proxmox::Compute::Node', :traits => [:proxmox, :service]
end

def deferred_nic_attrs
Expand All @@ -59,16 +59,16 @@ def set_nic_attributes(host, attributes, evaluator)
host
end

factory :nic_base_empty, :class => Nic::Base do
factory :nic_base_empty, :class => 'Nic::Base' do
type { 'Nic::Base' }
end

factory :nic_managed_empty, :class => Nic::Managed, :parent => :nic_base_empty do
factory :nic_managed_empty, :class => 'Nic::Managed', :parent => :nic_base_empty do
type { 'Nic::Managed' }
identifier { 'net0' }
end

factory :host_empty, :class => Host do
factory :host_empty, :class => 'Host' do
sequence(:name) { |n| "host#{n}" }
sequence(:hostname) { |n| "host#{n}" }
trait :compute_attributes do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ProxmoxComputeAttributesTest < ActiveSupport::TestCase

it 'sets container hostname with host name' do
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :primary => true,
:compute_attributes => { 'dhcp' => '1', 'dhcp6' => '1' })
:compute_attributes => { 'dhcp' => '1', 'dhcp6' => '1' })
host = FactoryBot.build(
:host_empty,
:interfaces => [physical_nic],
Expand Down
12 changes: 6 additions & 6 deletions test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ProxmoxInterfacesTest < ActiveSupport::TestCase
it 'raises Foreman::Exception when server proxmox NIC id does not match net[k] with k integer' do
compute_attributes = ActiveSupport::HashWithIndifferentAccess.new({ 'id' => 'dsfqsfqzef' })
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'eth0',
:compute_attributes => compute_attributes)
:compute_attributes => compute_attributes)
host = FactoryBot.build(
:host_empty,
:interfaces => [physical_nic],
Expand All @@ -58,7 +58,7 @@ class ProxmoxInterfacesTest < ActiveSupport::TestCase
ip6 = Array.new(4) { format('%<x>s', x: rand(16**4)) }.join(':') + '::1'
compute_attributes = ActiveSupport::HashWithIndifferentAccess.new({ 'id' => 'net0' })
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6,
:mac => mac_address, :compute_attributes => compute_attributes)
:mac => mac_address, :compute_attributes => compute_attributes)
host = FactoryBot.build(
:host_empty,
:interfaces => [physical_nic],
Expand All @@ -75,7 +75,7 @@ class ProxmoxInterfacesTest < ActiveSupport::TestCase
it 'raises Foreman::Exception when container proxmox NIC id does not match net[k] with k integer' do
compute_attributes = ActiveSupport::HashWithIndifferentAccess.new({ 'id' => 'dsfqsfqzef' })
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'eth0',
:compute_attributes => compute_attributes)
:compute_attributes => compute_attributes)
host = FactoryBot.build(
:host_empty,
:interfaces => [physical_nic],
Expand All @@ -94,7 +94,7 @@ class ProxmoxInterfacesTest < ActiveSupport::TestCase
compute_attributes = ActiveSupport::HashWithIndifferentAccess.new({ 'id' => 'net0', 'cidr' => cidr, 'gw' => ip,
'ip' => ip, 'dhcp6' => '1' })
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6,
:compute_attributes => compute_attributes)
:compute_attributes => compute_attributes)
host = FactoryBot.build(
:host_empty,
:interfaces => [physical_nic],
Expand All @@ -115,7 +115,7 @@ class ProxmoxInterfacesTest < ActiveSupport::TestCase
compute_attributes = ActiveSupport::HashWithIndifferentAccess.new({ 'id' => 'net0', 'cidr6' => cidr6,
'dhcp' => '1', 'gw6' => ip6 })
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6,
:compute_attributes => compute_attributes)
:compute_attributes => compute_attributes)
host = FactoryBot.build(
:host_empty,
:interfaces => [physical_nic],
Expand All @@ -137,7 +137,7 @@ class ProxmoxInterfacesTest < ActiveSupport::TestCase
compute_attributes = ActiveSupport::HashWithIndifferentAccess.new({ 'id' => 'net0', 'dhcp' => '1',
'ip6' => ip6, 'firewall' => firewall })
physical_nic = FactoryBot.build(:nic_base_empty, :identifier => 'net0', :ip => ip, :ip6 => ip6,
:mac => mac_address, :compute_attributes => compute_attributes)
:mac => mac_address, :compute_attributes => compute_attributes)
host = FactoryBot.build(
:host_empty,
:interfaces => [physical_nic],
Expand Down