Skip to content

Commit

Permalink
Replace class objects in query values with strings
Browse files Browse the repository at this point in the history
Fixes the following on rails 5.0:
DEPRECATION WARNING: Passing a class as a value in an Active
Record query is deprecated and will be removed. Pass a string instead.
(called from put_or_update at
/var/www/miq/vmdb/app/models/miq_queue.rb:343)

In rails 5.1, you get this if you try using a class object:
> MiqQueue.where(:class_name => MiqServer)
TypeError (can't cast Class)
  • Loading branch information
jrafanie committed May 30, 2019
1 parent 8ecc9fe commit 6ed429d
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/models/cloud_tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def self.create_cloud_tenant_queue(userid, ext_management_system, options = {})
:userid => userid
}
queue_opts = {
:class_name => class_by_ems(ext_management_system),
:class_name => class_by_ems(ext_management_system).name,
:method_name => 'create_cloud_tenant',
:priority => MiqQueue::HIGH_PRIORITY,
:role => 'ems_operations',
Expand Down Expand Up @@ -156,7 +156,7 @@ def self.post_refresh_ems(ems_id, _)
ems = ExtManagementSystem.find(ems_id)

MiqQueue.put_unless_exists(
:class_name => ems.class,
:class_name => ems.class.name,
:instance_id => ems_id,
:method_name => 'sync_cloud_tenants_with_tenants',
:zone => ems.my_zone
Expand Down
4 changes: 2 additions & 2 deletions app/models/manageiq/providers/cloud_manager/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def self.live_migrate_queue(userid, vm, options = {})
:userid => userid
}
queue_opts = {
:class_name => vm.class,
:class_name => vm.class.name,
:method_name => 'live_migrate',
:priority => MiqQueue::HIGH_PRIORITY,
:role => 'ems_operations',
Expand All @@ -253,7 +253,7 @@ def self.evacuate_queue(userid, vm, options = {})
:userid => userid
}
queue_opts = {
:class_name => vm.class,
:class_name => vm.class.name,
:method_name => 'evacuate',
:priority => MiqQueue::HIGH_PRIORITY,
:role => 'ems_operations',
Expand Down
2 changes: 1 addition & 1 deletion app/models/mixins/authentication_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def self.validate_credentials_task(args, user_id, zone)

queue_opts = {
:args => [*args],
:class_name => self,
:class_name => name,
:method_name => "raw_connect?",
:queue_name => "generic",
:role => "ems_operations",
Expand Down
6 changes: 3 additions & 3 deletions app/models/mixins/miq_provision_quota_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def quota_find_retired_vms_by_owner_and_group(options)
end

def quota_vm_stats(vms_method, options)
result = {:count => 0, :memory => 0, :cpu => 0, :snapshot_storage => 0, :used_storage => 0, :allocated_storage => 0, :ids => [], :class_name => Vm.name}
result = {:count => 0, :memory => 0, :cpu => 0, :snapshot_storage => 0, :used_storage => 0, :allocated_storage => 0, :ids => [], :class_name => "Vm"}
vms = send(vms_method, options)
result[:count] = vms.length
vms.each do |vm|
Expand Down Expand Up @@ -330,9 +330,9 @@ def bundle_quota_values(service_resource, result)
end

def quota_provision_stats(prov_method, options)
result = {:count => 0, :memory => 0, :cpu => 0, :storage => 0, :ids => [], :class_name => MiqProvisionRequest.name,
result = {:count => 0, :memory => 0, :cpu => 0, :storage => 0, :ids => [], :class_name => "MiqProvisionRequest",
:active => {
:class_name => MiqProvision.name, :ids => [], :storage_by_id => Hash.new { |k, v| k[v] = 0 },
:class_name => "MiqProvision", :ids => [], :storage_by_id => Hash.new { |k, v| k[v] = 0 },
:memory_by_host_id => Hash.new { |k, v| k[v] = 0 }, :cpu_by_host_id => Hash.new { |k, v| k[v] = 0 },
:vms_by_storage_id => Hash.new { |k, v| k[v] = [] }
}
Expand Down
2 changes: 1 addition & 1 deletion app/models/service_template_transformation_plan_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def transformation_log_queue(userid = nil, log_type = 'v2v')

_log.info("Queuing the download of #{log_type} log for #{description} with ID [#{id}]")
task_options = {:userid => userid, :action => 'transformation_log'}
queue_options = {:class_name => self.class,
queue_options = {:class_name => self.class.name,
:method_name => 'transformation_log',
:instance_id => id,
:args => [log_type],
Expand Down
2 changes: 1 addition & 1 deletion spec/models/mixins/authentication_mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def self.name; "TestClass"; end
let(:queue_opts) do
{
:args => [*args],
:class_name => ExtManagementSystem,
:class_name => "ExtManagementSystem",
:method_name => "raw_connect?",
:queue_name => "generic",
:role => "ems_operations",
Expand Down

0 comments on commit 6ed429d

Please sign in to comment.