From 7be3eac681f54fbb454ef05c104844eb93ce2422 Mon Sep 17 00:00:00 2001 From: Jason Frey Date: Mon, 20 Dec 2021 16:02:04 -0500 Subject: [PATCH] Merge pull request #771 from agrare/add_specs_ems_custom_attribute_bug Add specs showing ems_custom_attribute bug (cherry picked from commit f03d8337d1e1a186e64df81ff52cc3523b2b3b7f) --- .../vmware/infra_manager/refresher_spec.rb | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/spec/models/manageiq/providers/vmware/infra_manager/refresher_spec.rb b/spec/models/manageiq/providers/vmware/infra_manager/refresher_spec.rb index 3af330ff7..c5511b268 100644 --- a/spec/models/manageiq/providers/vmware/infra_manager/refresher_spec.rb +++ b/spec/models/manageiq/providers/vmware/infra_manager/refresher_spec.rb @@ -375,20 +375,36 @@ vm = ems.vms.find_by(:ems_ref => "vm-107") expect(vm.ems_custom_attributes).to be_empty - run_targeted_refresh(targeted_update_set([vm_add_new_custom_value_update])) + run_targeted_refresh(targeted_update_set([vm_add_new_custom_value_update(vm.ems_ref)])) custom_attrs = vm.reload.ems_custom_attributes expect(custom_attrs.count).to eq(1) expect(custom_attrs.first).to have_attributes(:name => "foo", :value => "bar", :source => "VC") end + it "adding a customValue to two VMs" do + vm1 = ems.vms.find_by(:ems_ref => "vm-107") + vm2 = ems.vms.find_by(:ems_ref => "vm-108") + expect(vm1.ems_custom_attributes).to be_empty + + run_targeted_refresh(targeted_update_set([vm_add_new_custom_value_update(vm1.ems_ref), vm_add_new_custom_value_update(vm2.ems_ref)])) + + custom_attrs = vm1.reload.ems_custom_attributes + expect(custom_attrs.count).to eq(1) + expect(custom_attrs.first).to have_attributes(:name => "foo", :value => "bar", :source => "VC") + + custom_attrs = vm2.reload.ems_custom_attributes + expect(custom_attrs.count).to eq(1) + expect(custom_attrs.first).to have_attributes(:name => "foo", :value => "bar", :source => "VC") + end + it "changing a customValue" do vm = ems.vms.find_by(:ems_ref => "vm-107") expect(vm.ems_custom_attributes).to be_empty run_targeted_refresh( targeted_update_set( - [vm_add_new_custom_value_update, vm_edit_custom_value_update] + [vm_add_new_custom_value_update(vm.ems_ref), vm_edit_custom_value_update(vm.ems_ref)] ) ) @@ -898,10 +914,10 @@ def dvpg_delete_object_update ) end - def vm_add_new_custom_value_update + def vm_add_new_custom_value_update(vm) RbVmomi::VIM.ObjectUpdate( :kind => "modify", - :obj => RbVmomi::VIM.VirtualMachine(vim, "vm-107"), + :obj => RbVmomi::VIM.VirtualMachine(vim, vm), :changeSet => [ RbVmomi::VIM.PropertyChange(:name => "availableField", :op => "assign", :val => [RbVmomi::VIM.CustomFieldDef(:key => 300, :managedObjectType => "VirtualMachine", :name => "foo", :type => "string")]), RbVmomi::VIM.PropertyChange(:name => "summary.customValue[300]", :op => "add", :val => RbVmomi::VIM.CustomFieldStringValue(:key => 300, :value => "bar")) @@ -909,10 +925,10 @@ def vm_add_new_custom_value_update ) end - def vm_edit_custom_value_update + def vm_edit_custom_value_update(vm) RbVmomi::VIM.ObjectUpdate( :kind => "modify", - :obj => RbVmomi::VIM.VirtualMachine(vim, "vm-107"), + :obj => RbVmomi::VIM.VirtualMachine(vim, vm), :changeSet => [ RbVmomi::VIM.PropertyChange(:name => "summary.customValue[300]", :op => "assign", :val => RbVmomi::VIM.CustomFieldStringValue(:key => 300, :value => "baz")) ]