Skip to content

Commit

Permalink
Leverage submit_job for role based queueing
Browse files Browse the repository at this point in the history
https://bugzilla.redhat.com/show_bug.cgi?id=1629945

Because the queue put was specifying a queue_name without a role OR
zone, the zone was being set to MiqServer.my_zone.  By leveraging the
higher level method, submit_job, specifying the service of "reporting"
sets the role and because reporting is a regional role, there's no need
to specify the zone, it will default to the "nil" (any) zone.
  • Loading branch information
jrafanie committed Oct 1, 2018
1 parent 68dad68 commit 2e9744c
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 6 deletions.
9 changes: 4 additions & 5 deletions app/models/miq_report/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ def queue_generate_table(options = {})
if sync
_async_generate_table(task.id, options)
else
MiqQueue.put(
:queue_name => "reporting",
MiqQueue.submit_job(
:service => "reporting",
:class_name => self.class.name,
:instance_id => id,
:method_name => "_async_generate_table",
Expand Down Expand Up @@ -792,9 +792,8 @@ def queue_report_result(options, res_opts)
_log.info("Adding generate report task to the message queue...")
task = MiqTask.create(:name => "Generate Report: '#{name}'", :userid => options[:userid])

MiqQueue.put(
:queue_name => "reporting",
:role => "reporting",
MiqQueue.submit_job(
:service => "reporting",
:class_name => self.class.name,
:instance_id => id,
:method_name => "build_report_result",
Expand Down
1 change: 0 additions & 1 deletion app/models/miq_report/generator/async.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def async_generate_table(options = {})
if self.new_record?
MiqQueue.submit_job(
:service => "reporting",
:role => "reporting",
:class_name => self.class.to_s,
:method_name => "_async_generate_table",
:args => [task.id, self, options],
Expand Down
33 changes: 33 additions & 0 deletions spec/models/miq_report/async_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
describe MiqReport do
context "Generator::Async" do
context ".async_generate_tables" do
let(:report) do
MiqReport.new(
:name => "Custom VM report",
:title => "Custom VM report",
:rpt_group => "Custom",
:rpt_type => "Custom",
:db => "ManageIQ::Providers::InfraManager::Vm",
)
end

it "creates task, queue, audit event" do
User.seed
EvmSpecHelper.local_miq_server
ServerRole.seed
expect(AuditEvent).to receive(:success)

described_class.async_generate_tables(:reports => [report])
task = MiqTask.first
expect(task.name).to eq("Generate Reports: [\"#{report.name}\"]")

message = MiqQueue.where(:method_name => "_async_generate_tables").first
expect(message).to have_attributes(
:role => "reporting",
:zone => nil,
:class_name => report.class.name,
:method_name => "_async_generate_tables"
)

expect(message.args.first).to eq(task.id)
end
end

context "._async_generate_tables" do
it "unknown taskid" do
expect { MiqReport._async_generate_tables(111111, :reports => []) }.to raise_error(MiqException::Error)
Expand Down
59 changes: 59 additions & 0 deletions spec/models/miq_report/generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,65 @@ def create_rollup(host, profile, used_mem)
end
end

describe "creates task, queue, audit event" do
let(:report) do
MiqReport.new(
:name => "Custom VM report",
:title => "Custom VM report",
:rpt_group => "Custom",
:rpt_type => "Custom",
:db => "ManageIQ::Providers::InfraManager::Vm",
)
end

before do
User.seed
EvmSpecHelper.local_miq_server
ServerRole.seed
expect(AuditEvent).to receive(:success)
end

it "#queue_generate_table" do
report.queue_generate_table(:userid => "admin")
task = MiqTask.first
expect(task).to have_attributes(
:name => "Generate Report: '#{report.name}'",
:userid => "admin"
)

message = MiqQueue.where(:method_name => "_async_generate_table")
message = message.first
expect(message).to have_attributes(
:role => "reporting",
:zone => nil,
:class_name => report.class.name,
:method_name => "_async_generate_table"
)

expect(message.args.first).to eq(task.id)
end

it "#queue_report_result" do
task_id = report.queue_report_result({:userid => "admin"}, {})
task = MiqTask.find(task_id)
expect(task).to have_attributes(
:name => "Generate Report: '#{report.name}'",
:userid => "admin"
)

message = MiqQueue.where(:method_name => "build_report_result")
message = message.first
expect(message).to have_attributes(
:role => "reporting",
:zone => nil,
:class_name => report.class.name,
:method_name => "build_report_result"
)

expect(message.args.first).to eq(task_id)
end
end

describe "#cols_for_report" do
it "uses cols" do
rpt = MiqReport.new(:db => "VmOrTemplate", :cols => %w(vendor version name))
Expand Down

0 comments on commit 2e9744c

Please sign in to comment.