Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update controller's device list in AssignController #3588

Merged
merged 1 commit into from
Oct 10, 2024

Conversation

dilyar85
Copy link
Member

@dilyar85 dilyar85 commented Oct 9, 2024

Description

This PR updates the AssignController function to add the assigned device to the controller's device list. This ensures that PickController() function returns the appropriate controller with available slots, as it's based on the current number of devices attached to the controller.

Closes: N/A

How Has This Been Tested?

  • Updated the existing TestAssignController to validate the controller's device list.
  • Deployed a VM with multiple devices, invoking AssignController during a single VM reconfiguration task. Verified that the devices were properly assigned to the controller without exceeding the maximum allowed slots:
$ govc device.ls -vm vm-iso-3-cdroms cdrom-\*
cdrom-3002  VirtualCdrom  ISO [sharedVmfs-0] contentlib-...
cdrom-3000  VirtualCdrom  ISO [sharedVmfs-0] contentlib-...
cdrom-3001  VirtualCdrom  ISO [sharedVmfs-0] contentlib-...

$ govc device.info -json -vm vm-iso-3-cdroms ide-\* | jq '.devices[] | {name, device}'
{
  "name": "ide-200",
  "device": [
    3000,
    3001
  ]
}
{
  "name": "ide-201",
  "device": [
    3002
  ]
}

Guidelines

Please read and follow the CONTRIBUTION guidelines of this project.

Copy link
Member

@dougm dougm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dilyar85 !

bryanv
bryanv previously approved these changes Oct 10, 2024
Copy link
Member

@dougm dougm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's fix this failing test first: https://github.com/vmware/govmomi/actions/runs/11264744416/job/31326263686?pr=3588
I can take a closer look in a bit

@dougm
Copy link
Member

dougm commented Oct 10, 2024

vcsim may change the Device.Key, in which case we need to change the Controller.Device reference too:

diff --git a/simulator/virtual_machine.go b/simulator/virtual_machine.go
index a596798d..1bda935c 100644
--- a/simulator/virtual_machine.go
+++ b/simulator/virtual_machine.go
@@ -1279,6 +1279,7 @@ func (vm *VirtualMachine) configureDevice(
 	d := device.GetVirtualDevice()
 	var controller types.BaseVirtualController
 
+	key := d.Key
 	if d.Key <= 0 {
 		// Keys can't be negative; Key 0 is reserved
 		d.Key = devices.NewKey()
@@ -1293,6 +1294,19 @@ func (vm *VirtualMachine) configureDevice(
 		d.Key++
 	}
 
+	// Update device controller's key reference
+	if key != d.Key {
+		if p := devices.FindByKey(d.ControllerKey); p != nil {
+			c := p.(types.BaseVirtualController).GetVirtualController()
+			for i := range c.Device {
+				if c.Device[i] == key {
+					c.Device[i] = d.Key
+					break
+				}
+			}
+		}
+	}
+
 	label := devices.Name(device)
 	summary := label
 	dc := ctx.Map.getEntityDatacenter(ctx.Map.Get(*vm.Parent).(mo.Entity))

@dilyar85
Copy link
Member Author

Thanks @dougm! Updated with your suggestion above and got all the tests passed.

@dilyar85 dilyar85 requested a review from dougm October 10, 2024 14:58
Copy link
Member

@dougm dougm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dilyar85 !

@dilyar85 dilyar85 merged commit 4bc1e3d into vmware:main Oct 10, 2024
10 checks passed
@dilyar85 dilyar85 deleted the bugfix/assign-controller branch October 10, 2024 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants