From 0b358b8dc381d3a8721e935a5d38e460c78251fe Mon Sep 17 00:00:00 2001 From: Brandon Dunne Date: Thu, 12 Jul 2018 09:46:46 -0400 Subject: [PATCH] Ensure MiqSchedule#name is unique for ServiceTemplate orders https://bugzilla.redhat.com/show_bug.cgi?id=1564255 --- app/models/service_template.rb | 4 ++-- spec/models/service_template_spec.rb | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/models/service_template.rb b/app/models/service_template.rb index ace73941085..32d853ccc71 100644 --- a/app/models/service_template.rb +++ b/app/models/service_template.rb @@ -422,8 +422,8 @@ def order(user_or_id, options = nil, request_options = nil, schedule_time = nil) return {:errors => errors} unless errors.blank? schedule = MiqSchedule.create!( - :name => "Order #{self.class.name} #{id}", - :description => "Order #{self.class.name} #{id}", + :name => "Order #{self.class.name} #{id} at #{time}", + :description => "Order #{self.class.name} #{id} at #{time}", :sched_action => {:args => [user.id, options, request_options], :method => "queue_order"}, :resource_id => id, :towhat => "ServiceTemplate", diff --git a/spec/models/service_template_spec.rb b/spec/models/service_template_spec.rb index c0ffe0f3143..239bc9d4ea2 100644 --- a/spec/models/service_template_spec.rb +++ b/spec/models/service_template_spec.rb @@ -832,17 +832,28 @@ EvmSpecHelper.local_miq_server expect(resource_action_workflow).to receive(:validate_dialog).and_return([]) - result = service_template.order(user, {}, {}, Time.now.utc.to_s) + time = Time.zone.now.utc.to_s + result = service_template.order(user, {}, {}, time) expect(result.keys).to eq([:schedule]) # No errors expect(result[:schedule]).to have_attributes( - :name => "Order ServiceTemplate #{service_template.id}", + :name => "Order ServiceTemplate #{service_template.id} at #{time}", :sched_action => {:args => [user.id, {}, {}], :method => "queue_order"}, :towhat => "ServiceTemplate", :resource_id => service_template.id ) end + it "successfully scheduled twice" do + EvmSpecHelper.local_miq_server + expect(resource_action_workflow).to receive(:validate_dialog).twice.and_return([]) + + service_template.order(user, {}, {}, Time.zone.now.utc.to_s) + service_template.order(user, {}, {}, (Time.zone.now + 1.hour).utc.to_s) + + expect(service_template.miq_schedules.length).to eq(2) + end + context "#provision_request" do let(:arg1) { {'ordered_by' => 'fred'} } context "with submit_workflow" do