diff --git a/spec/models/vm_or_template_spec.rb b/spec/models/vm_or_template_spec.rb index 89c1b746452f..680bc625e67d 100644 --- a/spec/models/vm_or_template_spec.rb +++ b/spec/models/vm_or_template_spec.rb @@ -618,22 +618,45 @@ end end + describe "#assign_ems_created_on_queue" do + it "queuing task to execute 'assign_ems_created_on' on server with 'ems_operations' role" do + expect(MiqQueue).to receive(:submit_job).with( + :class_name => described_class.name, + :method_name => 'assign_ems_created_on', + :role => 'ems_operations', + :args => [vm.id], + :priority => MiqQueue::MIN_PRIORITY + ) + described_class.assign_ems_created_on_queue(vm.id) + end + end + + describe "assign_ems_created_on" do + it "assigns timestamp on `VmDeployedEvent` event to `vm#ems_created_on field " do + timestamp = Time.now.utc.change(:usec => 0) + FactoryBot.create(:ems_event, :event_type => "VmDeployedEvent", :dest_vm_or_template => vm, :timestamp => timestamp) + described_class.assign_ems_created_on(vm.id) + expect(vm.reload.ems_created_on.utc).to eq(timestamp) + end + end + it "with ems_events" do - ems = FactoryBot.create(:ems_vmware_with_authentication) - vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems) - ems_event_src = FactoryBot.create(:ems_event, :vm_or_template => vm) + ems = FactoryBot.create(:ems_vmware_with_authentication) + vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems) + ems_event_src = FactoryBot.create(:ems_event, :vm_or_template => vm) ems_event_dest = FactoryBot.create(:ems_event, :dest_vm_or_template => vm) expect(vm.ems_events.count).to eq(2) - expect(vm.ems_events_src.first).to be_kind_of(EmsEvent) - expect(vm.ems_events_src.first.id).to eq(ems_event_src.id) + #expect(vm.ems_events_src.first).to be_kind_of(EmsEvent) + #expect(vm.ems_events_src.first.id).to eq(ems_event_src.id) + expect(vm.ems_events_src.first).to eq(ems_event_src) expect(vm.ems_events_dest.first.id).to eq(ems_event_dest.id) end it "#miq_provision_vms" do - ems = FactoryBot.create(:ems_vmware_with_authentication) - template = FactoryBot.create(:template_vmware, :ext_management_system => ems) - vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems) + ems = FactoryBot.create(:ems_vmware_with_authentication) + template = FactoryBot.create(:template_vmware, :ext_management_system => ems) + vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems) options = { :vm_name => vm.name,