Skip to content

Commit

Permalink
Merge pull request #16594 from jameswnl/task-name
Browse files Browse the repository at this point in the history
EmsRefresh task name to use demodularize classname
  • Loading branch information
agrare authored Jan 18, 2018
2 parents 193d031 + 2d7e450 commit 962af5d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models/ems_refresh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def self.queue_merge(targets, ems, create_task = false)
end

def self.create_refresh_task(ems, targets)
targets = targets.collect { |target_class, target_id| [target_class.demodulize, target_id] }
task_options = {
:action => "EmsRefresh(#{ems.name}) [#{targets}]".truncate(255),
:userid => "system"
Expand Down
13 changes: 12 additions & 1 deletion spec/models/ems_refresh_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,21 @@
end
end

context "task name" do
let(:vm1) { FactoryGirl.create(:vm_vmware, :ext_management_system => @ems) }
let(:vm2) { FactoryGirl.create(:vm_vmware, :ext_management_system => @ems) }
it "uses targets' short classnames to compose task name" do
task_ids = described_class.queue_refresh_task([vm1, vm2])
task_name = MiqTask.find(task_ids.first).name
expect(task_name).to include([vm1.class.name.demodulize, vm1.id].to_s)
expect(task_name).to include([vm2.class.name.demodulize, vm1.id].to_s)
end
end

describe ".create_refresh_task" do
it "create refresh task and trancates task name to 255 symbols" do
vm = FactoryGirl.create(:vm_vmware, :name => "vm_vmware1", :ext_management_system => @ems)
targets = Array.new(500) { vm }
targets = Array.new(500) { [vm.class.name, vm.id] }
task_name = described_class.send(:create_refresh_task, @ems, targets).name
expect(task_name.include?(@ems.name)).to eq true
expect(task_name.length).to eq 255
Expand Down

0 comments on commit 962af5d

Please sign in to comment.