Skip to content

Commit

Permalink
Merge pull request #771 from agrare/add_specs_ems_custom_attribute_bug
Browse files Browse the repository at this point in the history
Add specs showing ems_custom_attribute bug

(cherry picked from commit f03d833)
  • Loading branch information
Fryguy committed Jan 10, 2022
1 parent e56df0c commit 7be3eac
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
)
)

Expand Down Expand Up @@ -898,21 +914,21 @@ 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"))
]
)
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"))
]
Expand Down

0 comments on commit 7be3eac

Please sign in to comment.