diff --git a/app/helpers/proxmox_compute_resources_helper.rb b/app/helpers/proxmox_compute_resources_helper.rb index ef1027484..e9b99f8c2 100644 --- a/app/helpers/proxmox_compute_resources_helper.rb +++ b/app/helpers/proxmox_compute_resources_helper.rb @@ -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 diff --git a/app/helpers/proxmox_form_helper.rb b/app/helpers/proxmox_form_helper.rb index 3d7a742a0..5c793ec56 100644 --- a/app/helpers/proxmox_form_helper.rb +++ b/app/helpers/proxmox_form_helper.rb @@ -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')) @@ -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], diff --git a/app/helpers/proxmox_vm_interfaces_helper.rb b/app/helpers/proxmox_vm_interfaces_helper.rb index 9202e1a9c..9456a4e8b 100644 --- a/app/helpers/proxmox_vm_interfaces_helper.rb +++ b/app/helpers/proxmox_vm_interfaces_helper.rb @@ -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 diff --git a/app/models/concerns/fog_extensions/proxmox/node.rb b/app/models/concerns/fog_extensions/proxmox/node.rb index 85cf70698..7d413cb04 100644 --- a/app/models/concerns/fog_extensions/proxmox/node.rb +++ b/app/models/concerns/fog_extensions/proxmox/node.rb @@ -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 diff --git a/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb b/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb index 9e18a56c8..c80464eee 100644 --- a/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb +++ b/app/models/foreman_fog_proxmox/proxmox_compute_attributes.rb @@ -30,7 +30,7 @@ def host_compute_attrs(host) unless compute_os_types(host).include?(ostype) raise ::Foreman::Exception, format(_('Operating system family %s is not consistent with %s'), type: host.operatingsystem.type, -ostype: ostype) + ostype: ostype) end end super @@ -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 diff --git a/app/models/foreman_fog_proxmox/proxmox_version.rb b/app/models/foreman_fog_proxmox/proxmox_version.rb index 8adb036c1..c8e414430 100644 --- a/app/models/foreman_fog_proxmox/proxmox_version.rb +++ b/app/models/foreman_fog_proxmox/proxmox_version.rb @@ -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 diff --git a/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb b/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb index 7cf90de20..65331edbb 100644 --- a/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb +++ b/app/models/foreman_fog_proxmox/proxmox_vm_commands.rb @@ -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) diff --git a/app/models/foreman_fog_proxmox/proxmox_vm_new.rb b/app/models/foreman_fog_proxmox/proxmox_vm_new.rb index e8a97c43a..e3de34743 100644 --- a/app/models/foreman_fog_proxmox/proxmox_vm_new.rb +++ b/app/models/foreman_fog_proxmox/proxmox_vm_new.rb @@ -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}") diff --git a/config/routes.rb b/config/routes.rb index c5e7e2074..c29b7902f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/test/factories/proxmox_factory.rb b/test/factories/proxmox_factory.rb index 537530438..4402fc571 100644 --- a/test/factories/proxmox_factory.rb +++ b/test/factories/proxmox_factory.rb @@ -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')] } @@ -32,10 +32,10 @@ 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' } @@ -43,7 +43,7 @@ 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 @@ -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 diff --git a/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb b/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb index 3294176ac..f4acaf1d0 100644 --- a/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb +++ b/test/unit/foreman_fog_proxmox/proxmox_compute_attributes_test.rb @@ -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], diff --git a/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb b/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb index 656bd3b2c..7e4365a88 100644 --- a/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb +++ b/test/unit/foreman_fog_proxmox/proxmox_interfaces_test.rb @@ -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], @@ -58,7 +58,7 @@ class ProxmoxInterfacesTest < ActiveSupport::TestCase ip6 = Array.new(4) { format('%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], @@ -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], @@ -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], @@ -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], @@ -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],